@mpxjs/webpack-plugin 2.10.3 → 2.10.4

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 (103) hide show
  1. package/lib/config.js +2 -1
  2. package/lib/index.js +1 -1
  3. package/lib/platform/json/wx/index.js +6 -3
  4. package/lib/platform/style/wx/index.js +23 -12
  5. package/lib/platform/template/wx/component-config/button.js +19 -2
  6. package/lib/platform/template/wx/component-config/canvas.js +4 -0
  7. package/lib/platform/template/wx/component-config/checkbox-group.js +4 -0
  8. package/lib/platform/template/wx/component-config/checkbox.js +4 -0
  9. package/lib/platform/template/wx/component-config/cover-image.js +7 -1
  10. package/lib/platform/template/wx/component-config/cover-view.js +4 -0
  11. package/lib/platform/template/wx/component-config/fix-component-name.js +3 -2
  12. package/lib/platform/template/wx/component-config/form.js +7 -1
  13. package/lib/platform/template/wx/component-config/icon.js +4 -0
  14. package/lib/platform/template/wx/component-config/image.js +7 -1
  15. package/lib/platform/template/wx/component-config/input.js +18 -3
  16. package/lib/platform/template/wx/component-config/label.js +4 -0
  17. package/lib/platform/template/wx/component-config/movable-area.js +7 -1
  18. package/lib/platform/template/wx/component-config/movable-view.js +12 -3
  19. package/lib/platform/template/wx/component-config/navigator.js +4 -0
  20. package/lib/platform/template/wx/component-config/picker-view-column.js +4 -0
  21. package/lib/platform/template/wx/component-config/picker-view.js +7 -1
  22. package/lib/platform/template/wx/component-config/picker.js +7 -1
  23. package/lib/platform/template/wx/component-config/radio-group.js +4 -0
  24. package/lib/platform/template/wx/component-config/radio.js +4 -0
  25. package/lib/platform/template/wx/component-config/rich-text.js +4 -0
  26. package/lib/platform/template/wx/component-config/root-portal.js +4 -0
  27. package/lib/platform/template/wx/component-config/scroll-view.js +10 -2
  28. package/lib/platform/template/wx/component-config/swiper-item.js +7 -1
  29. package/lib/platform/template/wx/component-config/swiper.js +12 -3
  30. package/lib/platform/template/wx/component-config/switch.js +4 -0
  31. package/lib/platform/template/wx/component-config/text.js +24 -3
  32. package/lib/platform/template/wx/component-config/textarea.js +17 -2
  33. package/lib/platform/template/wx/component-config/unsupported.js +7 -0
  34. package/lib/platform/template/wx/component-config/video.js +10 -2
  35. package/lib/platform/template/wx/component-config/view.js +11 -1
  36. package/lib/platform/template/wx/component-config/web-view.js +4 -0
  37. package/lib/platform/template/wx/index.js +42 -75
  38. package/lib/react/processScript.js +1 -18
  39. package/lib/runtime/components/react/dist/event.config.js +1 -0
  40. package/lib/runtime/components/react/dist/getInnerListeners.js +18 -7
  41. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -1
  42. package/lib/runtime/components/react/dist/mpx-inline-text.jsx +11 -0
  43. package/lib/runtime/components/react/dist/mpx-input.jsx +3 -6
  44. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +2 -2
  45. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +194 -68
  46. package/lib/runtime/components/react/dist/mpx-picker/dateData.js +17 -0
  47. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +178 -96
  48. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +79 -139
  49. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +190 -90
  50. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +60 -75
  51. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +100 -228
  52. package/lib/runtime/components/react/dist/{mpx-picker-view.jsx → mpx-picker-view/index.jsx} +3 -3
  53. package/lib/runtime/components/react/dist/{mpx-picker-view-column.jsx → mpx-picker-view-column/index.jsx} +64 -16
  54. package/lib/runtime/components/react/dist/{mpx-picker-view-column-item.jsx → mpx-picker-view-column/pickerViewColumnItem.jsx} +8 -5
  55. package/lib/runtime/components/react/dist/{pickerFaces.js → mpx-picker-view-column/pickerViewFaces.js} +6 -0
  56. package/lib/runtime/components/react/dist/mpx-popup/index.jsx +61 -0
  57. package/lib/runtime/components/react/dist/mpx-popup/popupBase.jsx +92 -0
  58. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +192 -25
  59. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +8 -7
  60. package/lib/runtime/components/react/dist/mpx-simple-view.jsx +11 -15
  61. package/lib/runtime/components/react/dist/mpx-video.jsx +3 -3
  62. package/lib/runtime/components/react/dist/mpx-web-view.jsx +7 -4
  63. package/lib/runtime/components/react/dist/utils.jsx +2 -1
  64. package/lib/runtime/components/react/event.config.ts +2 -0
  65. package/lib/runtime/components/react/getInnerListeners.ts +28 -25
  66. package/lib/runtime/components/react/mpx-canvas/index.tsx +2 -2
  67. package/lib/runtime/components/react/mpx-inline-text.tsx +18 -0
  68. package/lib/runtime/components/react/mpx-input.tsx +2 -6
  69. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +1 -1
  70. package/lib/runtime/components/react/mpx-picker/date.tsx +226 -69
  71. package/lib/runtime/components/react/mpx-picker/dateData.ts +22 -0
  72. package/lib/runtime/components/react/mpx-picker/index.tsx +239 -118
  73. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +96 -139
  74. package/lib/runtime/components/react/mpx-picker/region.tsx +217 -89
  75. package/lib/runtime/components/react/mpx-picker/selector.tsx +75 -80
  76. package/lib/runtime/components/react/mpx-picker/time.tsx +119 -236
  77. package/lib/runtime/components/react/mpx-picker/type.ts +85 -71
  78. package/lib/runtime/components/react/{mpx-picker-view.tsx → mpx-picker-view/index.tsx} +7 -7
  79. package/lib/runtime/components/react/{mpx-picker-view-column.tsx → mpx-picker-view-column/index.tsx} +70 -19
  80. package/lib/runtime/components/react/{mpx-picker-view-column-item.tsx → mpx-picker-view-column/pickerViewColumnItem.tsx} +8 -5
  81. package/lib/runtime/components/react/{pickerFaces.ts → mpx-picker-view-column/pickerViewFaces.ts} +7 -0
  82. package/lib/runtime/components/react/mpx-popup/index.tsx +86 -0
  83. package/lib/runtime/components/react/mpx-popup/popupBase.tsx +130 -0
  84. package/lib/runtime/components/react/mpx-scroll-view.tsx +249 -43
  85. package/lib/runtime/components/react/mpx-simple-text.tsx +10 -8
  86. package/lib/runtime/components/react/mpx-simple-view.tsx +11 -16
  87. package/lib/runtime/components/react/mpx-video.tsx +2 -2
  88. package/lib/runtime/components/react/mpx-web-view.tsx +7 -4
  89. package/lib/runtime/components/react/types/getInnerListeners.d.ts +5 -1
  90. package/lib/runtime/components/react/types/global.d.ts +1 -1
  91. package/lib/runtime/components/react/utils.tsx +3 -2
  92. package/lib/runtime/components/web/mini-video-controls.min.js +1 -1
  93. package/lib/runtime/components/web/mpx-input.vue +1 -1
  94. package/lib/runtime/stringify.wxs +2 -2
  95. package/lib/template-compiler/compiler.js +8 -8
  96. package/lib/utils/env.js +1 -1
  97. package/package.json +4 -5
  98. /package/lib/runtime/components/react/dist/{pickerVIewContext.js → mpx-picker-view/pickerVIewContext.js} +0 -0
  99. /package/lib/runtime/components/react/dist/{pickerViewIndicator.jsx → mpx-picker-view-column/pickerViewIndicator.jsx} +0 -0
  100. /package/lib/runtime/components/react/dist/{pickerViewMask.jsx → mpx-picker-view-column/pickerViewMask.jsx} +0 -0
  101. /package/lib/runtime/components/react/{pickerVIewContext.ts → mpx-picker-view/pickerVIewContext.ts} +0 -0
  102. /package/lib/runtime/components/react/{pickerViewIndicator.tsx → mpx-picker-view-column/pickerViewIndicator.tsx} +0 -0
  103. /package/lib/runtime/components/react/{pickerViewMask.tsx → mpx-picker-view-column/pickerViewMask.tsx} +0 -0
@@ -10,7 +10,7 @@
10
10
  * ✔ enable-back-to-top
11
11
  * ✘ enable-passive
12
12
  * ✔ refresher-enabled
13
- * refresher-threshold
13
+ * refresher-threshold(仅自定义下拉节点样式支持)
14
14
  * ✔ refresher-default-style(仅 android 支持)
15
15
  * ✔ refresher-background(仅 android 支持)
16
16
  * ✔ refresher-triggered
@@ -31,14 +31,14 @@
31
31
  * ✔ bindscrolltolower
32
32
  * ✔ bindscroll
33
33
  */
34
- import { ScrollView, RefreshControl } from 'react-native-gesture-handler'
34
+ import { ScrollView, RefreshControl, Gesture, GestureDetector } from 'react-native-gesture-handler'
35
35
  import { View, NativeSyntheticEvent, NativeScrollEvent, LayoutChangeEvent, ViewStyle } from 'react-native'
36
- import { JSX, ReactNode, RefObject, useRef, useState, useEffect, forwardRef, useContext, createElement, useMemo } from 'react'
37
- import { useAnimatedRef } from 'react-native-reanimated'
36
+ import { isValidElement, Children, JSX, ReactNode, RefObject, useRef, useState, useEffect, forwardRef, useContext, useMemo, createElement } from 'react'
37
+ import Animated, { useAnimatedRef, useSharedValue, withTiming, useAnimatedStyle, runOnJS } from 'react-native-reanimated'
38
38
  import { warn } from '@mpxjs/utils'
39
39
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
40
40
  import useNodesRef, { HandlerRef } from './useNodesRef'
41
- import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture, GestureHandler } from './utils'
41
+ import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture, GestureHandler, HIDDEN_STYLE } from './utils'
42
42
  import { IntersectionObserverContext, ScrollViewContext } from './context'
43
43
 
44
44
  interface ScrollViewProps {
@@ -46,6 +46,7 @@ interface ScrollViewProps {
46
46
  enhanced?: boolean;
47
47
  bounces?: boolean;
48
48
  style?: ViewStyle;
49
+ scrollEventThrottle?: number;
49
50
  'scroll-x'?: boolean;
50
51
  'scroll-y'?: boolean;
51
52
  'enable-back-to-top'?: boolean;
@@ -58,6 +59,7 @@ interface ScrollViewProps {
58
59
  'refresher-enabled'?: boolean;
59
60
  'refresher-default-style'?: 'black' | 'white' | 'none';
60
61
  'refresher-background'?: string;
62
+ 'refresher-threshold'?: number;
61
63
  'scroll-top'?: number;
62
64
  'scroll-left'?: number;
63
65
  'enable-offset'?: boolean;
@@ -90,7 +92,6 @@ type ScrollAdditionalProps = {
90
92
  onScroll: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
91
93
  onContentSizeChange: (width: number, height: number) => void;
92
94
  onLayout?: (event: LayoutChangeEvent) => void;
93
- scrollEventThrottle: number;
94
95
  scrollsToTop: boolean;
95
96
  showsHorizontalScrollIndicator: boolean;
96
97
  showsVerticalScrollIndicator: boolean;
@@ -106,6 +107,7 @@ type ScrollAdditionalProps = {
106
107
  onScrollEndDrag?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
107
108
  onMomentumScrollEnd?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
108
109
  };
110
+
109
111
  const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, ScrollViewProps>((scrollViewProps: ScrollViewProps = {}, ref): JSX.Element => {
110
112
  const { textProps, innerProps: props = {} } = splitProps(scrollViewProps)
111
113
  const {
@@ -129,6 +131,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
129
131
  'refresher-enabled': refresherEnabled,
130
132
  'refresher-default-style': refresherDefaultStyle,
131
133
  'refresher-background': refresherBackground,
134
+ 'refresher-threshold': refresherThreshold = 45,
132
135
  'show-scrollbar': showScrollbar = true,
133
136
  'scroll-into-view': scrollIntoView = '',
134
137
  'scroll-top': scrollTop = 0,
@@ -148,11 +151,21 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
148
151
  const simultaneousHandlers = flatGesture(originSimultaneousHandlers)
149
152
  const waitForHandlers = flatGesture(waitFor)
150
153
 
151
- const [refreshing, setRefreshing] = useState(true)
152
-
153
154
  const snapScrollTop = useRef(0)
154
155
  const snapScrollLeft = useRef(0)
155
156
 
157
+ const [refreshing, setRefreshing] = useState(false)
158
+
159
+ const [enableScroll, setEnableScroll] = useState(true)
160
+ const enableScrollValue = useSharedValue(true)
161
+
162
+ const [scrollBounces, setScrollBounces] = useState(false)
163
+ const bouncesValue = useSharedValue(!!false)
164
+
165
+ const translateY = useSharedValue(0)
166
+ const isAtTop = useSharedValue(true)
167
+ const refresherHeight = useSharedValue(0)
168
+
156
169
  const scrollOptions = useRef({
157
170
  contentLength: 0,
158
171
  offset: 0,
@@ -168,6 +181,14 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
168
181
 
169
182
  const firstScrollIntoViewChange = useRef<boolean>(false)
170
183
 
184
+ const refreshColor = {
185
+ black: ['#000'],
186
+ white: ['#fff']
187
+ }
188
+
189
+ const { refresherContent, otherContent } = getRefresherContent(props.children)
190
+ const hasRefresher = refresherContent && refresherEnabled
191
+
171
192
  const {
172
193
  normalStyle,
173
194
  hasVarDec,
@@ -203,6 +224,10 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
203
224
 
204
225
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout })
205
226
 
227
+ const hasRefresherLayoutRef = useRef(false)
228
+
229
+ // layout 完成前先隐藏,避免安卓闪烁问题
230
+ const refresherLayoutStyle = useMemo(() => { return !hasRefresherLayoutRef.current ? HIDDEN_STYLE : {} }, [hasRefresherLayoutRef.current])
206
231
  const lastOffset = useRef(0)
207
232
 
208
233
  if (scrollX && scrollY) {
@@ -222,12 +247,6 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
222
247
  }
223
248
  }, [scrollTop, scrollLeft])
224
249
 
225
- useEffect(() => {
226
- if (refreshing !== refresherTriggered) {
227
- setRefreshing(!!refresherTriggered)
228
- }
229
- }, [refresherTriggered])
230
-
231
250
  useEffect(() => {
232
251
  if (scrollIntoView && __selectRef) {
233
252
  if (!firstScrollIntoViewChange.current) {
@@ -239,6 +258,22 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
239
258
  firstScrollIntoViewChange.current = true
240
259
  }, [scrollIntoView])
241
260
 
261
+ useEffect(() => {
262
+ if (refresherEnabled) {
263
+ setRefreshing(!!refresherTriggered)
264
+
265
+ if (!refresherContent) return
266
+
267
+ if (refresherTriggered) {
268
+ translateY.value = withTiming(refresherHeight.value)
269
+ resetScrollState(false)
270
+ } else {
271
+ translateY.value = withTiming(0)
272
+ resetScrollState(true)
273
+ }
274
+ }
275
+ }, [refresherTriggered])
276
+
242
277
  function scrollTo ({ top = 0, left = 0, animated = false } : { top?: number; left?: number; animated?: boolean }) {
243
278
  scrollToOffset(left, top, animated)
244
279
  }
@@ -249,7 +284,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
249
284
  const { nodeRef } = refs.getNodeInstance()
250
285
  nodeRef.current?.measureLayout(
251
286
  scrollViewRef.current,
252
- (left: number, top:number) => {
287
+ (left: number, top: number) => {
253
288
  scrollToOffset(left, top)
254
289
  }
255
290
  )
@@ -333,6 +368,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
333
368
  const { bindscroll } = props
334
369
  const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset
335
370
  const { width: scrollWidth, height: scrollHeight } = e.nativeEvent.contentSize
371
+ isAtTop.value = scrollTop <= 0
336
372
  bindscroll &&
337
373
  bindscroll(
338
374
  getCustomEvent('scroll', e, {
@@ -359,6 +395,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
359
395
  const { bindscrollend } = props
360
396
  const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset
361
397
  const { width: scrollWidth, height: scrollHeight } = e.nativeEvent.contentSize
398
+ isAtTop.value = scrollTop <= 0
362
399
  bindscrollend &&
363
400
  bindscrollend(
364
401
  getCustomEvent('scrollend', e, {
@@ -394,14 +431,6 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
394
431
  }
395
432
  }
396
433
 
397
- function onRefresh () {
398
- const { bindrefresherrefresh } = props
399
- bindrefresherrefresh &&
400
- bindrefresherrefresh(
401
- getCustomEvent('refresherrefresh', {}, { layoutRef }, props)
402
- )
403
- }
404
-
405
434
  function onScrollTouchStart (e: NativeSyntheticEvent<TouchEvent>) {
406
435
  const { bindtouchstart } = props
407
436
  bindtouchstart && bindtouchstart(e)
@@ -462,6 +491,156 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
462
491
  onScrollDrag(e)
463
492
  }
464
493
 
494
+ // 处理刷新
495
+ function onRefresh () {
496
+ if (hasRefresher && refresherTriggered === undefined) {
497
+ // 处理使用了自定义刷新组件,又没设置 refresherTriggered 的情况
498
+ setRefreshing(true)
499
+ setTimeout(() => {
500
+ setRefreshing(false)
501
+ translateY.value = withTiming(0)
502
+ if (!enableScrollValue.value) {
503
+ resetScrollState(true)
504
+ }
505
+ }, 500)
506
+ }
507
+ const { bindrefresherrefresh } = props
508
+ bindrefresherrefresh &&
509
+ bindrefresherrefresh(
510
+ getCustomEvent('refresherrefresh', {}, { layoutRef }, props)
511
+ )
512
+ }
513
+
514
+ function getRefresherContent (children: ReactNode) {
515
+ let refresherContent = null
516
+ const otherContent: ReactNode[] = []
517
+
518
+ Children.forEach(children, (child) => {
519
+ if (isValidElement(child) && child.props.slot === 'refresher') {
520
+ refresherContent = child
521
+ } else {
522
+ otherContent.push(child)
523
+ }
524
+ })
525
+
526
+ return {
527
+ refresherContent,
528
+ otherContent
529
+ }
530
+ }
531
+
532
+ // 刷新控件的动画样式
533
+ const refresherAnimatedStyle = useAnimatedStyle(() => {
534
+ return {
535
+ position: 'absolute',
536
+ left: 0,
537
+ right: 0,
538
+ top: -refresherHeight.value, // 初始隐藏在顶部
539
+ transform: [{ translateY: Math.min(translateY.value, refresherHeight.value) }],
540
+ backgroundColor: refresherBackground || 'transparent'
541
+ }
542
+ })
543
+
544
+ // 内容区域的动画样式 - 只有内容区域需要下移
545
+ const contentAnimatedStyle = useAnimatedStyle(() => {
546
+ return {
547
+ transform: [{
548
+ translateY: translateY.value > refresherHeight.value
549
+ ? refresherHeight.value
550
+ : translateY.value
551
+ }]
552
+ }
553
+ })
554
+
555
+ function onRefresherLayout (e: LayoutChangeEvent) {
556
+ const { height } = e.nativeEvent.layout
557
+ refresherHeight.value = height
558
+ hasRefresherLayoutRef.current = true
559
+ }
560
+
561
+ function updateScrollState (newValue: boolean) {
562
+ 'worklet'
563
+ if (enableScrollValue.value !== newValue) {
564
+ enableScrollValue.value = newValue
565
+ runOnJS(setEnableScroll)(newValue)
566
+ }
567
+ }
568
+
569
+ const resetScrollState = (value: boolean) => {
570
+ enableScrollValue.value = value
571
+ setEnableScroll(value)
572
+ }
573
+
574
+ function updateBouncesState (newValue: boolean) {
575
+ 'worklet'
576
+ if (bouncesValue.value !== newValue) {
577
+ bouncesValue.value = newValue
578
+ runOnJS(setScrollBounces)(newValue)
579
+ }
580
+ }
581
+
582
+ // 处理下拉刷新的手势
583
+ const panGesture = Gesture.Pan()
584
+ .onUpdate((event) => {
585
+ 'worklet'
586
+ if (enhanced && !!bounces) {
587
+ if (event.translationY > 0 && bouncesValue.value) {
588
+ updateBouncesState(false)
589
+ } else if ((event.translationY < 0) && !bouncesValue.value) {
590
+ updateBouncesState(true)
591
+ }
592
+ }
593
+
594
+ if (translateY.value <= 0 && event.translationY < 0) {
595
+ // 滑动到顶再向上开启滚动
596
+ updateScrollState(true)
597
+ } else if (event.translationY > 0 && isAtTop.value) {
598
+ // 滚动到顶再向下禁止滚动
599
+ updateScrollState(false)
600
+ }
601
+ // 禁止滚动后切换为滑动
602
+ if (!enableScrollValue.value && isAtTop.value) {
603
+ if (refreshing) {
604
+ // 从完全展开状态(refresherHeight.value)开始计算偏移
605
+ translateY.value = Math.max(
606
+ 0,
607
+ Math.min(
608
+ refresherHeight.value,
609
+ refresherHeight.value + event.translationY
610
+ )
611
+ )
612
+ } else if (event.translationY > 0) {
613
+ // 非刷新状态下的下拉逻辑保持不变
614
+ translateY.value = Math.min(event.translationY * 0.6, refresherHeight.value)
615
+ }
616
+ }
617
+ })
618
+ .onEnd((event) => {
619
+ 'worklet'
620
+ if (enableScrollValue.value) return
621
+ if (refreshing) {
622
+ // 刷新状态下,根据滑动距离决定是否隐藏
623
+ // 如果向下滑动没超过 refresherThreshold,就完全隐藏,如果向上滑动完全隐藏
624
+ if ((event.translationY > 0 && translateY.value < refresherThreshold) || event.translationY < 0) {
625
+ translateY.value = withTiming(0)
626
+ updateScrollState(true)
627
+ runOnJS(setRefreshing)(false)
628
+ } else {
629
+ translateY.value = withTiming(refresherHeight.value)
630
+ }
631
+ } else if (event.translationY >= refresherHeight.value) {
632
+ // 触发刷新
633
+ translateY.value = withTiming(refresherHeight.value)
634
+ runOnJS(onRefresh)()
635
+ } else {
636
+ // 回弹
637
+ translateY.value = withTiming(0)
638
+ updateScrollState(true)
639
+ runOnJS(setRefreshing)(false)
640
+ }
641
+ })
642
+ .simultaneousWithExternalGesture(scrollViewRef)
643
+
465
644
  const scrollAdditionalProps: ScrollAdditionalProps = extendObject(
466
645
  {
467
646
  style: extendObject({}, innerStyle, layoutStyle),
@@ -473,7 +652,8 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
473
652
  scrollsToTop: enableBackToTop,
474
653
  showsHorizontalScrollIndicator: scrollX && showScrollbar,
475
654
  showsVerticalScrollIndicator: scrollY && showScrollbar,
476
- scrollEnabled: scrollX || scrollY,
655
+ scrollEnabled: !enableScroll ? false : !!(scrollX || scrollY),
656
+ bounces: false,
477
657
  ref: scrollViewRef,
478
658
  onScroll: onScroll,
479
659
  onContentSizeChange: onContentSizeChange,
@@ -491,7 +671,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
491
671
 
492
672
  if (enhanced) {
493
673
  Object.assign(scrollAdditionalProps, {
494
- bounces,
674
+ bounces: hasRefresher ? scrollBounces : !!bounces,
495
675
  pagingEnabled
496
676
  })
497
677
  }
@@ -524,35 +704,61 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
524
704
  'bindrefresherrefresh'
525
705
  ], { layoutRef })
526
706
 
527
- const refreshColor = {
528
- black: ['#000'],
529
- white: ['#fff']
530
- }
707
+ const withRefresherScrollView = createElement(
708
+ GestureDetector,
709
+ { gesture: panGesture },
710
+ createElement(
711
+ ScrollView,
712
+ innerProps,
713
+ createElement(
714
+ Animated.View,
715
+ { style: [refresherAnimatedStyle, refresherLayoutStyle], onLayout: onRefresherLayout },
716
+ refresherContent
717
+ ),
718
+ createElement(
719
+ Animated.View,
720
+ { style: contentAnimatedStyle },
721
+ createElement(
722
+ ScrollViewContext.Provider,
723
+ { value: contextValue },
724
+ wrapChildren(
725
+ extendObject({}, props, { children: otherContent }),
726
+ {
727
+ hasVarDec,
728
+ varContext: varContextRef.current,
729
+ textStyle,
730
+ textProps
731
+ }
732
+ )
733
+ )
734
+ )
735
+ )
736
+ )
531
737
 
532
- return createElement(
738
+ const commonScrollView = createElement(
533
739
  ScrollView,
534
- extendObject({}, innerProps, {
740
+ extendObject(innerProps, {
535
741
  refreshControl: refresherEnabled
536
742
  ? createElement(RefreshControl, extendObject({
537
743
  progressBackgroundColor: refresherBackground,
538
744
  refreshing: refreshing,
539
745
  onRefresh: onRefresh
540
- }, (refresherDefaultStyle && refresherDefaultStyle !== 'none' ? { colors: refreshColor[refresherDefaultStyle] } : null)))
746
+ }, refresherDefaultStyle && refresherDefaultStyle !== 'none'
747
+ ? { colors: refreshColor[refresherDefaultStyle] }
748
+ : {}))
541
749
  : undefined
542
750
  }),
543
- createElement(ScrollViewContext.Provider,
544
- { value: contextValue },
545
- wrapChildren(
546
- props,
547
- {
548
- hasVarDec,
549
- varContext: varContextRef.current,
550
- textStyle,
551
- textProps
552
- }
553
- )
751
+ createElement(ScrollViewContext.Provider, { value: contextValue },
752
+ wrapChildren(props, {
753
+ hasVarDec,
754
+ varContext: varContextRef.current,
755
+ textStyle,
756
+ textProps
757
+ })
554
758
  )
555
759
  )
760
+
761
+ return hasRefresher ? withRefresherScrollView : commonScrollView
556
762
  })
557
763
 
558
764
  _ScrollView.displayName = 'MpxScrollView'
@@ -1,18 +1,20 @@
1
1
  import { Text, TextProps } from 'react-native'
2
2
  import { JSX, createElement } from 'react'
3
+ import useInnerProps from './getInnerListeners'
3
4
 
4
- import { extendObject } from './utils'
5
-
6
- const _Text2 = (props: TextProps): JSX.Element => {
5
+ const SimpleText = (props: TextProps): JSX.Element => {
7
6
  const {
8
- allowFontScaling = false
7
+ allowFontScaling = false,
8
+ children
9
9
  } = props
10
10
 
11
- return createElement(Text, extendObject({}, props, {
11
+ const innerProps = useInnerProps(props, {
12
12
  allowFontScaling
13
- }))
13
+ }, [])
14
+
15
+ return createElement(Text, innerProps, children)
14
16
  }
15
17
 
16
- _Text2.displayName = 'MpxSimpleText'
18
+ SimpleText.displayName = 'MpxSimpleText'
17
19
 
18
- export default _Text2
20
+ export default SimpleText
@@ -1,23 +1,18 @@
1
1
  import { View, ViewProps, TextStyle } from 'react-native'
2
- import { createElement, forwardRef, useRef } from 'react'
3
- import useNodesRef, { HandlerRef } from './useNodesRef'
4
- import { extendObject, splitProps, splitStyle, wrapChildren } from './utils'
5
-
6
- const _View2 = forwardRef<HandlerRef<View, ViewProps>, ViewProps>((simpleViewProps: ViewProps, ref) => {
7
- const nodeRef = useRef(null)
2
+ import { createElement } from 'react'
3
+ import { splitProps, splitStyle, wrapChildren } from './utils'
4
+ import useInnerProps from './getInnerListeners'
8
5
 
6
+ const SimpleView = (simpleViewProps: ViewProps): JSX.Element => {
9
7
  const { textProps, innerProps: props = {} } = splitProps(simpleViewProps)
10
8
 
11
9
  const { textStyle, innerStyle = {} } = splitStyle(props.style || {})
12
10
 
13
- useNodesRef(props, ref, nodeRef, {
14
- style: innerStyle || {}
15
- })
11
+ const innerProps = useInnerProps(props, {
12
+ style: innerStyle
13
+ }, [])
16
14
 
17
- return createElement(View, extendObject({}, props, {
18
- style: innerStyle,
19
- ref: nodeRef
20
- }), wrapChildren(
15
+ return createElement(View, innerProps, wrapChildren(
21
16
  props,
22
17
  {
23
18
  hasVarDec: false,
@@ -25,8 +20,8 @@ const _View2 = forwardRef<HandlerRef<View, ViewProps>, ViewProps>((simpleViewPro
25
20
  textProps
26
21
  }
27
22
  ))
28
- })
23
+ }
29
24
 
30
- _View2.displayName = 'MpxSimpleView'
25
+ SimpleView.displayName = 'MpxSimpleView'
31
26
 
32
- export default _View2
27
+ export default SimpleView
@@ -233,7 +233,7 @@ const MpxVideo = forwardRef<HandlerRef<View, VideoProps>, VideoProps>((videoProp
233
233
  {},
234
234
  {
235
235
  detail: {
236
- position: Platform.OS === 'android' ? seekTime * 1000 : seekTime
236
+ position: __mpx_mode__ !== 'ios' ? seekTime * 1000 : seekTime
237
237
  },
238
238
  layoutRef
239
239
  },
@@ -326,7 +326,7 @@ const MpxVideo = forwardRef<HandlerRef<View, VideoProps>, VideoProps>((videoProp
326
326
  if (isDrm) {
327
327
  source.drm = {
328
328
  type: DRMType.FAIRPLAY,
329
- certificateUrl: Platform.OS === 'android' ? provisionUrl : certificateUrl,
329
+ certificateUrl: __mpx_mode__ !== 'ios' ? provisionUrl : certificateUrl,
330
330
  licenseServer: licenseUrl
331
331
  }
332
332
  }
@@ -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()
@@ -140,7 +143,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
140
143
  }
141
144
 
142
145
  const _reload = function () {
143
- if (__mpx_mode__ === 'android') {
146
+ if (__mpx_mode__ !== 'ios') {
144
147
  fristLoaded.current = false // 安卓需要重新设置
145
148
  }
146
149
  setPageLoadErr(false)
@@ -186,7 +189,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
186
189
  }
187
190
 
188
191
  const _onLoadProgress = function (event: WebViewProgressEvent) {
189
- if (__mpx_mode__ === 'android') {
192
+ if (__mpx_mode__ !== 'ios') {
190
193
  canGoBack.current = event.nativeEvent.canGoBack
191
194
  }
192
195
  }
@@ -302,7 +305,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
302
305
  }
303
306
  }
304
307
  const onLoadEnd = function (res: WebViewEvent) {
305
- if (__mpx_mode__ === 'android') {
308
+ if (__mpx_mode__ !== 'ios') {
306
309
  res.persist()
307
310
  setTimeout(() => {
308
311
  onLoadEndHandle(res)
@@ -53,6 +53,9 @@ interface UseInnerPropsConfig {
53
53
  interface DataSetType {
54
54
  [key: string]: string;
55
55
  }
56
+ interface ExtendedNativeTouchEvent extends NativeTouchEvent {
57
+ _stoppedEventTypes?: Set<string>
58
+ }
56
59
 
57
60
  export {
58
61
  NativeTouchEvent,
@@ -64,5 +67,6 @@ export {
64
67
  LayoutRef,
65
68
  SetTimeoutReturnType,
66
69
  DataSetType,
67
- Navigation
70
+ Navigation,
71
+ ExtendedNativeTouchEvent
68
72
  }
@@ -1,4 +1,4 @@
1
- declare let __mpx_mode__: 'wx' | 'ali' | 'swan' | 'qq' | 'tt' | 'web' | 'dd' | 'qa' | 'jd' | 'android' | 'ios'
1
+ declare let __mpx_mode__: 'wx' | 'ali' | 'swan' | 'qq' | 'tt' | 'web' | 'dd' | 'qa' | 'jd' | 'android' | 'ios' | 'harmony'
2
2
  declare module '@mpxjs/utils' {
3
3
  export function isEmptyObject (obj: Object): boolean
4
4
  export function isFunction (fn: unknown): boolean
@@ -20,10 +20,11 @@ export const HIDDEN_STYLE = {
20
20
  opacity: 0
21
21
  }
22
22
 
23
- declare const __mpx_mode__: 'ios' | 'android'
23
+ declare const __mpx_mode__: 'ios' | 'android' | 'harmony'
24
24
 
25
25
  export const isIOS = __mpx_mode__ === 'ios'
26
26
  export const isAndroid = __mpx_mode__ === 'android'
27
+ export const isHarmony = __mpx_mode__ === 'harmony'
27
28
 
28
29
  const varDecRegExp = /^--/
29
30
  const varUseRegExp = /var\(/
@@ -98,7 +99,7 @@ export function isText (ele: ReactNode): ele is ReactElement {
98
99
  if (isValidElement(ele)) {
99
100
  const displayName = (ele.type as ExtendedFunctionComponent)?.displayName
100
101
  const isCustomText = (ele.type as ExtendedFunctionComponent)?.isCustomText
101
- return displayName === 'MpxText' || displayName === 'MpxSimpleText' || displayName === 'Text' || !!isCustomText
102
+ return displayName === 'MpxText' || displayName === 'MpxSimpleText' || displayName === 'MpxInlineText' || displayName === 'Text' || !!isCustomText
102
103
  }
103
104
  return false
104
105
  }