Created
May 24, 2020 11:36
-
-
Save jennmueng/70b8162febec9627383d89afb9903fb9 to your computer and use it in GitHub Desktop.
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
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