|
1 | | -# REACT-NATIVE-REANIMATED-FLIP |
| 1 | +<div align="center"> |
| 2 | + |
| 3 | +[](https://www.npmjs.com/package/react-native-flip) [](https://www.npmjs.com/package/react-native-flip) |
| 4 | + |
| 5 | +<h1>React Native Reanimated Flip Card</h1> |
2 | 6 |
|
3 | | - |
| 7 | +<img width="auto" height="500" src="./gif/flip.gif"> |
| 8 | + |
| 9 | +</div> |
4 | 10 |
|
5 | 11 | # Install |
6 | 12 |
|
7 | 13 | ```sh |
8 | | - yarn add react-native-flip |
| 14 | +yarn add react-native-flip |
| 15 | +# or |
| 16 | +npm i react-native-flip |
9 | 17 | ``` |
10 | 18 |
|
| 19 | +> :warning: You need to install [react-native-reanimated](https://docs.swmansion.com/react-native-reanimated/docs/next/installation/) and follow their installation instructions. |
| 20 | +
|
11 | 21 | # Usage |
12 | 22 |
|
13 | 23 | ```js |
14 | 24 | import FlipCard from "react-native-flip" |
15 | 25 |
|
16 | 26 | const make = () => { |
| 27 | + const Front = ( |
| 28 | + <View |
| 29 | + style={{ |
| 30 | + backgroundColor: "#ed8936", |
| 31 | + alignItems: "center", |
| 32 | + padding: 100, |
| 33 | + borderRadius: 12, |
| 34 | + }} |
| 35 | + > |
| 36 | + <Text style={{ fontSize: 18, color: "black" }}>Front</Text> |
| 37 | + <TouchableOpacity |
| 38 | + onPress={changeSide} |
| 39 | + style={{ |
| 40 | + padding: 10, |
| 41 | + marginTop: 20, |
| 42 | + backgroundColor: "white", |
| 43 | + borderRadius: 12, |
| 44 | + }} |
| 45 | + > |
| 46 | + <Text>Click here to Flip</Text> |
| 47 | + </TouchableOpacity> |
| 48 | + </View> |
| 49 | + ) |
| 50 | + const Back = ( |
| 51 | + <View |
| 52 | + style={{ |
| 53 | + backgroundColor: "#007AFF", |
| 54 | + alignItems: "center", |
| 55 | + padding: 100, |
| 56 | + borderRadius: 12, |
| 57 | + }} |
| 58 | + > |
| 59 | + <Text style={{ fontSize: 18, color: "white" }}>Back</Text> |
| 60 | + <TouchableOpacity |
| 61 | + onPress={changeSide} |
| 62 | + style={{ |
| 63 | + padding: 10, |
| 64 | + marginTop: 20, |
| 65 | + backgroundColor: "white", |
| 66 | + borderRadius: 12, |
| 67 | + }} |
| 68 | + > |
| 69 | + <Text>Click here to Flip</Text> |
| 70 | + </TouchableOpacity> |
| 71 | + </View> |
| 72 | + ) |
17 | 73 | return ( |
18 | | - <FlipCard |
19 | | - side={0} |
20 | | - front={<Text>Front component</Text>} |
21 | | - back={<Text>Back component</Text>} |
22 | | - /> |
| 74 | + <SafeAreaView style={styles.container}> |
| 75 | + <Text style={styles.textStyle}>Hello, World</Text> |
| 76 | + <Text style={styles.textStyle}>React Native Reanimated Flip Card</Text> |
| 77 | + <Button |
| 78 | + title={`Change rotation. The card rotation is: ${rotate}`} |
| 79 | + onPress={() => { |
| 80 | + setRotate((rotation) => (rotation === "X" ? "Y" : "X")) |
| 81 | + }} |
| 82 | + /> |
| 83 | + <Button title={`Flip: ${side}`} onPress={changeSide} /> |
| 84 | + <FlipCard |
| 85 | + side={side} |
| 86 | + rotate={rotate} |
| 87 | + style={styles.flipContainer} |
| 88 | + front={Front} |
| 89 | + back={Back} |
| 90 | + /> |
| 91 | + </SafeAreaView> |
23 | 92 | ) |
24 | 93 | } |
25 | 94 | ``` |
26 | 95 |
|
| 96 | +## :wrench: Props |
| 97 | + |
| 98 | +| Name | Description | Required | Type | Default | |
| 99 | +| ----------- | --------------------------------------- | -------- | ------------- | ------- | |
| 100 | +| perspective | Perspective of rotation | NO | Number | 1200 | |
| 101 | +| side | A value indicating Front(1) or Back(0) | YES | <1, 0> | - | |
| 102 | +| rotate | A value indicating the axis of rotation | NO | <'Y', 'X'> | "Y" | |
| 103 | +| style | Container Style | NO | ViewStyle | - | |
| 104 | +| front | React component in Front Side | YES | React.Element | - | |
| 105 | +| back | React component in Back Side | YES | React.Element | - | |
| 106 | + |
| 107 | + |
| 108 | +## :camera: Screenhots |
| 109 | + |
| 110 | +| iOS | Android | |
| 111 | +|-----|---------| |
| 112 | +|<img width="auto" height="500" src="./gif/ios.gif">|<img width="auto" height="500" src="./gif/android.gif">| |
| 113 | + |
27 | 114 | # Try it out |
28 | 115 |
|
29 | 116 | You can also try out the [example app](https://snack.expo.io/@pzatorski/react-native-flip-example) with Expo. |
30 | 117 |
|
| 118 | +You can also try the [React Native App](https://github.com/Karthik-B-06/react-native-reanimated-flip/tree/rn-example-with-better-readme/rn-example/RNFlip). |
| 119 | + |
31 | 120 | The source code for the example app is under [/examples](https://github.com/czystyl/react-native-reanimated-flip/tree/develop/examples) folder. |
0 commit comments