react-native-navigation的迁移库

CustomTransitionDestination.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. const React = require('react');
  2. const { Component } = require('react');
  3. const { View, TouchableOpacity, Image, Text } = require('react-native');
  4. const { Navigation } = require('react-native-navigation');
  5. class CustomTransitionDestination extends Component {
  6. constructor(props) {
  7. super(props);
  8. this.pop = this.pop.bind(this);
  9. this.push = this.push.bind(this);
  10. }
  11. static get options() {
  12. return {
  13. topBar: {
  14. title: {
  15. text: 'ye babyyyyyy',
  16. fontFamily: 'HelveticaNeue-Italic'
  17. },
  18. backButton: {
  19. transition: 'custom'
  20. },
  21. largeTitle: {
  22. visible: false
  23. }
  24. }
  25. };
  26. }
  27. push() {
  28. Navigation.push(this.props.componentId, {
  29. component: {
  30. name: 'navigation.playground.OptionsScreen'
  31. }
  32. });
  33. }
  34. pop() {
  35. Navigation.pop(this.props.componentId, {
  36. customTransition: {
  37. animations: [
  38. { type: 'sharedElement', fromId: 'title2', toId: 'title1', startDelay: 0, springVelocity: 0.2, duration: 0.5 },
  39. { type: 'sharedElement', toId: 'image1', fromId: 'customDestinationImage', startDelay: 0, springVelocity: 0.2, duration: 0.5 },
  40. { type: 'sharedElement', toId: 'image2', fromId: 'customDestinationImage2', startDelay: 0, duration: 0.8 },
  41. { fromId: 'image4', x: { from: 50 }, y: { from: 50 }, startAlpha: 0, startDelay: 0, duration: 0.8, springVelocity: 0.5 },
  42. { fromId: 'customDestinationParagraph', y: { to: 50 }, x: { to: 50 }, endAlpha: 0, startAlpha: 1, startDelay: 0, duration: 0.8 }
  43. ],
  44. duration: 0.8
  45. }
  46. });
  47. }
  48. render() {
  49. return (
  50. <View style={styles.root}>
  51. <View>
  52. <Navigation.Element resizeMode={'contain'} elementId={'customDestinationImage'}>
  53. <Image resizeMode={'contain'} style={{ width: 300, height: 300 }} source={require('../../img/400.jpeg')} />
  54. </Navigation.Element>
  55. <Navigation.Element elementId={'customDestinationImage2'}>
  56. <Image style={{ width: 100, height: 100 }} source={require('../../img/2048.jpeg')} />
  57. </Navigation.Element>
  58. </View>
  59. <TouchableOpacity testID={'shared_image2'} onPress={this.pop}>
  60. <Navigation.Element elementId={'title2'}>
  61. <Text style={styles.h1}>{`Custom Transition Screen`}</Text>
  62. </Navigation.Element>
  63. </TouchableOpacity>
  64. <Navigation.Element elementId={'customDestinationParagraph'}>
  65. <Text style={styles.p}>{`Lorem ipsum dolor sit amet, consectetur adipiscing elit,
  66. sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
  67. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
  68. nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit
  69. in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
  70. cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum`}
  71. </Text>
  72. </Navigation.Element>
  73. </View>
  74. );
  75. }
  76. }
  77. module.exports = CustomTransitionDestination;
  78. const styles = {
  79. root: {
  80. flexGrow: 1,
  81. justifyContent: 'center',
  82. alignItems: 'center',
  83. backgroundColor: '#f5fcff'
  84. },
  85. h1: {
  86. fontSize: 24,
  87. textAlign: 'left',
  88. margin: 10
  89. },
  90. p: {
  91. fontSize: 14,
  92. margin: 10,
  93. textAlign: 'left'
  94. },
  95. footer: {
  96. fontSize: 10,
  97. color: '#888',
  98. marginTop: 10
  99. }
  100. };