diff --git a/src/index.tsx b/src/index.tsx index a2f6a7c..c0aa5ad 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -81,6 +81,7 @@ export default class AppIntroSlider extends React.Component< height: 0, activeIndex: 0, }; + _timeout = 0; flatList: FlatList | undefined; goToSlide = (pageNum: number, triggerOnSlideChange?: boolean) => { @@ -245,6 +246,10 @@ export default class AppIntroSlider extends React.Component< }; _onMomentumScrollEnd = (e: {nativeEvent: NativeScrollEvent}) => { + this._onScrollEnd(e); + }; + + _onScrollEnd = (e: {nativeEvent: NativeScrollEvent}) => { const offset = e.nativeEvent.contentOffset.x; // Touching very very quickly and continuous brings about // a variation close to - but not quite - the width. @@ -260,6 +265,13 @@ export default class AppIntroSlider extends React.Component< this.props.onSlideChange && this.props.onSlideChange(newIndex, lastIndex); }; + _onScroll = (e: {nativeEvent: NativeScrollEvent}) => { + if (Platform.OS === 'web') { + clearTimeout(this._timeout); + this._timeout = setTimeout(() => this._onScrollEnd(e), 150); + } + }; + _onLayout = ({nativeEvent}: LayoutChangeEvent) => { const {width, height} = nativeEvent.layout; if (width !== this.state.width || height !== this.state.height) { @@ -311,6 +323,7 @@ export default class AppIntroSlider extends React.Component< onMomentumScrollEnd={this._onMomentumScrollEnd} extraData={extra} onLayout={this._onLayout} + onScroll={this._onScroll} // make sure all slides are rendered so we can use dots to navigate to them initialNumToRender={data.length} {...otherProps}