Guest User

Untitled

a guest
May 26th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. swipe = () => {
  2. // Ignore if already scrolling or if there is less than 2 slides
  3. if (this.internals.isScrolling || this.state.total < 2) {
  4. return;
  5. }
  6.  
  7. const state = this.state,
  8. diff = this.state.index + 1,
  9. x = diff * state.width,
  10. y = 0;
  11.  
  12. // Call scrollTo on scrollView component to perform the swipe
  13. this.scrollView && this.scrollView.scrollTo({ x, y, animated: true });
  14.  
  15. // Update internal scroll state
  16. this.internals.isScrolling = true;
  17.  
  18. // Trigger onScrollEnd manually on android
  19. if (Platform.OS === 'android') {
  20. setImmediate(() => {
  21. this.onScrollEnd({
  22. nativeEvent: {
  23. position: diff
  24. }
  25. });
  26. });
  27. }
  28. };
  29.  
  30. renderScrollView = (pages) => {
  31. return (
  32. <ScrollView
  33. ref={(component) => {
  34. this.scrollView = component;
  35. }}
  36. {...this.props}
  37. contentContainerStyle={[ styles.wrapper, this.props.style ]}
  38. onScrollBeginDrag={this.onScrollBegin}
  39. onMomentumScrollEnd={this.onScrollEnd}
  40. onScrollEndDrag={this.onScrollEndDrag}
  41. >
  42. {pages.map((page, i) => (
  43. // Render each slide inside a View
  44. <View style={[ styles.fullScreen, styles.slide ]} key={i}>
  45. {page}
  46. </View>
  47. ))}
  48. </ScrollView>
  49. );
  50. };
  51.  
  52. renderPagination = () => {
  53. if (this.state.total <= 1) {
  54. return null;
  55. }
  56.  
  57. const ActiveDot = <View style={[ styles.dot, styles.activeDot ]} />,
  58. Dot = <View style={styles.dot} />;
  59.  
  60. let dots = [];
  61.  
  62. for (let key = 0; key < this.state.total; key++) {
  63. dots.push(
  64. key === this.state.index
  65. ? // Active dot
  66. React.cloneElement(ActiveDot, { key })
  67. : // Other dots
  68. React.cloneElement(Dot, { key })
  69. );
  70. }
  71.  
  72. return (
  73. <View pointerEvents="none" style={[ styles.pagination, styles.fullScreen ]}>
  74. {dots}
  75. </View>
  76. );
  77. };
  78.  
  79. /**
  80. * Render Continue or Done button
  81. */
  82. renderButton = () => {
  83. const lastScreen = this.state.index === this.state.total - 1;
  84. const screenHasButton = this.state.index !== 0;
  85. return (
  86. <View pointerEvents="box-none" style={[ styles.buttonWrapper, styles.fullScreen ]}>
  87. {lastScreen ? (
  88. // Show this button on the last screen
  89. // TODO: Add a handler that would send a user to your app after onboarding is complete
  90. <Button title="Start Now" color="#25c6da"/>
  91. ) : (
  92. screenHasButton && (
  93. <Text
  94. style={styles.button}
  95. onPress={() => {
  96. this.swipe(); //this works fine
  97. }}
  98. >
  99. Swipe to continue
  100. </Text>
  101. )
  102. )}
  103. </View>
  104. );
  105. };
  106.  
  107. /**
  108. * Render the component
  109. */
  110. render = ({ children, willSwipe } = this.props) => {
  111. if(willSwipe){
  112. console.log('trigger') //this works fine
  113. this.swipe(); //error is here
  114. }
  115. return (
  116. <View style={[ styles.container, styles.fullScreen ]}>
  117. {this.renderScrollView(children)}
  118. {this.renderButton()}
  119. </View>
  120. );
  121. };
Add Comment
Please, Sign In to add comment