项目作者: arunahuja94

项目描述 :
The card component which has a motion of flip for React Native(Android/iOS) with gestures
高级语言: JavaScript
项目地址: git://github.com/arunahuja94/react-native-flip-card-plus.git
创建时间: 2021-04-06T19:15:08Z
项目社区:https://github.com/arunahuja94/react-native-flip-card-plus

开源协议:MIT License

下载


react-native-flip-card-plus

The card component which has a motion of flip for React Native(Android/ios) with gestures

Installation

npm i react-native-flip-card-plus

Look and feel

Once you’re up and running


Product: demo
Product: demo

Usage with single card

  1. import React, { Component } from 'react';
  2. import {
  3. Text,
  4. View,
  5. Button,
  6. StyleSheet,
  7. TouchableOpacity,
  8. Pressable,
  9. } from 'react-native';
  10. import FlipCard from "react-native-flip-card-plus";
  11. export default class App extends Component {
  12. constructor(props) {
  13. super(props);
  14. this.card = React.createRef();
  15. }
  16. render() {
  17. return (
  18. <View style={styles.container}>
  19. <FlipCard
  20. flipDirection={"h"}
  21. style={styles.cardContainer}
  22. ref={(card) => (this.card = card)}
  23. onFlipStart={() => console.log('onFlipStart')}
  24. onFlipEnd={() => console.log('onFlipEnd')}>
  25. <Pressable
  26. style={styles.card}
  27. onLongPress={() => alert('onLongPress')}>
  28. <Text style={styles.label}>FRONT</Text>
  29. </Pressable>
  30. <Pressable style={styles.card} onPress={() => alert('onPress')}>
  31. <Text style={styles.label}>BACK</Text>
  32. </Pressable>
  33. </FlipCard>
  34. <View style={styles.manualTriggers}>
  35. <Pressable
  36. style={styles.trigger}
  37. onPress={() => this.card.flipHorizontal()}>
  38. <Text style={{ color: 'white' }}>Horizontal</Text>
  39. </Pressable>
  40. <Pressable
  41. style={styles.trigger}
  42. onPress={() => this.card.flipVertical()}>
  43. <Text style={{ color: 'white' }}>Vetical</Text>
  44. </Pressable>
  45. </View>
  46. </View>
  47. );
  48. }
  49. }
  50. const styles = StyleSheet.create({
  51. container: {
  52. flex: 1,
  53. justifyContent: 'center',
  54. alignItems: 'center',
  55. backgroundColor: '#F5FCFF',
  56. },
  57. cardContainer: {
  58. width: 220,
  59. height: 270,
  60. },
  61. card: {
  62. width: 220,
  63. height: 270,
  64. justifyContent: 'center',
  65. alignItems: 'center',
  66. backgroundColor: '#FE474C',
  67. borderRadius: 5,
  68. shadowColor: 'rgba(0,0,0,0.5)',
  69. shadowOffset: {
  70. width: 0,
  71. height: 1,
  72. },
  73. shadowOpacity: 0.5,
  74. },
  75. label: {
  76. textAlign: 'center',
  77. fontSize: 25,
  78. fontFamily: 'System',
  79. color: '#ffffff',
  80. backgroundColor: 'transparent',
  81. },
  82. manualTriggers: {
  83. flexDirection: 'row',
  84. },
  85. trigger: {
  86. backgroundColor: 'black',
  87. margin: 20,
  88. paddingHorizontal: 10,
  89. paddingVertical: 5,
  90. borderRadius: 5,
  91. shadowColor: 'rgba(0,0,0,0.5)',
  92. shadowOffset: {
  93. width: 0,
  94. height: 1,
  95. },
  96. shadowOpacity: 0.5,
  97. },
  98. });

Usage with multiple cards (MAP)

  1. import React, { Component } from 'react';
  2. import { Text, View, Button, StyleSheet, Pressable } from 'react-native';
  3. import FlipCard from "react-native-flip-card-plus";
  4. export default class App extends Component {
  5. constructor(props) {
  6. super(props);
  7. this.multiCardRef = [];
  8. this.state = {
  9. cards: ['CARD1', 'CARD2'],
  10. };
  11. }
  12. render() {
  13. return (
  14. <View style={styles.container}>
  15. {this.state.cards.map((item, index) => {
  16. return (
  17. <>
  18. <FlipCard
  19. flipDirection={'h'}
  20. style={styles.cardContainer}
  21. onFlipStart={() => console.log('onFlipStart')}
  22. onFlipEnd={() => console.log('onFlipEnd')}
  23. ref={(card) => (this.multiCardRef['card' + index] = card)}>
  24. <Pressable
  25. style={styles.card}
  26. onLongPress={() => alert('onLongPress')}>
  27. <Text style={styles.label}>{item} Front</Text>
  28. </Pressable>
  29. <Pressable style={styles.card} onPress={() => alert('onPress')}>
  30. <Text style={styles.label}>{item} Back</Text>
  31. </Pressable>
  32. </FlipCard>
  33. <View style={styles.manualTriggers}>
  34. <Pressable
  35. style={styles.trigger}
  36. onPress={() =>
  37. this.multiCardRef['card' + index].flipHorizontal()
  38. }>
  39. <Text style={{ color: 'white' }}>Horizontal</Text>
  40. </Pressable>
  41. <Pressable
  42. style={styles.trigger}
  43. onPress={() =>
  44. this.multiCardRef['card' + index].flipVertical()
  45. }>
  46. <Text style={{ color: 'white' }}>Vetical</Text>
  47. </Pressable>
  48. </View>
  49. </>
  50. );
  51. })}
  52. </View>
  53. );
  54. }
  55. }
  56. const styles = StyleSheet.create({
  57. container: {
  58. flex: 1,
  59. justifyContent: 'center',
  60. alignItems: 'center',
  61. backgroundColor: '#F5FCFF',
  62. },
  63. cardContainer: {
  64. width: 220,
  65. height: 270,
  66. },
  67. card: {
  68. width: 220,
  69. height: 270,
  70. justifyContent: 'center',
  71. alignItems: 'center',
  72. backgroundColor: '#FE474C',
  73. borderRadius: 5,
  74. shadowColor: 'rgba(0,0,0,0.5)',
  75. shadowOffset: {
  76. width: 0,
  77. height: 1,
  78. },
  79. shadowOpacity: 0.5,
  80. },
  81. label: {
  82. textAlign: 'center',
  83. fontSize: 25,
  84. fontFamily: 'System',
  85. color: '#ffffff',
  86. backgroundColor: 'transparent',
  87. },
  88. manualTriggers: {
  89. flexDirection: 'row',
  90. },
  91. trigger: {
  92. backgroundColor: 'black',
  93. margin: 20,
  94. paddingHorizontal: 10,
  95. paddingVertical: 5,
  96. borderRadius: 5,
  97. shadowColor: 'rgba(0,0,0,0.5)',
  98. shadowOffset: {
  99. width: 0,
  100. height: 1,
  101. },
  102. shadowOpacity: 0.5,
  103. },
  104. });

props

Props type description required default
style object container style {}
duration number flip duration 1000
flipZoom number zoom level on flip 0.09
flipDirection string ‘h’ or ‘v’ if swipeable ‘h’
perspective number 800
flipHorizontal function Flip horizontal trigger
flipVertical function Flip vertical trigger
swipeable bool enable/disable gesture swipe true

events

Props type description
onFlipStart func function to be called when the flip-animation starts. it receives the card-sides index
onFlipEnd func function to be called when the flip-animation ends. it receives the card-sides index

Credits

Inspired by react-native-card-flip