Comments (5)
Hey @MauriceNino, I'll try to find some time to check it out.
from react-native-reanimated-flip.
Thanks a lot!
from react-native-reanimated-flip.
I guess this package doesn't work anymore, I get the same error.
from react-native-reanimated-flip.
Same issue here
from react-native-reanimated-flip.
Here's a fixed version for react-native-reanimated
3.6.0. I also created a PR for this: #58
import Animated, {
Easing,
interpolate,
useAnimatedStyle,
useDerivedValue,
withTiming,
} from 'react-native-reanimated';
import {StyleSheet, ViewStyle} from 'react-native';
import React from 'react';
export enum FlipSide {
FRONT,
BACK,
}
export enum RotateAxis {
Y = 'Y',
X = 'X',
}
type Props = {
perspective?: number;
side: FlipSide;
rotate?: RotateAxis;
style?: ViewStyle;
front: React.ReactElement;
back: React.ReactElement;
};
const ReanimatedFlip = ({
perspective = 1200,
rotate = RotateAxis.Y,
side,
front,
back,
style,
}: Props) => {
const rotatePosition = interpolate(side, [0, 1], [180, 360]);
const rotateValue = useDerivedValue(() => {
return withTiming(rotatePosition, {
duration: 500,
easing: Easing.inOut(Easing.ease),
});
});
const rotationFlip = useDerivedValue(() => {
if (rotate === RotateAxis.Y) {
return {
rotateY: `${rotateValue.value}deg`,
};
}
return {
rotateX: `${rotateValue.value}deg`,
};
}, [rotate, rotateValue]);
const rotationFlipBack = useDerivedValue(() => {
if (rotate === RotateAxis.Y) {
return {
rotateY: '180deg',
};
}
return {
rotateX: '180deg',
};
}, [rotate]);
const opacityFront = useDerivedValue(() => {
return withTiming(side, {
duration: 500,
easing: Easing.inOut(Easing.ease),
});
}, [side]);
const opacityBack = useDerivedValue(() => {
return withTiming(side === 0 ? 1 : 0, {
duration: 500,
easing: Easing.inOut(Easing.ease),
});
}, [side]);
const animatedStyleFront = useAnimatedStyle(() => {
return {
opacity: opacityFront.value,
transform: [{perspective}, {...rotationFlip.value}],
};
}, [rotate, side, rotationFlip]);
const animatedStyleBack = useAnimatedStyle(() => {
return {
opacity: opacityBack.value,
transform: [
{perspective},
{...rotationFlipBack.value},
{...rotationFlip.value},
],
};
}, [rotate, side]);
return (
<Animated.View style={StyleSheet.flatten([style, styles.container])}>
<Animated.View style={[styles.side, animatedStyleFront]}>
{front}
</Animated.View>
<Animated.View style={[styles.side, animatedStyleBack]}>
{back}
</Animated.View>
</Animated.View>
);
};
const styles = StyleSheet.create({
container: {
justifyContent: 'center',
alignItems: 'center',
height: '100%',
width: '100%'
},
side: {
width: '100%',
height: '100%',
position: 'absolute',
justifyContent: 'center',
alignItems: 'center',
},
});
export default ReanimatedFlip;
from react-native-reanimated-flip.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-reanimated-flip.