Skip to content

Instantly share code, notes, and snippets.

@jennmueng
Created May 24, 2020 11:36
Show Gist options
  • Save jennmueng/70b8162febec9627383d89afb9903fb9 to your computer and use it in GitHub Desktop.
Save jennmueng/70b8162febec9627383d89afb9903fb9 to your computer and use it in GitHub Desktop.
class HoverableTouchable extends PureComponent {
hoverOpacity = new Animated.Value(1);
onMouseEnter = () => {
Animated.timing(this.hoverOpacity, {
toValue: 0.3,
duration: 100,
useNativeDriver: true // not available on web, make a check here, something like Platform.OS === 'web' ? ...
}).start()
}
onMouseLeave = () => {
Animated.timing(this.hoverOpacity, {
toValue: 1,
duration: 100,
useNativeDriver: true // not available on web, make a check here, something like Platform.OS === 'web' ? ...
}).start()
}
render() {
return (
<AnimatedHoverable
style={{
opacity: this.hoverOpacity
}}
onMouseEnter={this.onMouseEnter}
onMouseLeave={this.onMouseLeave}
>
<TouchableOpacity
onPress={this.props.onPress}
>
</TouchableOpacity>
</AnimatedHoverable>
)
}
}
const AnimatedHoverable = Animated.createAnimatedComponent(styled.View`
flex: 0;
${/* more styles here */}
`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment