Skip to content

Instantly share code, notes, and snippets.

@mmazzarolo
Last active May 23, 2016 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmazzarolo/4d223de6787b9a57ce4b to your computer and use it in GitHub Desktop.
Save mmazzarolo/4d223de6787b9a57ce4b to your computer and use it in GitHub Desktop.
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