import * as React from 'react'; import { BackgroundPropType, StyleProp, Platform, TouchableHighlight, TouchableNativeFeedback, TouchableWithoutFeedback, View, ViewStyle, StyleSheet, } from 'react-native'; import color from 'color'; import { withTheme } from '../../core/theming'; const ANDROID_VERSION_LOLLIPOP = 21; const ANDROID_VERSION_PIE = 28; type Props = React.ComponentProps & { borderless?: boolean; background?: BackgroundPropType; disabled?: boolean; onPress?: () => void | null; rippleColor?: string; underlayColor?: string; children: React.ReactNode; style?: StyleProp; theme: ReactNativePaper.Theme; }; const TouchableRipple = ({ style, background, borderless = false, disabled: disabledProp, rippleColor, underlayColor, children, theme, ...rest }: Props) => { const { dark, colors } = theme; const disabled = disabledProp || !rest.onPress; const calculatedRippleColor = rippleColor || color(colors.text) .alpha(dark ? 0.32 : 0.2) .rgb() .string(); // A workaround for ripple on Android P is to use useForeground + overflow: 'hidden' // https://github.com/facebook/react-native/issues/6480 const useForeground = Platform.OS === 'android' && Platform.Version >= ANDROID_VERSION_PIE && borderless; if (TouchableRipple.supported) { return ( {React.Children.only(children)} ); } return ( {React.Children.only(children)} ); }; TouchableRipple.supported = Platform.OS === 'android' && Platform.Version >= ANDROID_VERSION_LOLLIPOP; const styles = StyleSheet.create({ overflowHidden: { overflow: 'hidden', }, }); export default withTheme(TouchableRipple);