@xhsreds/reds-rn-next 0.10.1-beta202512112152 → 0.10.1-beta202512161121

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.
Files changed (49) hide show
  1. package/coverage/.tmp/coverage-0.json +1 -1
  2. package/coverage/.tmp/coverage-1.json +1 -1
  3. package/coverage/.tmp/coverage-10.json +1 -1
  4. package/coverage/.tmp/coverage-11.json +1 -1
  5. package/coverage/.tmp/coverage-12.json +1 -1
  6. package/coverage/.tmp/coverage-13.json +1 -1
  7. package/coverage/.tmp/coverage-15.json +1 -1
  8. package/coverage/.tmp/coverage-16.json +1 -1
  9. package/coverage/.tmp/coverage-17.json +1 -1
  10. package/coverage/.tmp/coverage-18.json +1 -1
  11. package/coverage/.tmp/coverage-19.json +1 -1
  12. package/coverage/.tmp/coverage-2.json +1 -1
  13. package/coverage/.tmp/coverage-20.json +1 -1
  14. package/coverage/.tmp/coverage-21.json +1 -1
  15. package/coverage/.tmp/coverage-22.json +1 -1
  16. package/coverage/.tmp/coverage-24.json +1 -1
  17. package/coverage/.tmp/coverage-25.json +1 -1
  18. package/coverage/.tmp/coverage-26.json +1 -1
  19. package/coverage/.tmp/coverage-27.json +1 -1
  20. package/coverage/.tmp/coverage-28.json +1 -1
  21. package/coverage/.tmp/coverage-30.json +1 -1
  22. package/coverage/.tmp/coverage-32.json +1 -1
  23. package/coverage/.tmp/coverage-33.json +1 -1
  24. package/coverage/.tmp/coverage-34.json +1 -1
  25. package/coverage/.tmp/coverage-35.json +1 -1
  26. package/coverage/.tmp/coverage-36.json +1 -1
  27. package/coverage/.tmp/coverage-37.json +1 -1
  28. package/coverage/.tmp/coverage-38.json +1 -1
  29. package/coverage/.tmp/coverage-39.json +1 -1
  30. package/coverage/.tmp/coverage-4.json +1 -1
  31. package/coverage/.tmp/coverage-40.json +1 -1
  32. package/coverage/.tmp/coverage-41.json +1 -1
  33. package/coverage/.tmp/coverage-42.json +1 -1
  34. package/coverage/.tmp/coverage-5.json +1 -1
  35. package/coverage/.tmp/coverage-6.json +1 -1
  36. package/coverage/.tmp/coverage-7.json +1 -1
  37. package/coverage/.tmp/coverage-8.json +1 -1
  38. package/coverage/.tmp/coverage-9.json +1 -1
  39. package/lib/cjs/components/Alert/styles.js +1 -1
  40. package/lib/cjs/components/Alert/styles.js.map +1 -1
  41. package/lib/cjs/components/PullRefresh/PullRefresh.js +76 -16
  42. package/lib/cjs/components/PullRefresh/PullRefresh.js.map +1 -1
  43. package/lib/esm/components/Alert/styles.js +1 -1
  44. package/lib/esm/components/Alert/styles.js.map +1 -1
  45. package/lib/esm/components/PullRefresh/PullRefresh.js +76 -16
  46. package/lib/esm/components/PullRefresh/PullRefresh.js.map +1 -1
  47. package/package.json +2 -2
  48. package/src/components/Alert/styles.ts +1 -1
  49. package/src/components/PullRefresh/PullRefresh.tsx +113 -39
@@ -126,14 +126,22 @@ export default function PullRefresh(props: RedsPullRefresh) {
126
126
  // 有拉动距离但是不够设定的下拉高度
127
127
  } else if (panValue > 0) {
128
128
  updatePullState(PullState.FINISH);
129
+ setMoveHeight(0);
130
+ setMovePercent(0);
129
131
  animatedTo(0, () => {
130
132
  setIsPulling(false);
131
133
  updatePullState(PullState.INIT);
134
+ pan.setValue(0);
135
+ pan.flattenOffset();
132
136
  });
133
137
  // 否则就是初始状态
134
138
  } else {
135
139
  updatePullState(PullState.INIT);
136
140
  setIsPulling(false);
141
+ setMoveHeight(0);
142
+ setMovePercent(0);
143
+ pan.setValue(0);
144
+ pan.flattenOffset();
137
145
  }
138
146
  };
139
147
 
@@ -202,7 +210,19 @@ export default function PullRefresh(props: RedsPullRefresh) {
202
210
  if (props.initRefresh && !hasInitRefreshed) {
203
211
  return false;
204
212
  }
205
- return isPulling ? false : scrollY <= 0 && gestureState.vy > 0 && gestureState.vy > Math.abs(gestureState.vx);
213
+ // Block during refresh states
214
+ if (isRefreshing || pullState === PullState.LOADING || pullState === PullState.HOLDING) {
215
+ return false;
216
+ }
217
+ // Block if already pulling
218
+ if (isPulling) {
219
+ return false;
220
+ }
221
+ // Explicitly reject upward swipes
222
+ if (gestureState.vy < 0) {
223
+ return false;
224
+ }
225
+ return scrollY <= 0 && gestureState.vy > 0 && gestureState.vy > Math.abs(gestureState.vx);
206
226
  };
207
227
 
208
228
  // 手势对象
@@ -216,12 +236,13 @@ export default function PullRefresh(props: RedsPullRefresh) {
216
236
  });
217
237
  }
218
238
  return PanResponder.create({
219
- onStartShouldSetPanResponder: canMove,
220
- onStartShouldSetPanResponderCapture: canMove,
239
+ onStartShouldSetPanResponder: () => false,
240
+ onStartShouldSetPanResponderCapture: () => false,
221
241
  onMoveShouldSetPanResponder: canMove,
222
242
  onMoveShouldSetPanResponderCapture: canMove,
223
243
  onPanResponderGrant: () => {
224
244
  animation && animation.stop();
245
+ pan.flattenOffset();
225
246
  // @ts-ignore
226
247
  pan.setOffset(pan._value);
227
248
  updatePullState(PullState.PULLING);
@@ -244,14 +265,26 @@ export default function PullRefresh(props: RedsPullRefresh) {
244
265
  },
245
266
  onPanResponderRelease: onRelease,
246
267
  onPanResponderTerminationRequest() {
247
- return false;
268
+ if (isPulling || pullState === PullState.PULLING) {
269
+ return false;
270
+ }
271
+ return true;
248
272
  },
249
273
  onPanResponderTerminate: onRelease,
250
274
  onShouldBlockNativeResponder() {
251
- return true;
275
+ return isPulling || pullState === PullState.PULLING;
252
276
  },
253
277
  });
254
- }, [isPulling, scrollY, props.initRefresh, hasInitRefreshed, pullAnimHeight, props.nativeAndroidPullRefresh]);
278
+ }, [
279
+ isPulling,
280
+ scrollY,
281
+ props.initRefresh,
282
+ hasInitRefreshed,
283
+ pullAnimHeight,
284
+ props.nativeAndroidPullRefresh,
285
+ isRefreshing,
286
+ pullState,
287
+ ]);
255
288
 
256
289
  // 根据外层传递参数变化进行更新执行(自定义实现启用时)
257
290
  useEffect(() => {
@@ -274,9 +307,14 @@ export default function PullRefresh(props: RedsPullRefresh) {
274
307
  setPullTimeout(
275
308
  //@ts-ignore
276
309
  setTimeout(() => {
310
+ pan.flattenOffset();
311
+ setMoveHeight(0);
312
+ setMovePercent(0);
277
313
  animatedTo(0, () => {
278
314
  setIsPulling(false);
279
315
  updatePullState(PullState.INIT);
316
+ pan.setValue(0);
317
+ pan.flattenOffset();
280
318
  });
281
319
  updatePullState(PullState.FINISH);
282
320
  }, props?.msHoldingTime ?? 1000),
@@ -296,11 +334,14 @@ export default function PullRefresh(props: RedsPullRefresh) {
296
334
 
297
335
  // 重写ScrollView的onScroll事件(自定义:用于手势门控/头部位置; Android 原生:注入 RefreshControl)
298
336
  const scrollContent = useMemo(() => {
299
- return React.Children.map(props.children, (child: any) =>
300
- React.cloneElement(child, {
301
- // 设置滚动响应频率
302
- scrollEventThrottle: 1,
303
- ...(Platform.OS === "android" && props.nativeAndroidPullRefresh
337
+ return React.Children.map(props.children, (child: any) => {
338
+ const originalOnScroll = child.props.onScroll;
339
+ const hasNativeDriver =
340
+ originalOnScroll &&
341
+ (originalOnScroll["__isNative"] === true || (originalOnScroll as any)?._animation?.useNativeDriver === true);
342
+
343
+ const injectedProps =
344
+ Platform.OS === "android" && props.nativeAndroidPullRefresh
304
345
  ? {
305
346
  refreshControl: (
306
347
  <RNRefreshControl
@@ -326,37 +367,70 @@ export default function PullRefresh(props: RedsPullRefresh) {
326
367
  />
327
368
  ),
328
369
  onScroll: (evt: any) => {
329
- if (child.props.onScroll && typeof child.props.onScroll === "function") {
330
- child.props.onScroll(evt);
370
+ if (originalOnScroll && typeof originalOnScroll === "function") {
371
+ originalOnScroll(evt);
331
372
  }
332
373
  },
333
374
  }
334
- : {
335
- onScroll: (evt: any) => {
336
- setScrollY(evt.nativeEvent.contentOffset.y);
337
- // iOS下拉刷新Loading时,ScrollView向上滑动的时候,refreshControl部分同样上滑
338
- if (pullState === PullState.LOADING && evt.nativeEvent.contentOffset.y > 0) {
339
- const y = Math.max(0, pullAnimHeight - evt.nativeEvent.contentOffset.y);
340
- viewRef.current &&
341
- viewRef.current.setNativeProps({
342
- style: {
343
- transform: [{ translateY: y }],
344
- },
345
- });
346
- animatedViewRef.current &&
347
- animatedViewRef.current.setNativeProps({
348
- style: {
349
- transform: [{ translateY: y }],
350
- },
351
- });
352
- }
353
- if (child.props.onScroll && typeof child.props.onScroll === "function") {
354
- child.props.onScroll(evt);
355
- }
356
- },
357
- }),
358
- }),
359
- );
375
+ : hasNativeDriver
376
+ ? {
377
+ // When the child uses native-driver Animated.event, keep it intact to avoid crashes
378
+ onScroll: originalOnScroll,
379
+ onMomentumScrollEnd: (evt: any) => {
380
+ setScrollY(evt.nativeEvent.contentOffset.y);
381
+ child.props.onMomentumScrollEnd && child.props.onMomentumScrollEnd(evt);
382
+ },
383
+ onScrollEndDrag: (evt: any) => {
384
+ setScrollY(evt.nativeEvent.contentOffset.y);
385
+ // Keep header position in loading state
386
+ if (pullState === PullState.LOADING && evt.nativeEvent.contentOffset.y > 0) {
387
+ const y = Math.max(0, pullAnimHeight - evt.nativeEvent.contentOffset.y);
388
+ viewRef.current &&
389
+ viewRef.current.setNativeProps({
390
+ style: {
391
+ transform: [{ translateY: y }],
392
+ },
393
+ });
394
+ animatedViewRef.current &&
395
+ animatedViewRef.current.setNativeProps({
396
+ style: {
397
+ transform: [{ translateY: y }],
398
+ },
399
+ });
400
+ }
401
+ child.props.onScrollEndDrag && child.props.onScrollEndDrag(evt);
402
+ },
403
+ }
404
+ : {
405
+ onScroll: (evt: any) => {
406
+ setScrollY(evt.nativeEvent.contentOffset.y);
407
+ // iOS下拉刷新Loading时,ScrollView向上滑动的时候,refreshControl部分同样上滑
408
+ if (pullState === PullState.LOADING && evt.nativeEvent.contentOffset.y > 0) {
409
+ const y = Math.max(0, pullAnimHeight - evt.nativeEvent.contentOffset.y);
410
+ viewRef.current &&
411
+ viewRef.current.setNativeProps({
412
+ style: {
413
+ transform: [{ translateY: y }],
414
+ },
415
+ });
416
+ animatedViewRef.current &&
417
+ animatedViewRef.current.setNativeProps({
418
+ style: {
419
+ transform: [{ translateY: y }],
420
+ },
421
+ });
422
+ }
423
+ if (originalOnScroll && typeof originalOnScroll === "function") {
424
+ originalOnScroll(evt);
425
+ }
426
+ },
427
+ };
428
+
429
+ return React.cloneElement(child, {
430
+ scrollEventThrottle: 1,
431
+ ...injectedProps,
432
+ });
433
+ });
360
434
  }, [
361
435
  pullState,
362
436
  props.children,