@mpxjs/webpack-plugin 2.10.5 → 2.10.6

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 (62) hide show
  1. package/lib/index.js +10 -1
  2. package/lib/json-compiler/helper.js +1 -4
  3. package/lib/platform/template/wx/index.js +21 -1
  4. package/lib/resolver/PackageEntryPlugin.js +3 -1
  5. package/lib/runtime/components/react/dist/mpx-button.jsx +7 -2
  6. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +2 -4
  7. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +20 -17
  8. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +7 -2
  9. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +7 -2
  10. package/lib/runtime/components/react/dist/mpx-icon/index.jsx +7 -2
  11. package/lib/runtime/components/react/dist/mpx-image.jsx +9 -2
  12. package/lib/runtime/components/react/dist/mpx-input.jsx +7 -2
  13. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +1 -1
  14. package/lib/runtime/components/react/dist/mpx-label.jsx +7 -2
  15. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +7 -2
  16. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +76 -42
  17. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +11 -13
  18. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +8 -7
  19. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +26 -8
  20. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +9 -2
  21. package/lib/runtime/components/react/dist/mpx-radio.jsx +7 -2
  22. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +7 -2
  23. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +13 -4
  24. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +11 -9
  25. package/lib/runtime/components/react/dist/mpx-swiper.jsx +82 -36
  26. package/lib/runtime/components/react/dist/mpx-switch.jsx +7 -2
  27. package/lib/runtime/components/react/dist/mpx-text.jsx +7 -2
  28. package/lib/runtime/components/react/dist/mpx-video.jsx +7 -2
  29. package/lib/runtime/components/react/dist/mpx-view.jsx +2 -4
  30. package/lib/runtime/components/react/dist/utils.jsx +2 -2
  31. package/lib/runtime/components/react/mpx-button.tsx +9 -1
  32. package/lib/runtime/components/react/mpx-canvas/Image.ts +4 -4
  33. package/lib/runtime/components/react/mpx-canvas/index.tsx +24 -17
  34. package/lib/runtime/components/react/mpx-checkbox-group.tsx +9 -1
  35. package/lib/runtime/components/react/mpx-checkbox.tsx +9 -1
  36. package/lib/runtime/components/react/mpx-icon/index.tsx +9 -1
  37. package/lib/runtime/components/react/mpx-image.tsx +38 -19
  38. package/lib/runtime/components/react/mpx-input.tsx +10 -1
  39. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +1 -1
  40. package/lib/runtime/components/react/mpx-label.tsx +9 -1
  41. package/lib/runtime/components/react/mpx-movable-area.tsx +7 -1
  42. package/lib/runtime/components/react/mpx-movable-view.tsx +75 -42
  43. package/lib/runtime/components/react/mpx-picker/index.tsx +18 -16
  44. package/lib/runtime/components/react/mpx-picker-view/index.tsx +22 -8
  45. package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +34 -30
  46. package/lib/runtime/components/react/mpx-radio-group.tsx +20 -9
  47. package/lib/runtime/components/react/mpx-radio.tsx +9 -1
  48. package/lib/runtime/components/react/mpx-rich-text/index.tsx +10 -2
  49. package/lib/runtime/components/react/mpx-scroll-view.tsx +14 -3
  50. package/lib/runtime/components/react/mpx-swiper-item.tsx +11 -19
  51. package/lib/runtime/components/react/mpx-swiper.tsx +95 -38
  52. package/lib/runtime/components/react/mpx-switch.tsx +10 -2
  53. package/lib/runtime/components/react/mpx-text.tsx +10 -2
  54. package/lib/runtime/components/react/mpx-video.tsx +7 -2
  55. package/lib/runtime/components/react/mpx-view.tsx +8 -4
  56. package/lib/runtime/components/react/utils.tsx +4 -4
  57. package/lib/runtime/components/web/mpx-web-view.vue +1 -1
  58. package/lib/runtime/mpxGlobal.js +1 -0
  59. package/lib/runtime/optionProcessor.d.ts +5 -0
  60. package/lib/template-compiler/bind-this.js +8 -7
  61. package/lib/wxs/pre-loader.js +1 -0
  62. package/package.json +4 -4
@@ -22,6 +22,7 @@ import { FormContext, FormFieldValue, RadioGroupContext, GroupValue } from './co
22
22
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
23
23
  import useNodesRef, { HandlerRef } from './useNodesRef'
24
24
  import { useLayout, useTransformStyle, wrapChildren, extendObject } from './utils'
25
+ import Portal from './mpx-portal'
25
26
 
26
27
  export interface RadioGroupProps {
27
28
  name: string
@@ -71,6 +72,7 @@ const radioGroup = forwardRef<
71
72
  const styleObj = extendObject({}, defaultStyle, style)
72
73
 
73
74
  const {
75
+ hasPositionFixed,
74
76
  hasSelfPercent,
75
77
  normalStyle,
76
78
  hasVarDec,
@@ -156,18 +158,27 @@ const radioGroup = forwardRef<
156
158
  }
157
159
  )
158
160
 
159
- return createElement(View, innerProps, createElement(
160
- RadioGroupContext.Provider,
161
- { value: contextValue },
162
- wrapChildren(
163
- props,
161
+ const finalComponent = createElement(View, innerProps,
162
+ createElement(
163
+ RadioGroupContext.Provider,
164
164
  {
165
- hasVarDec,
166
- varContext: varContextRef.current
167
- }
165
+ value: contextValue
166
+ },
167
+ wrapChildren(
168
+ props,
169
+ {
170
+ hasVarDec,
171
+ varContext: varContextRef.current
172
+ }
173
+ )
168
174
  )
169
175
  )
170
- )
176
+
177
+ if (hasPositionFixed) {
178
+ return createElement(Portal, null, finalComponent)
179
+ }
180
+
181
+ return finalComponent
171
182
  })
172
183
 
173
184
  radioGroup.displayName = 'MpxRadioGroup'
@@ -12,6 +12,7 @@ import useInnerProps, { getCustomEvent } from './getInnerListeners'
12
12
  import useNodesRef, { HandlerRef } from './useNodesRef'
13
13
  import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject } from './utils'
14
14
  import Icon from './mpx-icon'
15
+ import Portal from './mpx-portal'
15
16
 
16
17
  export interface RadioProps {
17
18
  value?: string
@@ -117,6 +118,7 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
117
118
  }
118
119
 
119
120
  const {
121
+ hasPositionFixed,
120
122
  hasSelfPercent,
121
123
  normalStyle,
122
124
  hasVarDec,
@@ -192,7 +194,7 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
192
194
  }
193
195
  }, [checked])
194
196
 
195
- return createElement(View, innerProps,
197
+ const finalComponent = createElement(View, innerProps,
196
198
  createElement(
197
199
  View,
198
200
  { style: defaultStyle },
@@ -213,6 +215,12 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
213
215
  }
214
216
  )
215
217
  )
218
+
219
+ if (hasPositionFixed) {
220
+ return createElement(Portal, null, finalComponent)
221
+ }
222
+
223
+ return finalComponent
216
224
  }
217
225
  )
218
226
 
@@ -9,6 +9,7 @@ import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
9
9
  import { useTransformStyle, useLayout, extendObject } from '../utils'
10
10
  import { WebView, WebViewMessageEvent } from 'react-native-webview'
11
11
  import { generateHTML } from './html'
12
+ import Portal from '../mpx-portal'
12
13
 
13
14
  type Node = {
14
15
  type: 'node' | 'text'
@@ -69,7 +70,8 @@ const _RichText = forwardRef<HandlerRef<View, _RichTextProps>, _RichTextProps>((
69
70
  normalStyle,
70
71
  hasSelfPercent,
71
72
  setWidth,
72
- setHeight
73
+ setHeight,
74
+ hasPositionFixed
73
75
  } = useTransformStyle(Object.assign({
74
76
  width: '100%',
75
77
  height: webViewHeight
@@ -109,7 +111,7 @@ const _RichText = forwardRef<HandlerRef<View, _RichTextProps>, _RichTextProps>((
109
111
 
110
112
  const html: string = typeof nodes === 'string' ? nodes : jsonToHtmlStr(nodes)
111
113
 
112
- return createElement(View, innerProps,
114
+ let finalComponent: JSX.Element = createElement(View, innerProps,
113
115
  createElement(WebView, {
114
116
  source: { html: generateHTML(html) },
115
117
  onMessage: (event: WebViewMessageEvent) => {
@@ -117,6 +119,12 @@ const _RichText = forwardRef<HandlerRef<View, _RichTextProps>, _RichTextProps>((
117
119
  }
118
120
  })
119
121
  )
122
+
123
+ if (hasPositionFixed) {
124
+ finalComponent = createElement(Portal, null, finalComponent)
125
+ }
126
+
127
+ return finalComponent
120
128
  })
121
129
 
122
130
  _RichText.displayName = 'mpx-rich-text'
@@ -35,11 +35,12 @@ import { ScrollView, RefreshControl, Gesture, GestureDetector } from 'react-nati
35
35
  import { View, NativeSyntheticEvent, NativeScrollEvent, LayoutChangeEvent, ViewStyle } from 'react-native'
36
36
  import { isValidElement, Children, JSX, ReactNode, RefObject, useRef, useState, useEffect, forwardRef, useContext, useMemo, createElement } from 'react'
37
37
  import Animated, { useAnimatedRef, useSharedValue, withTiming, useAnimatedStyle, runOnJS } from 'react-native-reanimated'
38
- import { warn } from '@mpxjs/utils'
38
+ import { warn, hasOwn } from '@mpxjs/utils'
39
39
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
40
40
  import useNodesRef, { HandlerRef } from './useNodesRef'
41
41
  import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture, GestureHandler, HIDDEN_STYLE } from './utils'
42
42
  import { IntersectionObserverContext, ScrollViewContext } from './context'
43
+ import Portal from './mpx-portal'
43
44
 
44
45
  interface ScrollViewProps {
45
46
  children?: ReactNode
@@ -194,6 +195,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
194
195
  hasVarDec,
195
196
  varContextRef,
196
197
  hasSelfPercent,
198
+ hasPositionFixed,
197
199
  setWidth,
198
200
  setHeight
199
201
  } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
@@ -643,7 +645,11 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
643
645
 
644
646
  const scrollAdditionalProps: ScrollAdditionalProps = extendObject(
645
647
  {
646
- style: extendObject({}, innerStyle, layoutStyle),
648
+ style: extendObject(hasOwn(innerStyle, 'flex') || hasOwn(innerStyle, 'flexGrow')
649
+ ? {}
650
+ : {
651
+ flexGrow: 0
652
+ }, innerStyle, layoutStyle),
647
653
  pinchGestureEnabled: false,
648
654
  alwaysBounceVertical: false,
649
655
  alwaysBounceHorizontal: false,
@@ -764,7 +770,12 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
764
770
  )
765
771
  )
766
772
 
767
- return hasRefresher ? withRefresherScrollView : commonScrollView
773
+ let scrollViewComponent = hasRefresher ? withRefresherScrollView : commonScrollView
774
+
775
+ if (hasPositionFixed) {
776
+ scrollViewComponent = createElement(Portal, null, scrollViewComponent)
777
+ }
778
+ return scrollViewComponent
768
779
  })
769
780
 
770
781
  _ScrollView.displayName = 'MpxScrollView'
@@ -1,6 +1,6 @@
1
1
  import { View } from 'react-native'
2
2
  import Animated, { useAnimatedStyle, interpolate, SharedValue } from 'react-native-reanimated'
3
- import { ReactNode, forwardRef, useRef, useContext } from 'react'
3
+ import { ReactNode, forwardRef, useRef, useContext, createElement } from 'react'
4
4
  import useInnerProps from './getInnerListeners'
5
5
  import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
6
6
  import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout, extendObject } from './utils'
@@ -95,24 +95,16 @@ const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProp
95
95
  transform: transformStyle
96
96
  })
97
97
  })
98
- return (
99
- <Animated.View
100
- {...innerProps}
101
- style={[innerStyle, layoutStyle, itemAnimatedStyle, customStyle]}
102
- data-itemId={props['item-id']}>
103
- {
104
- wrapChildren(
105
- props,
106
- {
107
- hasVarDec,
108
- varContext: varContextRef.current,
109
- textStyle,
110
- textProps
111
- }
112
- )
113
- }
114
- </Animated.View>
115
- )
98
+ const mergeProps = extendObject({}, innerProps, {
99
+ style: [innerStyle, layoutStyle, itemAnimatedStyle, customStyle],
100
+ 'data-itemId': props['item-id']
101
+ })
102
+ return createElement(Animated.View, mergeProps, wrapChildren(props, {
103
+ hasVarDec,
104
+ varContext: varContextRef.current,
105
+ textStyle,
106
+ textProps
107
+ }))
116
108
  })
117
109
 
118
110
  _SwiperItem.displayName = 'MpxSwiperItem'
@@ -1,12 +1,13 @@
1
1
  import { View, NativeSyntheticEvent, LayoutChangeEvent } from 'react-native'
2
- import { GestureDetector, Gesture } from 'react-native-gesture-handler'
2
+ import { GestureDetector, Gesture, PanGesture } from 'react-native-gesture-handler'
3
3
  import Animated, { useAnimatedStyle, useSharedValue, withTiming, Easing, runOnJS, useAnimatedReaction, cancelAnimation } from 'react-native-reanimated'
4
4
 
5
- import React, { JSX, forwardRef, useRef, useEffect, ReactNode, ReactElement, useMemo } from 'react'
5
+ import React, { JSX, forwardRef, useRef, useEffect, ReactNode, ReactElement, useMemo, createElement } from 'react'
6
6
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
7
7
  import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
8
- import { useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren, extendObject } from './utils'
8
+ import { useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren, extendObject, GestureHandler, flatGesture } from './utils'
9
9
  import { SwiperContext } from './context'
10
+ import Portal from './mpx-portal'
10
11
  /**
11
12
  * ✔ indicator-dots
12
13
  * ✔ indicator-color
@@ -45,7 +46,7 @@ interface SwiperProps {
45
46
  vertical?: boolean
46
47
  style: {
47
48
  [key: string]: any
48
- }
49
+ };
49
50
  'easing-function'?: EaseType
50
51
  'previous-margin'?: string
51
52
  'next-margin'?: string
@@ -53,8 +54,11 @@ interface SwiperProps {
53
54
  'enable-var': boolean
54
55
  'parent-font-size'?: number
55
56
  'parent-width'?: number
56
- 'parent-height'?: number
57
+ 'parent-height'?: number;
57
58
  'external-var-context'?: Record<string, any>
59
+ 'wait-for'?: Array<GestureHandler>
60
+ 'simultaneous-handlers'?: Array<GestureHandler>
61
+ disableGesture?: boolean
58
62
  bindchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
59
63
  }
60
64
 
@@ -126,7 +130,7 @@ const easeMap = {
126
130
 
127
131
  const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((props: SwiperProps, ref): JSX.Element => {
128
132
  const {
129
- 'indicator-dots': showsPagination,
133
+ 'indicator-dots': showPagination,
130
134
  'indicator-color': dotColor = 'rgba(0, 0, 0, .3)',
131
135
  'indicator-active-color': activeDotColor = '#000000',
132
136
  'enable-var': enableVar = false,
@@ -134,21 +138,30 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
134
138
  'parent-width': parentWidth,
135
139
  'parent-height': parentHeight,
136
140
  'external-var-context': externalVarContext,
141
+ 'simultaneous-handlers': originSimultaneousHandlers = [],
142
+ 'wait-for': waitFor = [],
137
143
  style = {},
138
144
  autoplay = false,
139
- circular = false
145
+ circular = false,
146
+ disableGesture = false
140
147
  } = props
141
148
  const easeingFunc = props['easing-function'] || 'default'
142
149
  const easeDuration = props.duration || 500
143
150
  const horizontal = props.vertical !== undefined ? !props.vertical : true
144
151
  const nodeRef = useRef<View>(null)
145
- useNodesRef<View, SwiperProps>(props, ref, nodeRef, {})
152
+ // 手势协同gesture 1.0
153
+ const swiperGestureRef = useRef<PanGesture>()
154
+ useNodesRef<View, SwiperProps>(props, ref, nodeRef, {
155
+ // scrollView内部会过滤是否绑定了gestureRef,withRef(swiperGestureRef)给gesture对象设置一个ref(2.0版本)
156
+ gestureRef: swiperGestureRef
157
+ })
146
158
  // 计算transfrom之类的
147
159
  const {
148
160
  normalStyle,
149
161
  hasVarDec,
150
162
  varContextRef,
151
163
  hasSelfPercent,
164
+ hasPositionFixed,
152
165
  setWidth,
153
166
  setHeight
154
167
  } = useTransformStyle(style, {
@@ -195,6 +208,27 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
195
208
  const moveTime = useSharedValue(0)
196
209
  const timerId = useRef(0 as number | ReturnType<typeof setTimeout>)
197
210
  const intervalTimer = props.interval || 500
211
+
212
+ const simultaneousHandlers = flatGesture(originSimultaneousHandlers)
213
+ const waitForHandlers = flatGesture(waitFor)
214
+ // 判断gesture手势是否需要协同处理、等待手势失败响应
215
+ const gestureSwitch = useRef(false)
216
+ // 初始化上一次的手势
217
+ const prevSimultaneousHandlersRef = useRef<Array<GestureHandler>>(originSimultaneousHandlers || [])
218
+ const prevWaitForHandlersRef = useRef<Array<GestureHandler>>(waitFor || [])
219
+ const hasSimultaneousHandlersChanged = prevSimultaneousHandlersRef.current.length !== (originSimultaneousHandlers?.length || 0) ||
220
+ (originSimultaneousHandlers || []).some((handler, index) => handler !== prevSimultaneousHandlersRef.current[index])
221
+
222
+ const hasWaitForHandlersChanged = prevWaitForHandlersRef.current.length !== (waitFor?.length || 0) ||
223
+ (waitFor || []).some((handler, index) => handler !== prevWaitForHandlersRef.current[index])
224
+
225
+ if (hasSimultaneousHandlersChanged || hasWaitForHandlersChanged) {
226
+ gestureSwitch.current = !gestureSwitch.current
227
+ }
228
+ // 存储上一次的手势
229
+ prevSimultaneousHandlersRef.current = originSimultaneousHandlers || []
230
+ prevWaitForHandlersRef.current = waitFor || []
231
+
198
232
  const {
199
233
  // 存储layout布局信息
200
234
  layoutRef,
@@ -248,7 +282,6 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
248
282
  })
249
283
 
250
284
  function renderPagination () {
251
- if (children.length <= 1) return null
252
285
  const activeColor = activeDotColor || '#007aff'
253
286
  const unActionColor = dotColor || 'rgba(0,0,0,.2)'
254
287
  // 正常渲染所有dots
@@ -491,7 +524,6 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
491
524
  offset.value = getOffset(currentIndex.value, step.value)
492
525
  }
493
526
  }, [circular, preMargin])
494
-
495
527
  const { gestureHandler } = useMemo(() => {
496
528
  function getTargetPosition (eventData: EventDataType) {
497
529
  'worklet'
@@ -574,6 +606,15 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
574
606
  })
575
607
  }
576
608
  }
609
+ function handleBackInit () {
610
+ 'worklet'
611
+ // 微信的效果
612
+ // 1. 只有一个元素,即使设置了circular,也不会产生循环的效果,2. 可以响应手势,但是会有回弹的效果
613
+ offset.value = withTiming(0, {
614
+ duration: easeDuration,
615
+ easing: easeMap[easeingFunc]
616
+ })
617
+ }
577
618
  function handleBack (eventData: EventDataType) {
578
619
  'worklet'
579
620
  const { translation } = eventData
@@ -675,7 +716,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
675
716
  return
676
717
  }
677
718
  const { isBoundary, resetOffset } = reachBoundary(eventData)
678
- if (isBoundary && circularShared.value) {
719
+ if (childrenLength.value > 1 && isBoundary && circularShared.value) {
679
720
  offset.value = resetOffset
680
721
  } else {
681
722
  offset.value = moveDistance + offset.value
@@ -691,6 +732,9 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
691
732
  const eventData = {
692
733
  translation: moveDistance
693
734
  }
735
+ if (childrenLength.value === 1) {
736
+ return handleBackInit()
737
+ }
694
738
  // 用户手指按下起来, 需要计算正确的位置, 比如在滑动过程中突然按下然后起来,需要计算到正确的位置
695
739
  if (!circularShared.value && !canMove(eventData)) {
696
740
  return
@@ -702,10 +746,25 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
702
746
  handleEnd(eventData)
703
747
  }
704
748
  })
749
+ .withRef(swiperGestureRef)
750
+ // swiper横向,当y轴滑动5像素手势失效;swiper纵向只响应swiper的滑动事件
751
+ if (dir === 'x') {
752
+ gesturePan.activeOffsetX([-2, 2]).failOffsetY([-5, 5])
753
+ } else {
754
+ gesturePan.activeOffsetY([-2, 2]).failOffsetX([-5, 5])
755
+ }
756
+ // 手势协同2.0
757
+ if (simultaneousHandlers && simultaneousHandlers.length) {
758
+ gesturePan.simultaneousWithExternalGesture(...simultaneousHandlers)
759
+ }
760
+
761
+ if (waitForHandlers && waitForHandlers.length) {
762
+ gesturePan.requireExternalGestureToFail(...waitForHandlers)
763
+ }
705
764
  return {
706
765
  gestureHandler: gesturePan
707
766
  }
708
- }, [])
767
+ }, [gestureSwitch.current])
709
768
 
710
769
  const animatedStyles = useAnimatedStyle(() => {
711
770
  if (dir === 'x') {
@@ -715,34 +774,32 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
715
774
  }
716
775
  })
717
776
 
718
- function renderSwiper () {
719
- const arrPages: Array<ReactNode> | ReactNode = renderItems()
720
- return (<View style={[normalStyle, layoutStyle, styles.swiper]} {...layoutProps} {...innerProps}>
721
- <Animated.View style={[{
722
- flexDirection: dir === 'x' ? 'row' : 'column',
723
- width: '100%',
724
- height: '100%'
725
- }, animatedStyles]}>
726
- {wrapChildren({
727
- children: arrPages
728
- }, {
729
- hasVarDec,
730
- varContext: varContextRef.current,
731
- textStyle,
732
- textProps
733
- })}
734
- </Animated.View>
735
- {showsPagination && renderPagination()}
736
- </View>)
777
+ let finalComponent: JSX.Element
778
+ const arrPages: Array<ReactNode> | ReactNode = renderItems()
779
+ const mergeProps = Object.assign({
780
+ style: [normalStyle, layoutStyle, styles.swiper]
781
+ }, layoutProps, innerProps)
782
+ const animateComponent = createElement(Animated.View, {
783
+ style: [{ flexDirection: dir === 'x' ? 'row' : 'column', width: '100%', height: '100%' }, animatedStyles]
784
+ }, wrapChildren({
785
+ children: arrPages
786
+ }, {
787
+ hasVarDec,
788
+ varContext: varContextRef.current,
789
+ textStyle,
790
+ textProps
791
+ }))
792
+ const renderChildrens = showPagination ? [animateComponent, renderPagination()] : animateComponent
793
+ finalComponent = createElement(View, mergeProps, renderChildrens)
794
+ if (!disableGesture) {
795
+ finalComponent = createElement(GestureDetector, {
796
+ gesture: gestureHandler
797
+ }, finalComponent)
737
798
  }
738
-
739
- if (children.length === 1) {
740
- return renderSwiper()
741
- } else {
742
- return (<GestureDetector gesture={gestureHandler}>
743
- {renderSwiper()}
744
- </GestureDetector>)
799
+ if (hasPositionFixed) {
800
+ finalComponent = createElement(Portal, null, finalComponent)
745
801
  }
802
+ return finalComponent
746
803
  })
747
804
  SwiperWrapper.displayName = 'MpxSwiperWrapper'
748
805
 
@@ -11,6 +11,7 @@ import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
11
11
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
12
12
 
13
13
  import CheckBox from './mpx-checkbox'
14
+ import Portal from './mpx-portal'
14
15
  import { FormContext, FormFieldValue } from './context'
15
16
  import { useTransformStyle, useLayout, extendObject } from './utils'
16
17
 
@@ -62,7 +63,8 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
62
63
  normalStyle,
63
64
  hasSelfPercent,
64
65
  setWidth,
65
- setHeight
66
+ setHeight,
67
+ hasPositionFixed
66
68
  } = useTransformStyle(style, {
67
69
  enableVar,
68
70
  externalVarContext,
@@ -151,7 +153,7 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
151
153
  )
152
154
  }
153
155
 
154
- return createElement(
156
+ let finalComponent: JSX.Element = createElement(
155
157
  Switch,
156
158
  extendObject({}, innerProps, {
157
159
  style: normalStyle,
@@ -161,6 +163,12 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
161
163
  ios_backgroundColor: '#FFF'
162
164
  })
163
165
  )
166
+
167
+ if (hasPositionFixed) {
168
+ finalComponent = createElement(Portal, null, finalComponent)
169
+ }
170
+
171
+ return finalComponent
164
172
  })
165
173
 
166
174
  _Switch.displayName = 'MpxSwitch'
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import { Text, TextStyle, TextProps } from 'react-native'
8
8
  import { useRef, forwardRef, ReactNode, JSX, createElement } from 'react'
9
+ import Portal from './mpx-portal'
9
10
  import useInnerProps from './getInnerListeners'
10
11
  import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
11
12
  import { useTransformStyle, wrapChildren, extendObject } from './utils'
@@ -38,7 +39,8 @@ const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref):
38
39
  const {
39
40
  normalStyle,
40
41
  hasVarDec,
41
- varContextRef
42
+ varContextRef,
43
+ hasPositionFixed
42
44
  } = useTransformStyle(style, {
43
45
  enableVar,
44
46
  externalVarContext,
@@ -68,13 +70,19 @@ const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref):
68
70
  ]
69
71
  )
70
72
 
71
- return createElement(Text, innerProps, wrapChildren(
73
+ let finalComponent:JSX.Element = createElement(Text, innerProps, wrapChildren(
72
74
  props,
73
75
  {
74
76
  hasVarDec,
75
77
  varContext: varContextRef.current
76
78
  }
77
79
  ))
80
+
81
+ if (hasPositionFixed) {
82
+ finalComponent = createElement(Portal, null, finalComponent)
83
+ }
84
+
85
+ return finalComponent
78
86
  })
79
87
 
80
88
  _Text.displayName = 'MpxText'
@@ -74,6 +74,7 @@ import {
74
74
  } from './utils'
75
75
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
76
76
  import useNodesRef, { HandlerRef } from './useNodesRef'
77
+ import Portal from './mpx-portal'
77
78
 
78
79
  interface VideoProps {
79
80
  src: string
@@ -170,7 +171,7 @@ const MpxVideo = forwardRef<HandlerRef<View, VideoProps>, VideoProps>((videoProp
170
171
 
171
172
  propsRef.current = props
172
173
 
173
- const { normalStyle, hasSelfPercent, setWidth, setHeight } =
174
+ const { normalStyle, hasSelfPercent, setWidth, setHeight, hasPositionFixed } =
174
175
  useTransformStyle(extendObject({}, styles.container, style), {
175
176
  enableVar,
176
177
  externalVarContext,
@@ -381,9 +382,13 @@ const MpxVideo = forwardRef<HandlerRef<View, VideoProps>, VideoProps>((videoProp
381
382
  ],
382
383
  { layoutRef }
383
384
  )
384
- return createElement(View, { style: extendObject({}, normalStyle, layoutStyle), ref: viewRef },
385
+ let videoComponent: JSX.Element = createElement(View, { style: extendObject({}, normalStyle, layoutStyle), ref: viewRef },
385
386
  createElement(Video, innerProps)
386
387
  )
388
+ if (hasPositionFixed) {
389
+ videoComponent = createElement(Portal, null, videoComponent)
390
+ }
391
+ return videoComponent
387
392
  })
388
393
 
389
394
  export default MpxVideo
@@ -638,10 +638,14 @@ function useWrapImage (imageStyle?: ExtendedViewStyle, innerStyle?: Record<strin
638
638
  }
639
639
  }
640
640
 
641
- return <View key='backgroundImage' {...needLayout ? { onLayout } : null} style={{ ...inheritStyle(innerStyle), ...StyleSheet.absoluteFillObject, overflow: 'hidden' }}>
642
- {show && type === 'linear' && <LinearGradient useAngle={true} {...imageStyleToProps(preImageInfo, sizeInfo.current as Size, layoutInfo.current as Size)} />}
643
- {show && type === 'image' && (renderImage(imageStyleToProps(preImageInfo, sizeInfo.current as Size, layoutInfo.current as Size), enableFastImage))}
644
- </View>
641
+ const backgroundProps: ViewProps = extendObject({ key: 'backgroundImage' }, needLayout ? { onLayout } : {},
642
+ { style: extendObject({}, inheritStyle(innerStyle), StyleSheet.absoluteFillObject, { overflow: 'hidden' as const }) }
643
+ )
644
+
645
+ return createElement(View, backgroundProps,
646
+ show && type === 'linear' && createElement(LinearGradient, extendObject({ useAngle: true }, imageStyleToProps(preImageInfo, sizeInfo.current as Size, layoutInfo.current as Size))),
647
+ show && type === 'image' && renderImage(imageStyleToProps(preImageInfo, sizeInfo.current as Size, layoutInfo.current as Size), enableFastImage)
648
+ )
645
649
  }
646
650
 
647
651
  interface WrapChildrenConfig {
@@ -1,4 +1,4 @@
1
- import { useEffect, useCallback, useMemo, useRef, ReactNode, ReactElement, isValidElement, useContext, useState, Dispatch, SetStateAction, Children, cloneElement } from 'react'
1
+ import { useEffect, useCallback, useMemo, useRef, ReactNode, ReactElement, isValidElement, useContext, useState, Dispatch, SetStateAction, Children, cloneElement, createElement } from 'react'
2
2
  import { LayoutChangeEvent, TextStyle, ImageProps, Image } from 'react-native'
3
3
  import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn } from '@mpxjs/utils'
4
4
  import { VarContext, ScrollViewContext, RouteContext } from './context'
@@ -503,8 +503,8 @@ export function splitProps<T extends Record<string, any>> (props: T): {
503
503
  interface LayoutConfig {
504
504
  props: Record<string, any>
505
505
  hasSelfPercent: boolean
506
- setWidth: Dispatch<SetStateAction<number>>
507
- setHeight: Dispatch<SetStateAction<number>>
506
+ setWidth?: Dispatch<SetStateAction<number>>
507
+ setHeight?: Dispatch<SetStateAction<number>>
508
508
  onLayout?: (event?: LayoutChangeEvent) => void
509
509
  nodeRef: React.RefObject<any>
510
510
  }
@@ -636,7 +636,7 @@ export function renderImage (
636
636
  enableFastImage = false
637
637
  ) {
638
638
  const Component: React.ComponentType<ImageProps | FastImageProps> = enableFastImage ? FastImage : Image
639
- return <Component {...imageProps} />
639
+ return createElement(Component, imageProps)
640
640
  }
641
641
 
642
642
  export function pickStyle (styleObj: Record<string, any> = {}, pickedKeys: Array<string>, callback?: (key: string, val: number | string) => number | string) {
@@ -197,4 +197,4 @@ export default {
197
197
  right: 0;
198
198
  bottom: 0;
199
199
  }
200
- </style>
200
+ </style>
@@ -0,0 +1 @@
1
+ module.exports = Object.create(global)
@@ -4,8 +4,13 @@ declare global {
4
4
  [key: string]: any
5
5
  }
6
6
  }
7
+ interface Window {
8
+ mpxGlobal: Record<string, any>
9
+ }
7
10
  }
8
11
 
12
+ declare const mpxGlobal: Record<string, any>
13
+
9
14
  export function processComponentOption (...args: any): object
10
15
 
11
16
  export function getComponent (...args: any): object