Created
August 28, 2018 16:24
-
-
Save yusent/646f60bb4ff9fcca9c05f9bae831121c to your computer and use it in GitHub Desktop.
Touchable with native feedback for both Android and IOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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