Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- swipe = () => {
- // Ignore if already scrolling or if there is less than 2 slides
- if (this.internals.isScrolling || this.state.total < 2) {
- return;
- }
- const state = this.state,
- diff = this.state.index + 1,
- x = diff * state.width,
- y = 0;
- // Call scrollTo on scrollView component to perform the swipe
- this.scrollView && this.scrollView.scrollTo({ x, y, animated: true });
- // Update internal scroll state
- this.internals.isScrolling = true;
- // Trigger onScrollEnd manually on android
- if (Platform.OS === 'android') {
- setImmediate(() => {
- this.onScrollEnd({
- nativeEvent: {
- position: diff
- }
- });
- });
- }
- };
- renderScrollView = (pages) => {
- return (
- <ScrollView
- ref={(component) => {
- this.scrollView = component;
- }}
- {...this.props}
- contentContainerStyle={[ styles.wrapper, this.props.style ]}
- onScrollBeginDrag={this.onScrollBegin}
- onMomentumScrollEnd={this.onScrollEnd}
- onScrollEndDrag={this.onScrollEndDrag}
- >
- {pages.map((page, i) => (
- // Render each slide inside a View
- <View style={[ styles.fullScreen, styles.slide ]} key={i}>
- {page}
- </View>
- ))}
- </ScrollView>
- );
- };
- renderPagination = () => {
- if (this.state.total <= 1) {
- return null;
- }
- const ActiveDot = <View style={[ styles.dot, styles.activeDot ]} />,
- Dot = <View style={styles.dot} />;
- let dots = [];
- for (let key = 0; key < this.state.total; key++) {
- dots.push(
- key === this.state.index
- ? // Active dot
- React.cloneElement(ActiveDot, { key })
- : // Other dots
- React.cloneElement(Dot, { key })
- );
- }
- return (
- <View pointerEvents="none" style={[ styles.pagination, styles.fullScreen ]}>
- {dots}
- </View>
- );
- };
- /**
- * Render Continue or Done button
- */
- renderButton = () => {
- const lastScreen = this.state.index === this.state.total - 1;
- const screenHasButton = this.state.index !== 0;
- return (
- <View pointerEvents="box-none" style={[ styles.buttonWrapper, styles.fullScreen ]}>
- {lastScreen ? (
- // Show this button on the last screen
- // TODO: Add a handler that would send a user to your app after onboarding is complete
- <Button title="Start Now" color="#25c6da"/>
- ) : (
- screenHasButton && (
- <Text
- style={styles.button}
- onPress={() => {
- this.swipe(); //this works fine
- }}
- >
- Swipe to continue
- </Text>
- )
- )}
- </View>
- );
- };
- /**
- * Render the component
- */
- render = ({ children, willSwipe } = this.props) => {
- if(willSwipe){
- console.log('trigger') //this works fine
- this.swipe(); //error is here
- }
- return (
- <View style={[ styles.container, styles.fullScreen ]}>
- {this.renderScrollView(children)}
- {this.renderButton()}
- </View>
- );
- };
Add Comment
Please, Sign In to add comment