Skip to content

Commit

Permalink
Touchable [nfc]: Inline value for background prop on Android.
Browse files Browse the repository at this point in the history
After the upcoming RN v0.61 -> v0.62 upgrade, Flow would correctly
flag the fact that we're trying to compare a `number | string` value
to a number. (`Platform.Version` is a number on Android and a string
on iOS [1].)

With the new placement of the `Platform.Version` check, Flow will be
able to infer that `Platform.Version` is a number from the
conditional on `Platform.OS` above. (It looks like RN types
`Platform` as a union of types corresponding to each platform, so
`Platform.OS` and `Platform.Version` correctly correspond with each
other.)

[1] https://reactnative.dev/docs/platform-specific-code#detecting-the-android-version
  • Loading branch information
chrisbobbe committed Sep 1, 2020
1 parent 4b2321a commit cf13577
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/common/Touchable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ import type { ViewStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet
import type { Node as React$Node } from 'react';
import { HIGHLIGHT_COLOR } from '../styles';

const androidBackground =
Platform.Version >= 21
? TouchableNativeFeedback.Ripple(HIGHLIGHT_COLOR)
: TouchableNativeFeedback.SelectableBackground();

type Props = $ReadOnly<{|
accessibilityLabel?: string,
style?: ViewStyleProp,
Expand Down Expand Up @@ -92,7 +87,11 @@ export default class Touchable extends PureComponent<Props> {
return (
<TouchableNativeFeedback
accessibilityLabel={accessibilityLabel}
background={androidBackground}
background={
Platform.Version >= 21
? TouchableNativeFeedback.Ripple(HIGHLIGHT_COLOR)
: TouchableNativeFeedback.SelectableBackground()
}
onPress={onPress}
onLongPress={onLongPress}
>
Expand Down

0 comments on commit cf13577

Please sign in to comment.