@mpxjs/webpack-plugin 2.10.1-beta.10-1 → 2.10.1-beta.10-3

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.
@@ -83,6 +83,7 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
83
83
  };
84
84
  }, []);
85
85
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout });
86
+ const lastOffset = useRef(0);
86
87
  if (scrollX && scrollY) {
87
88
  warn('scroll-x and scroll-y cannot be set to true at the same time, Mpx will use the value of scroll-y as the criterion');
88
89
  }
@@ -130,7 +131,8 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
130
131
  function onStartReached(e) {
131
132
  const { bindscrolltoupper } = props;
132
133
  const { offset } = scrollOptions.current;
133
- if (bindscrolltoupper && (offset <= upperThreshold)) {
134
+ const isScrollingBackward = offset < lastOffset.current;
135
+ if (bindscrolltoupper && (offset <= upperThreshold) && isScrollingBackward) {
134
136
  if (!hasCallScrollToUpper.current) {
135
137
  bindscrolltoupper(getCustomEvent('scrolltoupper', e, {
136
138
  detail: {
@@ -149,12 +151,13 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
149
151
  const { bindscrolltolower } = props;
150
152
  const { contentLength, visibleLength, offset } = scrollOptions.current;
151
153
  const distanceFromEnd = contentLength - visibleLength - offset;
152
- if (bindscrolltolower && (distanceFromEnd < lowerThreshold)) {
154
+ const isScrollingForward = offset > lastOffset.current;
155
+ if (bindscrolltolower && (distanceFromEnd < lowerThreshold) && isScrollingForward) {
153
156
  if (!hasCallScrollToLower.current) {
154
157
  hasCallScrollToLower.current = true;
155
158
  bindscrolltolower(getCustomEvent('scrolltolower', e, {
156
159
  detail: {
157
- direction: scrollX ? 'right' : 'botttom'
160
+ direction: scrollX ? 'right' : 'bottom'
158
161
  },
159
162
  layoutRef
160
163
  }, props));
@@ -203,6 +206,8 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
203
206
  onStartReached(e);
204
207
  onEndReached(e);
205
208
  updateIntersection();
209
+ // 在 onStartReached、onEndReached 执行完后更新 lastOffset
210
+ lastOffset.current = scrollOptions.current.offset;
206
211
  }
207
212
  function onScrollEnd(e) {
208
213
  const { bindscrollend } = props;
@@ -222,6 +227,7 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
222
227
  onStartReached(e);
223
228
  onEndReached(e);
224
229
  updateIntersection();
230
+ lastOffset.current = scrollOptions.current.offset;
225
231
  }
226
232
  function updateIntersection() {
227
233
  if (enableTriggerIntersectionObserver && intersectionObservers) {
@@ -75,7 +75,10 @@ const _WebView = forwardRef((props, ref) => {
75
75
  };
76
76
  const navigation = useNavigation();
77
77
  useEffect(() => {
78
- const beforeRemoveSubscription = navigation?.addListener?.('beforeRemove', beforeRemoveHandle);
78
+ let beforeRemoveSubscription;
79
+ if (__mpx_mode__ !== 'ios') {
80
+ beforeRemoveSubscription = navigation?.addListener?.('beforeRemove', beforeRemoveHandle);
81
+ }
79
82
  return () => {
80
83
  if (isFunction(beforeRemoveSubscription)) {
81
84
  beforeRemoveSubscription();
@@ -202,6 +202,8 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
202
202
 
203
203
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout })
204
204
 
205
+ const lastOffset = useRef(0)
206
+
205
207
  if (scrollX && scrollY) {
206
208
  warn('scroll-x and scroll-y cannot be set to true at the same time, Mpx will use the value of scroll-y as the criterion')
207
209
  }
@@ -259,7 +261,8 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
259
261
  function onStartReached (e: NativeSyntheticEvent<NativeScrollEvent>) {
260
262
  const { bindscrolltoupper } = props
261
263
  const { offset } = scrollOptions.current
262
- if (bindscrolltoupper && (offset <= upperThreshold)) {
264
+ const isScrollingBackward = offset < lastOffset.current
265
+ if (bindscrolltoupper && (offset <= upperThreshold) && isScrollingBackward) {
263
266
  if (!hasCallScrollToUpper.current) {
264
267
  bindscrolltoupper(
265
268
  getCustomEvent('scrolltoupper', e, {
@@ -280,13 +283,14 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
280
283
  const { bindscrolltolower } = props
281
284
  const { contentLength, visibleLength, offset } = scrollOptions.current
282
285
  const distanceFromEnd = contentLength - visibleLength - offset
283
- if (bindscrolltolower && (distanceFromEnd < lowerThreshold)) {
286
+ const isScrollingForward = offset > lastOffset.current
287
+ if (bindscrolltolower && (distanceFromEnd < lowerThreshold) && isScrollingForward) {
284
288
  if (!hasCallScrollToLower.current) {
285
289
  hasCallScrollToLower.current = true
286
290
  bindscrolltolower(
287
291
  getCustomEvent('scrolltolower', e, {
288
292
  detail: {
289
- direction: scrollX ? 'right' : 'botttom'
293
+ direction: scrollX ? 'right' : 'bottom'
290
294
  },
291
295
  layoutRef
292
296
  }, props)
@@ -341,6 +345,8 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
341
345
  onStartReached(e)
342
346
  onEndReached(e)
343
347
  updateIntersection()
348
+ // 在 onStartReached、onEndReached 执行完后更新 lastOffset
349
+ lastOffset.current = scrollOptions.current.offset
344
350
  }
345
351
 
346
352
  function onScrollEnd (e: NativeSyntheticEvent<NativeScrollEvent>) {
@@ -363,6 +369,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
363
369
  onStartReached(e)
364
370
  onEndReached(e)
365
371
  updateIntersection()
372
+ lastOffset.current = scrollOptions.current.offset
366
373
  }
367
374
  function updateIntersection () {
368
375
  if (enableTriggerIntersectionObserver && intersectionObservers) {
@@ -123,7 +123,10 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
123
123
  const navigation = useNavigation()
124
124
 
125
125
  useEffect(() => {
126
- const beforeRemoveSubscription = navigation?.addListener?.('beforeRemove', beforeRemoveHandle)
126
+ let beforeRemoveSubscription:any
127
+ if (__mpx_mode__ !== 'ios') {
128
+ beforeRemoveSubscription = navigation?.addListener?.('beforeRemove', beforeRemoveHandle)
129
+ }
127
130
  return () => {
128
131
  if (isFunction(beforeRemoveSubscription)) {
129
132
  beforeRemoveSubscription()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.1-beta.10-1",
3
+ "version": "2.10.1-beta.10-3",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"