Skip to content

Instantly share code, notes, and snippets.

@yusent
Created August 28, 2018 16:24
Show Gist options
  • Save yusent/646f60bb4ff9fcca9c05f9bae831121c to your computer and use it in GitHub Desktop.
Save yusent/646f60bb4ff9fcca9c05f9bae831121c to your computer and use it in GitHub Desktop.
Touchable with native feedback for both Android and IOS
import React from 'react';
import {
Platform,
TouchableNativeFeedback,
TouchableOpacity,
View,
} from 'react-native';
const ANDROID_VERSION_LOLLIPOP = 21;
function TouchableItem(props) {
if (
Platform.OS === 'android' &&
Platform.Version >= ANDROID_VERSION_LOLLIPOP
) {
const { borderless, onPress, style, ...rest } = props;
return (
<TouchableNativeFeedback
{...rest}
background={
TouchableNativeFeedback.Ripple('rgba(0, 0, 0, .32)', borderless)
}
onPress={() => {
if (props.onPress) {
requestAnimationFrame(() => {
props.onPress();
});
}
}}
style={null}
>
<View style={style}>
{props.children}
</View>
</TouchableNativeFeedback>
);
}
return (
<TouchableOpacity {...props}>
{props.children}
</TouchableOpacity>
);
}
export { TouchableItem };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment