@codeleap/mobile 3.15.6 → 3.15.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/mobile",
3
- "version": "3.15.6",
3
+ "version": "3.15.7",
4
4
  "main": "src/index.ts",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -50,6 +50,7 @@ export type PagerProps = React.PropsWithChildren<{
50
50
  scrollLeftEnabled?: boolean
51
51
  scrollDirectionThrottle?: number
52
52
  onSwipeLastPage?: (event: ScrollEvent) => void
53
+ waitEventDispatchTimeout?: number
53
54
  } & ScrollViewProps>
54
55
 
55
56
  const defaultProps: Partial<PagerProps> = {
@@ -62,7 +63,8 @@ const defaultProps: Partial<PagerProps> = {
62
63
  scrollEnabled: true,
63
64
  scrollRightEnabled: true,
64
65
  scrollLeftEnabled: true,
65
- scrollDirectionThrottle: 650
66
+ scrollDirectionThrottle: 650,
67
+ waitEventDispatchTimeout: 250,
66
68
  }
67
69
 
68
70
  export const Pager = (pagerProps: PagerProps) => {
@@ -84,6 +86,7 @@ export const Pager = (pagerProps: PagerProps) => {
84
86
  onScroll,
85
87
  scrollDirectionThrottle,
86
88
  onSwipeLastPage,
89
+ waitEventDispatchTimeout,
87
90
  } = {
88
91
  ...defaultProps,
89
92
  ...pagerProps,
@@ -95,6 +98,8 @@ export const Pager = (pagerProps: PagerProps) => {
95
98
  const [scrollPositionX, setScrollPositionX] = React.useState(0)
96
99
  const [_scrollEnabled, setScrollEnabled] = React.useState(true)
97
100
 
101
+ const waitEventDispatch = useRef(false)
102
+
98
103
  const variantStyles = useDefaultComponentStyle<'u:Pager', typeof PagerPresets>(
99
104
  'u:Pager',
100
105
  {
@@ -127,20 +132,27 @@ export const Pager = (pagerProps: PagerProps) => {
127
132
 
128
133
  const hasScrollDirectionDisabled = !scrollLeftEnabled || !scrollRightEnabled
129
134
 
130
- const handleScrollEnd = useCallback(
131
- (event: ScrollEvent) => {
132
- const x = event?.nativeEvent.contentOffset.x
133
- const toPage = Math.floor(((Math.round(x)) / Math.round(width)))
135
+ const handleScrollEnd = useCallback((event: ScrollEvent) => {
136
+ if (waitEventDispatch.current === true) return null
134
137
 
135
- if (toPage !== page && toPage <= childArr.length - 1) {
136
- setPage(toPage)
137
- setPositionX(toPage * width)
138
- } else if (toPage >= childArr.length - 1 && TypeGuards.isFunction(onSwipeLastPage)) {
139
- onSwipeLastPage?.(event)
140
- }
141
- },
142
- [childArr, page, setPage],
143
- )
138
+ waitEventDispatch.current = true
139
+
140
+ const x = event?.nativeEvent.contentOffset.x
141
+ const toPage = Math.floor(((Math.round(x)) / Math.round(width)))
142
+
143
+ const length = childArr.length - 1
144
+
145
+ if (toPage >= length && TypeGuards.isFunction(onSwipeLastPage) && page >= length) {
146
+ onSwipeLastPage?.(event)
147
+ } else if (toPage !== page && toPage <= length) {
148
+ setPage(toPage)
149
+ setPositionX(toPage * width)
150
+ }
151
+
152
+ setTimeout(() => {
153
+ waitEventDispatch.current = false
154
+ }, waitEventDispatchTimeout)
155
+ }, [childArr, page, setPage, waitEventDispatch.current])
144
156
 
145
157
  const handleScroll = (event: ScrollEvent) => {
146
158
  const scrollX = event?.nativeEvent?.contentOffset?.x