Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/components/Scrollpicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ export class Scrollpicker extends React.Component<ScrollpickerProps, Scrollpicke
})
}

componentWillUnmount() {
this.timer && clearTimeout(this.timer)
}

componentWillReceiveProps (nextProps) {

if (nextProps !== this.props) {
Expand Down Expand Up @@ -281,9 +285,12 @@ export class Scrollpicker extends React.Component<ScrollpickerProps, Scrollpicke
}

onScroll (scrollIndex, scrollHeight) {
const targetItemIndex = this.scrollProper(scrollIndex, scrollHeight)
this.timer && clearTimeout(this.timer);
this.timer = setTimeout(()=>{
const targetItemIndex = this.scrollProper(scrollIndex, scrollHeight);
this.props.onChange && this.props.onChange(scrollIndex, targetItemIndex);

this.props.onChange && this.props.onChange(scrollIndex, targetItemIndex)
},100)
}

scrollProper (scrollIndex, scrollHeight, animated?) {
Expand Down Expand Up @@ -354,9 +361,16 @@ export class Scrollpicker extends React.Component<ScrollpickerProps, Scrollpicke
style={styles.scroller}
showsVerticalScrollIndicator={false}
contentContainerStyle={[styles.scrollerContentContainer]}
onScrollEndDrag={(e) => {
this.onScroll(scrollIndex, (e as any).nativeEvent.contentOffset.y)
}}
onScrollEndDrag: (e) => {
this.onScroll(scrollIndex, e.nativeEvent.contentOffset.y);
},
onMomentumScrollBegin:()=>{
this.timer && clearTimeout(this.timer);
this.timer = null
},
onMomentumScrollEnd: (e) => {
this.onScroll(scrollIndex, e.nativeEvent.contentOffset.y);
}
>
{scrollItem.map((item, index) => {
return (
Expand Down