Skip to content

Instantly share code, notes, and snippets.

@raspasov
Created January 4, 2021 21:54
Show Gist options
  • Save raspasov/bc7e717adccee0ba5ad60cdea41d66d6 to your computer and use it in GitHub Desktop.
Save raspasov/bc7e717adccee0ba5ad60cdea41d66d6 to your computer and use it in GitHub Desktop.
Basis Reanimated v2
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