Last active
May 23, 2016 15:31
-
-
Save mmazzarolo/4d223de6787b9a57ce4b to your computer and use it in GitHub Desktop.
This file contains 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, { PropTypes } from 'react' | |
import { Platform, View, TouchableNativeFeedback, TouchableOpacity } from 'react-native' | |
const IS_ANDROID = Platform.OS === 'android' | |
const IS_RIPPLE_EFFECT_SUPPORTED = Platform.Version >= 21 && IS_ANDROID | |
const TouchableView = ({ isRippleEnabled, children, style, ...props }) => { | |
if (IS_RIPPLE_EFFECT_SUPPORTED && !isRippleEnabled) { | |
const background = TouchableNativeFeedback.Ripple(null, false) | |
return ( | |
<TouchableNativeFeedback {...props} background={background}> | |
<View style={style}>{children}</View> | |
</TouchableNativeFeedback> | |
) | |
} else { | |
return ( | |
<TouchableOpacity {...props} style={style}> | |
{children} | |
</TouchableOpacity> | |
) | |
} | |
} | |
TouchableView.propTypes = { | |
isRippleEnabled: PropTypes.bool, | |
children: PropTypes.any, | |
style: View.propTypes.style | |
} | |
TouchableView.defaultProps = { | |
isRippleEnabled: true | |
} | |
export default TouchableView |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment