Created
January 4, 2021 21:54
-
-
Save raspasov/bc7e717adccee0ba5ad60cdea41d66d6 to your computer and use it in GitHub Desktop.
Basis Reanimated v2
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, Component, useImperativeHandle, useRef, forwardRef} from 'react'; | |
import Animated, {useSharedValue, useAnimatedStyle, withTiming, withSpring} from 'react-native-reanimated'; | |
function Box(props, ref) { | |
const aRef = useRef(); | |
useImperativeHandle(ref, function () { | |
return { | |
moveBox: function (globalY) { | |
translateY_R.value = withSpring(globalY) | |
} | |
}; | |
}); | |
// const global_y = props['global-y'] | |
const style = props['style'] | |
const height = props['height'] | |
const translateY_R = useSharedValue(0.5); | |
const animatedStyles = useAnimatedStyle(function () { | |
return { | |
transform: [{translateY: translateY_R.value * height}], | |
}; | |
}); | |
console.log("RENDER BOX") | |
return <Animated.View ref={aRef} | |
style={[style, animatedStyles]}/> | |
} | |
exports.Box = forwardRef(Box); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment