react-native-navigation的迁移库

CustomTransitionOrigin.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. const React = require('react');
  2. const { Component } = require('react');
  3. const { View, Text, Image, TouchableOpacity } = require('react-native');
  4. const { Navigation } = require('react-native-navigation');
  5. import ViewOverflow from 'react-native-view-overflow';
  6. class CustomTransitionOrigin extends Component {
  7. constructor(props) {
  8. super(props);
  9. this.onClickNavigationIcon = this.onClickNavigationIcon.bind(this);
  10. }
  11. static options() {
  12. return {
  13. topBar: {
  14. title: {
  15. fontFamily: 'HelveticaNeue-Italic',
  16. fontSize: 16
  17. },
  18. largeTitle: {
  19. visible: false
  20. },
  21. background: {
  22. translucent: true
  23. }
  24. }
  25. };
  26. }
  27. render() {
  28. return (
  29. <View style={styles.root}>
  30. <Navigation.Element elementId='title1'>
  31. <Text style={[styles.h1, { color: 'black' }]}>Custom Transition Screen</Text>
  32. </Navigation.Element>
  33. <View style={{ flex: 1, justifyContent: 'flex-start' }}>
  34. <TouchableOpacity testID='shared_image1' activeOpacity={0.5} onPress={this.onClickNavigationIcon}>
  35. <Navigation.Element resizeMode='cover' elementId='image1'>
  36. <Image resizeMode='cover' style={styles.gyroImage} source={require('../../img/400.jpeg')} />
  37. </Navigation.Element>
  38. </TouchableOpacity>
  39. <TouchableOpacity style={{ width: 110 }} activeOpacity={0.5} onPress={this.onClickNavigationIcon}>
  40. <View style={{ width: 100, height: 100, marginTop: 10, marginBottom: 30 }}>
  41. <Navigation.Element elementId='image2' style={{ zIndex: 1 }}>
  42. <Image style={styles.gyroImage} source={require('../../img/2048.jpeg')} />
  43. </Navigation.Element>
  44. <ViewOverflow>
  45. <Navigation.Element elementId='image2bg' style={{ width: 100, height: 100, marginLeft: 10, marginTop: -90 }}>
  46. <View style={{ width: 100, height: 100, backgroundColor: 'purple' }} />
  47. </Navigation.Element>
  48. </ViewOverflow>
  49. </View>
  50. </TouchableOpacity>
  51. <TouchableOpacity activeOpacity={0.5} onPress={this.onClickNavigationIcon}>
  52. <Navigation.Element elementId='image3'>
  53. <Image style={styles.gyroImage} source={require('../../img/Icon-87.png')} />
  54. </Navigation.Element>
  55. </TouchableOpacity>
  56. <TouchableOpacity activeOpacity={0.5} onPress={this.onClickNavigationIcon}>
  57. <Navigation.Element elementId='image4'>
  58. <Image style={styles.gyroImage} source={require('../../img/Icon-87.png')} />
  59. </Navigation.Element>
  60. </TouchableOpacity>
  61. </View>
  62. </View>
  63. );
  64. }
  65. onClickNavigationIcon() {
  66. Navigation.push(this.props.componentId, {
  67. component: {
  68. name: 'navigation.playground.CustomTransitionDestination',
  69. options: {
  70. animations: {
  71. push: {
  72. waitForRender: true,
  73. content: {
  74. alpha: {
  75. from: 0,
  76. to: 1,
  77. duration: 250
  78. }
  79. }
  80. }
  81. },
  82. customTransition: {
  83. animations: [
  84. { type: 'sharedElement', fromId: 'title1', toId: 'title2', startDelay: 0, springVelocity: 0.2, duration: 0.5 },
  85. {
  86. type: 'sharedElement', fromId: 'image1', toId: 'customDestinationImage', startDelay: 0, springVelocity: 0.9,
  87. springDamping: 0.9, duration: 0.8, interactivePop: true
  88. },
  89. { type: 'sharedElement', fromId: 'image2bg', toId: 'image2bgDestination', startDelay: 0, duration: 0.8 },
  90. { type: 'sharedElement', fromId: 'image2', toId: 'customDestinationImage2', startDelay: 0, duration: 0.8 },
  91. { fromId: 'image4', x: { to: 50 }, y: { to: 50 }, endAlpha: 0, startDelay: 0, duration: 0.8, springVelocity: 0.5 },
  92. { fromId: 'customDestinationParagraph', startY: 50, startAlpha: 0, endAlpha: 1, startDelay: 0, duration: 0.8 }
  93. ],
  94. duration: 0.8
  95. }
  96. }
  97. }
  98. });
  99. }
  100. }
  101. module.exports = CustomTransitionOrigin;
  102. const styles = {
  103. root: {
  104. alignItems: 'center',
  105. flexGrow: 1,
  106. backgroundColor: '#f5fcff'
  107. },
  108. h1: {
  109. fontSize: 24,
  110. textAlign: 'center',
  111. marginTop: 100
  112. },
  113. footer: {
  114. fontSize: 10,
  115. color: '#888',
  116. marginTop: 10
  117. },
  118. gyroImage: {
  119. marginTop: 10,
  120. width: 100,
  121. height: 100
  122. }
  123. };