Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions CardFlip.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class CardFlip extends Component<Props> {
rotation: new Animated.ValueXY({ x: 50, y: 50 }),
zoom: new Animated.Value(0),
rotateOrientation: "",
flipDirection: "y"
flipDirection: "y",
flipReverse: false,
}
}

Expand Down Expand Up @@ -197,7 +198,7 @@ class CardFlip extends Component<Props> {

getCardATransformation() {
//0, 50, 100
const { progress, rotation, side, rotateOrientation } = this.state;
const { progress, rotation, side, rotateOrientation, flipReverse } = this.state;

const sideAOpacity = progress.interpolate({
inputRange: [50, 51],
Expand All @@ -213,15 +214,15 @@ class CardFlip extends Component<Props> {
if (rotateOrientation === "x") {
const aXRotation = rotation.x.interpolate({
inputRange: [0, 50, 100, 150],
outputRange: ["-180deg", "0deg", "180deg", "0deg"],
outputRange: flipReverse ? ["180deg", "0deg", "-180deg", "0deg"] : ["-180deg", "0deg", "180deg", "0deg"],
extrapolate: "clamp"
});
sideATransform.transform.push({ rotateX: aXRotation });
} else {
// cardA Y-rotation
const aYRotation = rotation.y.interpolate({
inputRange: [0, 50, 100, 150],
outputRange: ["-180deg", "0deg", "180deg", "0deg"],
outputRange: flipReverse ? ["180deg", "0deg", "-180deg", "0deg"] : ["-180deg", "0deg", "180deg", "0deg"],
extrapolate: "clamp"
});
sideATransform.transform.push({ rotateY: aYRotation });
Expand All @@ -230,7 +231,7 @@ class CardFlip extends Component<Props> {
}

getCardBTransformation() {
const { progress, rotation, side, rotateOrientation } = this.state;
const { progress, rotation, side, rotateOrientation, flipReverse } = this.state;

const sideBOpacity = progress.interpolate({
inputRange: [50, 51],
Expand All @@ -247,7 +248,7 @@ class CardFlip extends Component<Props> {
if (rotateOrientation === "x") {
const bXRotation = rotation.x.interpolate({
inputRange: [0, 50, 100, 150],
outputRange: ["0deg", "-180deg", "-360deg", "180deg"],
outputRange: flipReverse ? ["0deg", "180deg", "360deg", "-180deg"] : ["0deg", "-180deg", "-360deg", "180deg"],
extrapolate: "clamp"
});
sideBTransform.transform.push({ rotateX: bXRotation });
Expand All @@ -256,14 +257,14 @@ class CardFlip extends Component<Props> {
// cardB Y-rotation
bYRotation = rotation.y.interpolate({
inputRange: [0, 50, 100, 150],
outputRange: ["0deg", "180deg", "0deg", "-180deg"],
outputRange: flipReverse ? ["0deg", "-180deg", "0deg", "180deg"] : ["0deg", "180deg", "0deg", "-180deg"],
extrapolate: "clamp"
});
} else {
// cardB Y-rotation
bYRotation = rotation.y.interpolate({
inputRange: [0, 50, 100, 150],
outputRange: ["0deg", "-180deg", "0deg", "180deg"],
outputRange: flipReverse ? ["0deg", "180deg", "0deg", "-180deg"] : ["0deg", "-180deg", "0deg", "180deg"],
extrapolate: "clamp"
});
}
Expand Down Expand Up @@ -321,6 +322,7 @@ CardFlip.defaultProps = {
duration: 500,
flipZoom: 0.09,
flipDirection: "y",
flipReverse: false,
perspective: 800,
onFlip: () => { },
onFlipStart: () => { },
Expand All @@ -336,6 +338,7 @@ CardFlip.propTypes = {
duration: PropTypes.number,
flipZoom: PropTypes.number,
flipDirection: PropTypes.string,
flipReverse: PropTypes.bool,
onFlip: PropTypes.func,
onFlipEnd: PropTypes.func,
onFlipStart: PropTypes.func,
Expand Down
16 changes: 15 additions & 1 deletion Example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const App: () => React$Node = () => {
activeOpacity={1}
style={[styles.card, styles.card1]}
onPress={() => this.card.flip()}>
<Text style={styles.label}>AB</Text>
<Text style={styles.label}>Regular</Text>
</TouchableOpacity>
<TouchableOpacity
activeOpacity={1}
Expand All @@ -25,6 +25,20 @@ const App: () => React$Node = () => {
<Text style={styles.label}>CD</Text>
</TouchableOpacity>
</CardFlip>
<CardFlip flipReverse style={[styles.cardContainer, {marginTop: 30}]} ref={card => (this.card2 = card)}>
<TouchableOpacity
activeOpacity={1}
style={[styles.card, styles.card1]}
onPress={() => this.card2.flip()}>
<Text style={styles.label}>flipReverse</Text>
</TouchableOpacity>
<TouchableOpacity
activeOpacity={1}
style={[styles.card, styles.card2]}
onPress={() => this.card2.flip()}>
<Text style={styles.label}>CD</Text>
</TouchableOpacity>
</CardFlip>
</View>
);
};
Expand Down
2 changes: 1 addition & 1 deletion Example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"react": "16.9.0",
"react-lifecycles-compat": "^3.0.4",
"react-native": "0.61.2",
"react-native-card-flip": "^1.0.4"
"react-native-card-flip": "../"
},
"devDependencies": {
"@babel/core": "^7.6.4",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import CardFlip from 'react-native-card-flip';
| duration | number | flip duration | | 1000 |
| flipZoom | number | zoom level on flip | | 0.09 |
| flipDirection | string | the rotation axis. 'x' or 'y' | | 'y' |
| flipReverse | boolean | reverses flip direction | | false |
| perspective | number | | | 800 |


Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type FlipCardProps = {
duration?: number;
flipZoom?: number;
flipDirection?: FlipDirection;
flipReverse?: boolean;
onFlip?: (index: number) => void;
onFlipEnd?: (index: number) => void;
onFlipStart?: (index: number) => void;
Expand Down