@mpxjs/webpack-plugin 2.10.4 → 2.10.5-beta.1

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 (100) hide show
  1. package/lib/index.js +10 -1
  2. package/lib/json-compiler/helper.js +1 -4
  3. package/lib/platform/json/wx/index.js +0 -1
  4. package/lib/platform/style/wx/index.js +22 -21
  5. package/lib/platform/template/wx/component-config/button.js +1 -1
  6. package/lib/platform/template/wx/component-config/index.js +5 -1
  7. package/lib/platform/template/wx/component-config/input.js +1 -1
  8. package/lib/platform/template/wx/component-config/sticky-header.js +23 -0
  9. package/lib/platform/template/wx/component-config/sticky-section.js +23 -0
  10. package/lib/platform/template/wx/index.js +21 -1
  11. package/lib/react/processJSON.js +7 -6
  12. package/lib/react/processScript.js +9 -1
  13. package/lib/react/script-helper.js +5 -1
  14. package/lib/resolver/PackageEntryPlugin.js +3 -1
  15. package/lib/runtime/components/react/context.ts +12 -3
  16. package/lib/runtime/components/react/dist/context.js +4 -1
  17. package/lib/runtime/components/react/dist/event.config.js +0 -2
  18. package/lib/runtime/components/react/dist/getInnerListeners.js +127 -153
  19. package/lib/runtime/components/react/dist/mpx-button.jsx +11 -7
  20. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +2 -4
  21. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +23 -21
  22. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +9 -4
  23. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +9 -5
  24. package/lib/runtime/components/react/dist/mpx-form.jsx +2 -2
  25. package/lib/runtime/components/react/dist/mpx-icon/index.jsx +9 -4
  26. package/lib/runtime/components/react/dist/mpx-image.jsx +11 -4
  27. package/lib/runtime/components/react/dist/mpx-input.jsx +24 -13
  28. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +23 -30
  29. package/lib/runtime/components/react/dist/mpx-label.jsx +9 -5
  30. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +9 -4
  31. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +77 -43
  32. package/lib/runtime/components/react/dist/mpx-navigator.jsx +11 -3
  33. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +12 -14
  34. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +10 -10
  35. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +28 -10
  36. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -4
  37. package/lib/runtime/components/react/dist/mpx-radio.jsx +9 -5
  38. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +9 -4
  39. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +31 -11
  40. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +3 -2
  41. package/lib/runtime/components/react/dist/mpx-simple-view.jsx +3 -3
  42. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +115 -0
  43. package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +45 -0
  44. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +15 -14
  45. package/lib/runtime/components/react/dist/mpx-swiper.jsx +86 -40
  46. package/lib/runtime/components/react/dist/mpx-switch.jsx +10 -7
  47. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -9
  48. package/lib/runtime/components/react/dist/mpx-video.jsx +9 -4
  49. package/lib/runtime/components/react/dist/mpx-view.jsx +15 -10
  50. package/lib/runtime/components/react/dist/mpx-web-view.jsx +13 -13
  51. package/lib/runtime/components/react/dist/useAnimationHooks.js +27 -4
  52. package/lib/runtime/components/react/dist/utils.jsx +99 -98
  53. package/lib/runtime/components/react/event.config.ts +1 -8
  54. package/lib/runtime/components/react/getInnerListeners.ts +146 -192
  55. package/lib/runtime/components/react/mpx-button.tsx +16 -8
  56. package/lib/runtime/components/react/mpx-canvas/Image.ts +4 -4
  57. package/lib/runtime/components/react/mpx-canvas/index.tsx +47 -32
  58. package/lib/runtime/components/react/mpx-checkbox-group.tsx +13 -4
  59. package/lib/runtime/components/react/mpx-checkbox.tsx +17 -10
  60. package/lib/runtime/components/react/mpx-form.tsx +25 -19
  61. package/lib/runtime/components/react/mpx-icon/index.tsx +13 -4
  62. package/lib/runtime/components/react/mpx-image.tsx +42 -22
  63. package/lib/runtime/components/react/mpx-input.tsx +32 -16
  64. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +31 -42
  65. package/lib/runtime/components/react/mpx-label.tsx +13 -6
  66. package/lib/runtime/components/react/mpx-movable-area.tsx +29 -14
  67. package/lib/runtime/components/react/mpx-movable-view.tsx +121 -81
  68. package/lib/runtime/components/react/mpx-navigator.tsx +4 -6
  69. package/lib/runtime/components/react/mpx-picker/index.tsx +24 -19
  70. package/lib/runtime/components/react/mpx-picker-view/index.tsx +39 -22
  71. package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +36 -32
  72. package/lib/runtime/components/react/mpx-radio-group.tsx +24 -12
  73. package/lib/runtime/components/react/mpx-radio.tsx +17 -10
  74. package/lib/runtime/components/react/mpx-rich-text/index.tsx +25 -8
  75. package/lib/runtime/components/react/mpx-scroll-view.tsx +95 -60
  76. package/lib/runtime/components/react/mpx-simple-text.tsx +10 -3
  77. package/lib/runtime/components/react/mpx-simple-view.tsx +10 -4
  78. package/lib/runtime/components/react/mpx-sticky-header.tsx +179 -0
  79. package/lib/runtime/components/react/mpx-sticky-section.tsx +96 -0
  80. package/lib/runtime/components/react/mpx-swiper-item.tsx +42 -43
  81. package/lib/runtime/components/react/mpx-swiper.tsx +142 -79
  82. package/lib/runtime/components/react/mpx-switch.tsx +29 -16
  83. package/lib/runtime/components/react/mpx-text.tsx +26 -15
  84. package/lib/runtime/components/react/mpx-video.tsx +41 -35
  85. package/lib/runtime/components/react/mpx-view.tsx +38 -18
  86. package/lib/runtime/components/react/mpx-web-view.tsx +12 -12
  87. package/lib/runtime/components/react/types/getInnerListeners.d.ts +65 -35
  88. package/lib/runtime/components/react/useAnimationHooks.ts +30 -9
  89. package/lib/runtime/components/react/utils.tsx +107 -103
  90. package/lib/runtime/components/web/mpx-scroll-view.vue +21 -4
  91. package/lib/runtime/components/web/mpx-sticky-header.vue +91 -0
  92. package/lib/runtime/components/web/mpx-sticky-section.vue +15 -0
  93. package/lib/runtime/components/web/mpx-web-view.vue +1 -1
  94. package/lib/runtime/mpxGlobal.js +1 -0
  95. package/lib/runtime/optionProcessor.d.ts +5 -0
  96. package/lib/template-compiler/bind-this.js +8 -7
  97. package/lib/template-compiler/compiler.js +1 -1
  98. package/lib/wxs/pre-loader.js +1 -0
  99. package/package.json +3 -3
  100. package/LICENSE +0 -433
@@ -1,17 +1,16 @@
1
- import { useRef, useMemo, RefObject } from 'react'
2
- import { hasOwn, collectDataset } from '@mpxjs/utils'
1
+ import { useRef, useMemo } from 'react'
2
+ import { collectDataset } from '@mpxjs/utils'
3
3
  import { omit, extendObject, useNavigation } from './utils'
4
- import eventConfigMap, { TAP_EVENTS, LONGPRESS_EVENTS } from './event.config'
4
+ import eventConfigMap from './event.config'
5
5
  import {
6
6
  Props,
7
- AdditionalProps,
7
+ EventConfig,
8
+ RawConfig,
9
+ EventType,
8
10
  RemoveProps,
9
- UseInnerPropsConfig,
10
11
  InnerRef,
11
- SetTimeoutReturnType,
12
12
  LayoutRef,
13
- ExtendedNativeTouchEvent,
14
- Navigation
13
+ ExtendedNativeTouchEvent
15
14
  } from './types/getInnerListeners'
16
15
 
17
16
  const globalEventState = {
@@ -21,21 +20,20 @@ const globalEventState = {
21
20
  const getTouchEvent = (
22
21
  type: string,
23
22
  event: ExtendedNativeTouchEvent,
24
- props: Props,
25
- config: UseInnerPropsConfig,
26
- navigation: Navigation
23
+ config: EventConfig
27
24
  ) => {
25
+ const { navigation, propsRef, layoutRef } = config
26
+ const props = propsRef.current
28
27
  const { y: navigationY = 0 } = navigation?.layout || {}
29
28
  const nativeEvent = event.nativeEvent
30
29
  const { timestamp, pageX, pageY, touches, changedTouches } = nativeEvent
31
30
  const { id } = props
32
- const { layoutRef } = config
33
31
 
34
32
  const currentTarget = extendObject({}, event.currentTarget, {
35
33
  id: id || '',
36
34
  dataset: collectDataset(props),
37
- offsetLeft: layoutRef?.current?.offsetLeft || 0,
38
- offsetTop: layoutRef?.current?.offsetTop || 0
35
+ offsetLeft: layoutRef.current?.offsetLeft || 0,
36
+ offsetTop: layoutRef.current?.offsetTop || 0
39
37
  })
40
38
 
41
39
  const pendingProps = (event as any)._targetInst?.pendingProps || {}
@@ -108,186 +106,129 @@ export const getCustomEvent = (
108
106
  }
109
107
 
110
108
  function handleEmitEvent (
111
- events: string[],
112
- type: string,
113
- oe: ExtendedNativeTouchEvent,
114
- propsRef: Record<string, any>,
115
- config: UseInnerPropsConfig,
116
- navigation: Navigation
109
+ name: string,
110
+ e: ExtendedNativeTouchEvent,
111
+ type: EventType,
112
+ eventConfig: EventConfig
117
113
  ) {
118
- events.forEach((event) => {
119
- if (propsRef.current[event]) {
120
- const match = /^(catch|capture-catch):?(.*?)(?:\.(.*))?$/.exec(event)
121
- // 检查是否已经被上层的 catch 阻止
122
- if ((type === 'tap' || type === 'longpress') && oe._stoppedEventTypes?.has(type)) {
123
- return
124
- }
125
- if (match) {
126
- const eventBase = match[2] || ''
127
- if (eventBase === 'tap' || eventBase === 'longpress') {
128
- // 为 tap、longpress 添加标记,影响后续的冒泡
129
- if (!oe._stoppedEventTypes) {
130
- oe._stoppedEventTypes = new Set()
131
- }
132
- oe._stoppedEventTypes.add(eventBase)
133
- } else {
134
- // 原生 touch 事件使用 stopPropagation
135
- oe.stopPropagation()
136
- }
137
- }
138
- propsRef.current[event](
139
- getTouchEvent(type, oe, propsRef.current, config, navigation)
140
- )
114
+ const { propsRef } = eventConfig
115
+ const eventCfg = eventConfig[name]
116
+ if (eventCfg) {
117
+ if (eventCfg.hasCatch && name !== 'tap' && name !== 'longpress') {
118
+ e.stopPropagation()
141
119
  }
142
- })
120
+ eventCfg[type].forEach((event) => {
121
+ propsRef.current[event]?.(getTouchEvent(name, e, eventConfig))
122
+ })
123
+ }
143
124
  }
144
125
 
145
- function checkIsNeedPress (e: ExtendedNativeTouchEvent, type: 'bubble' | 'capture', ref: RefObject<InnerRef>) {
146
- const tapDetailInfo = ref.current!.mpxPressInfo.detail || { x: 0, y: 0 }
147
- const nativeEvent = e.nativeEvent
148
- const currentPageX = nativeEvent.changedTouches[0].pageX
149
- const currentPageY = nativeEvent.changedTouches[0].pageY
126
+ function checkIsNeedPress (e: ExtendedNativeTouchEvent, type: 'bubble' | 'capture', ref: InnerRef) {
127
+ const tapDetailInfo = ref.current.mpxPressInfo.detail || { x: 0, y: 0 }
128
+ const currentPageX = e.nativeEvent.changedTouches[0].pageX
129
+ const currentPageY = e.nativeEvent.changedTouches[0].pageY
150
130
  if (
151
131
  Math.abs(currentPageX - tapDetailInfo.x) > 3 ||
152
- Math.abs(currentPageY - tapDetailInfo.y) > 3
132
+ Math.abs(currentPageY - tapDetailInfo.y) > 3
153
133
  ) {
154
134
  globalEventState.needPress = false
155
- ref.current!.startTimer[type] &&
156
- clearTimeout(ref.current!.startTimer[type] as SetTimeoutReturnType)
157
- ref.current!.startTimer[type] = null
135
+ ref.current.startTimer[type] && clearTimeout(ref.current.startTimer[type] as unknown as number)
136
+ ref.current.startTimer[type] = null
158
137
  }
159
138
  }
160
139
 
161
- function handleTouchstart (e: ExtendedNativeTouchEvent, type: 'bubble' | 'capture', ref: RefObject<InnerRef>, propsRef: Record<string, any>, config: UseInnerPropsConfig, navigation: Navigation) {
140
+ function handleTouchstart (e: ExtendedNativeTouchEvent, type: EventType, eventConfig: EventConfig) {
141
+ // 阻止事件被释放放回对象池,导致对象复用 _stoppedEventTypes 状态被保留
162
142
  e.persist()
163
- const bubbleTouchEvent = ['catchtouchstart', 'bindtouchstart']
164
- const bubblePressEvent = ['catchlongpress', 'bindlongpress']
165
- const captureTouchEvent = [
166
- 'capture-catchtouchstart',
167
- 'capture-bindtouchstart'
168
- ]
169
- const capturePressEvent = [
170
- 'capture-catchlongpress',
171
- 'capture-bindlongpress'
172
- ]
173
- ref.current!.startTimer[type] = null
143
+ const { innerRef } = eventConfig
174
144
  globalEventState.needPress = true
175
- const nativeEvent = e.nativeEvent
176
- ref.current!.mpxPressInfo.detail = {
177
- x: nativeEvent.changedTouches[0].pageX,
178
- y: nativeEvent.changedTouches[0].pageY
145
+ innerRef.current.mpxPressInfo.detail = {
146
+ x: e.nativeEvent.changedTouches[0].pageX,
147
+ y: e.nativeEvent.changedTouches[0].pageY
179
148
  }
180
- const currentTouchEvent =
181
- type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
182
- const currentPressEvent =
183
- type === 'bubble' ? bubblePressEvent : capturePressEvent
184
- handleEmitEvent(currentTouchEvent, 'touchstart', e, propsRef, config, navigation)
185
- if (LONGPRESS_EVENTS.some(eventName => propsRef.current[eventName])) {
186
- ref.current!.startTimer[type] = setTimeout(() => {
149
+
150
+ handleEmitEvent('touchstart', e, type, eventConfig)
151
+
152
+ if (eventConfig.longpress) {
153
+ if (e._stoppedEventTypes?.has('longpress')) {
154
+ return
155
+ }
156
+ if (eventConfig.longpress.hasCatch) {
157
+ e._stoppedEventTypes = e._stoppedEventTypes || new Set()
158
+ e._stoppedEventTypes.add('longpress')
159
+ }
160
+ innerRef.current.startTimer[type] && clearTimeout(innerRef.current.startTimer[type] as unknown as number)
161
+ innerRef.current.startTimer[type] = setTimeout(() => {
187
162
  // 只要触发过longpress, 全局就不再触发tap
188
163
  globalEventState.needPress = false
189
- handleEmitEvent(currentPressEvent, 'longpress', e, propsRef, config, navigation)
164
+ handleEmitEvent('longpress', e, type, eventConfig)
190
165
  }, 350)
191
166
  }
192
167
  }
193
168
 
194
- function handleTouchmove (e: ExtendedNativeTouchEvent, type: 'bubble' | 'capture', ref: RefObject<InnerRef>, propsRef: Record<string, any>, config: UseInnerPropsConfig, navigation: Navigation) {
195
- const bubbleTouchEvent = ['catchtouchmove', 'bindtouchmove']
196
- const captureTouchEvent = [
197
- 'capture-catchtouchmove',
198
- 'capture-bindtouchmove'
199
- ]
200
- const currentTouchEvent =
201
- type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
202
- handleEmitEvent(currentTouchEvent, 'touchmove', e, propsRef, config, navigation)
203
- if (TAP_EVENTS.some(eventName => propsRef.current[eventName])) {
204
- checkIsNeedPress(e, type, ref)
169
+ function handleTouchmove (e: ExtendedNativeTouchEvent, type: EventType, eventConfig: EventConfig) {
170
+ const { innerRef } = eventConfig
171
+ handleEmitEvent('touchmove', e, type, eventConfig)
172
+ if (eventConfig.tap) {
173
+ checkIsNeedPress(e, type, innerRef)
205
174
  }
206
175
  }
207
176
 
208
- function handleTouchend (e: ExtendedNativeTouchEvent, type: 'bubble' | 'capture', ref: RefObject<InnerRef>, propsRef: Record<string, any>, config: UseInnerPropsConfig, navigation: Navigation) {
209
- // move event may not be triggered
210
- if (TAP_EVENTS.some(eventName => propsRef.current[eventName])) {
211
- checkIsNeedPress(e, type, ref)
212
- }
213
- const bubbleTouchEvent = ['catchtouchend', 'bindtouchend']
214
- const bubbleTapEvent = ['catchtap', 'bindtap']
215
- const captureTouchEvent = [
216
- 'capture-catchtouchend',
217
- 'capture-bindtouchend'
218
- ]
219
- const captureTapEvent = ['capture-catchtap', 'capture-bindtap']
220
- const currentTouchEvent =
221
- type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
222
- const currentTapEvent =
223
- type === 'bubble' ? bubbleTapEvent : captureTapEvent
224
- ref.current!.startTimer[type] &&
225
- clearTimeout(ref.current!.startTimer[type] as SetTimeoutReturnType)
226
- ref.current!.startTimer[type] = null
227
- handleEmitEvent(currentTouchEvent, 'touchend', e, propsRef, config, navigation)
228
- if (globalEventState.needPress) {
229
- if (type === 'bubble' && config.disableTap) {
177
+ function handleTouchend (e: ExtendedNativeTouchEvent, type: EventType, eventConfig: EventConfig) {
178
+ const { innerRef, disableTap } = eventConfig
179
+ handleEmitEvent('touchend', e, type, eventConfig)
180
+ innerRef.current.startTimer[type] && clearTimeout(innerRef.current.startTimer[type] as unknown as number)
181
+ if (eventConfig.tap) {
182
+ checkIsNeedPress(e, type, innerRef)
183
+ if (!globalEventState.needPress || (type === 'bubble' && disableTap) || e._stoppedEventTypes?.has('tap')) {
230
184
  return
231
185
  }
232
- handleEmitEvent(currentTapEvent, 'tap', e, propsRef, config, navigation)
186
+ if (eventConfig.tap.hasCatch) {
187
+ e._stoppedEventTypes = e._stoppedEventTypes || new Set()
188
+ e._stoppedEventTypes.add('tap')
189
+ }
190
+ handleEmitEvent('tap', e, type, eventConfig)
233
191
  }
234
192
  }
235
193
 
236
- function handleTouchcancel (
237
- e: ExtendedNativeTouchEvent,
238
- type: 'bubble' | 'capture',
239
- ref: RefObject<InnerRef>,
240
- propsRef: Record<string, any>,
241
- config: UseInnerPropsConfig,
242
- navigation: Navigation
243
- ) {
244
- const bubbleTouchEvent = ['catchtouchcancel', 'bindtouchcancel']
245
- const captureTouchEvent = [
246
- 'capture-catchtouchcancel',
247
- 'capture-bindtouchcancel'
248
- ]
249
- const currentTouchEvent =
250
- type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
251
- ref.current!.startTimer[type] &&
252
- clearTimeout(ref.current!.startTimer[type] as SetTimeoutReturnType)
253
- ref.current!.startTimer[type] = null
254
- handleEmitEvent(currentTouchEvent, 'touchcancel', e, propsRef, config, navigation)
194
+ function handleTouchcancel (e: ExtendedNativeTouchEvent, type: EventType, eventConfig: EventConfig) {
195
+ const { innerRef } = eventConfig
196
+ handleEmitEvent('touchcancel', e, type, eventConfig)
197
+ innerRef.current.startTimer[type] && clearTimeout(innerRef.current.startTimer[type] as unknown as number)
255
198
  }
256
199
 
257
- function createTouchEventHandler (eventName: 'onTouchStart'|'onTouchMove'|'onTouchEnd'|'onTouchCancel', type: 'bubble' | 'capture') {
258
- return (e: ExtendedNativeTouchEvent, ref: RefObject<InnerRef>, propsRef: Record<string, any>, config: UseInnerPropsConfig, navigation: Navigation) => {
259
- const handlerMap = {
200
+ function createTouchEventHandler (eventName: string, eventConfig: EventConfig) {
201
+ return (e: ExtendedNativeTouchEvent) => {
202
+ const bubbleHandlerMap: Record<string, any> = {
260
203
  onTouchStart: handleTouchstart,
261
204
  onTouchMove: handleTouchmove,
262
205
  onTouchEnd: handleTouchend,
263
206
  onTouchCancel: handleTouchcancel
264
207
  }
265
208
 
266
- const handler = handlerMap[eventName]
267
- if (handler) {
268
- handler(e, type, ref, propsRef, config, navigation)
209
+ const captureHandlerMap: Record<string, any> = {
210
+ onTouchStartCapture: handleTouchstart,
211
+ onTouchMoveCapture: handleTouchmove,
212
+ onTouchEndCapture: handleTouchend,
213
+ onTouchCancelCapture: handleTouchcancel
214
+ }
215
+
216
+ if (bubbleHandlerMap[eventName]) {
217
+ bubbleHandlerMap[eventName](e, 'bubble', eventConfig)
218
+ }
219
+
220
+ if (captureHandlerMap[eventName]) {
221
+ captureHandlerMap[eventName](e, 'capture', eventConfig)
269
222
  }
270
223
  }
271
224
  }
272
225
 
273
- const touchEventList = [
274
- { eventName: 'onTouchStart', handler: createTouchEventHandler('onTouchStart', 'bubble') },
275
- { eventName: 'onTouchMove', handler: createTouchEventHandler('onTouchMove', 'bubble') },
276
- { eventName: 'onTouchEnd', handler: createTouchEventHandler('onTouchEnd', 'bubble') },
277
- { eventName: 'onTouchCancel', handler: createTouchEventHandler('onTouchCancel', 'bubble') },
278
- { eventName: 'onTouchStartCapture', handler: createTouchEventHandler('onTouchStart', 'capture') },
279
- { eventName: 'onTouchMoveCapture', handler: createTouchEventHandler('onTouchMove', 'capture') },
280
- { eventName: 'onTouchEndCapture', handler: createTouchEventHandler('onTouchEnd', 'capture') },
281
- { eventName: 'onTouchCancelCapture', handler: createTouchEventHandler('onTouchCancel', 'capture') }
282
- ]
283
-
284
226
  const useInnerProps = (
285
227
  props: Props = {},
286
- additionalProps: AdditionalProps = {},
287
228
  userRemoveProps: RemoveProps = [],
288
- rawConfig?: UseInnerPropsConfig
229
+ rawConfig?: RawConfig
289
230
  ) => {
290
- const ref = useRef<InnerRef>({
231
+ const innerRef: InnerRef = useRef({
291
232
  startTimer: {
292
233
  bubble: null,
293
234
  capture: null
@@ -299,67 +240,80 @@ const useInnerProps = (
299
240
  }
300
241
  }
301
242
  })
302
-
303
- const propsRef = useRef<Record<string, any>>({})
304
- const eventConfig: { [key: string]: string[] } = {}
305
- const config = rawConfig || {
306
- layoutRef: { current: {} },
307
- disableTap: false
308
- }
243
+ const propsRef = useRef({})
244
+ propsRef.current = props
309
245
  const navigation = useNavigation()
310
-
311
- const removeProps = [
312
- 'children',
313
- 'enable-background',
314
- 'enable-offset',
315
- 'enable-var',
316
- 'external-var-context',
317
- 'parent-font-size',
318
- 'parent-width',
319
- 'parent-height',
320
- ...userRemoveProps
321
- ]
322
-
323
- propsRef.current = extendObject({}, props, additionalProps)
246
+ const eventConfig: EventConfig = extendObject({
247
+ layoutRef: {
248
+ current: null
249
+ },
250
+ propsRef,
251
+ innerRef,
252
+ disableTap: false,
253
+ navigation
254
+ }, rawConfig)
324
255
 
325
256
  let hashEventKey = ''
326
257
  const rawEventKeys: Array<string> = []
327
-
328
- for (const key in eventConfigMap) {
329
- if (hasOwn(propsRef.current, key)) {
330
- eventConfig[key] = eventConfigMap[key].events
331
- hashEventKey = hashEventKey + eventConfigMap[key].bitFlag
258
+ const transformedEventSet = new Set<string>()
259
+ Object.keys(props).forEach((key) => {
260
+ if (eventConfigMap[key]) {
261
+ hashEventKey += eventConfigMap[key].bitFlag
332
262
  rawEventKeys.push(key)
263
+ eventConfigMap[key].events.forEach((event) => {
264
+ transformedEventSet.add(event)
265
+ })
266
+ const match = /^(bind|catch|capture-bind|capture-catch)(.*)$/.exec(key)!
267
+ const prefix = match[1]
268
+ const eventName = match[2]
269
+ eventConfig[eventName] = eventConfig[eventName] || {
270
+ bubble: [],
271
+ capture: [],
272
+ hasCatch: false
273
+ }
274
+ if (prefix === 'bind' || prefix === 'catch') {
275
+ eventConfig[eventName].bubble.push(key)
276
+ } else {
277
+ eventConfig[eventName].capture.push(key)
278
+ }
279
+
280
+ if (prefix === 'catch' || prefix === 'capture-catch') {
281
+ eventConfig[eventName].hasCatch = true
282
+ }
333
283
  }
334
- }
284
+ })
335
285
 
336
286
  const events = useMemo(() => {
337
- if (!rawEventKeys.length) {
287
+ if (!hashEventKey) {
338
288
  return {}
339
289
  }
340
- const transformedEventKeys = rawEventKeys.reduce((acc: string[], key) => {
341
- if (propsRef.current[key]) {
342
- return acc.concat(eventConfig[key])
343
- }
344
- return acc
345
- }, [])
346
- const finalEventKeys = [...new Set(transformedEventKeys)]
290
+
347
291
  const events: Record<string, (e: ExtendedNativeTouchEvent) => void> = {}
348
292
 
349
- touchEventList.forEach((item) => {
350
- if (finalEventKeys.includes(item.eventName)) {
351
- events[item.eventName] = (e: ExtendedNativeTouchEvent) =>
352
- item.handler(e, ref, propsRef, config, navigation)
353
- }
354
- })
293
+ for (const eventName of transformedEventSet) {
294
+ events[eventName] = createTouchEventHandler(eventName, eventConfig)
295
+ }
355
296
 
356
297
  return events
357
298
  }, [hashEventKey])
358
299
 
300
+ const removeProps = [
301
+ 'children',
302
+ 'enable-background',
303
+ 'enable-offset',
304
+ 'enable-var',
305
+ 'external-var-context',
306
+ 'parent-font-size',
307
+ 'parent-width',
308
+ 'parent-height',
309
+ ...userRemoveProps,
310
+ ...rawEventKeys
311
+ ]
312
+
359
313
  return extendObject(
360
314
  {},
361
315
  events,
362
- omit(propsRef.current, [...rawEventKeys, ...removeProps])
316
+ omit(props, removeProps)
363
317
  )
364
318
  }
365
319
  export default useInnerProps
@@ -42,7 +42,8 @@ import {
42
42
  TextStyle,
43
43
  Animated,
44
44
  Easing,
45
- NativeSyntheticEvent
45
+ NativeSyntheticEvent,
46
+ useAnimatedValue
46
47
  } from 'react-native'
47
48
  import { warn } from '@mpxjs/utils'
48
49
  import { GestureDetector, PanGesture } from 'react-native-gesture-handler'
@@ -51,6 +52,7 @@ import useInnerProps, { getCustomEvent } from './getInnerListeners'
51
52
  import useNodesRef, { HandlerRef } from './useNodesRef'
52
53
  import { RouteContext, FormContext } from './context'
53
54
  import type { ExtendedViewStyle } from './types/common'
55
+ import Portal from './mpx-portal'
54
56
 
55
57
  export type Type = 'default' | 'primary' | 'warn'
56
58
 
@@ -156,7 +158,7 @@ const timer = (data: any, time = 3000) => new Promise((resolve) => {
156
158
  })
157
159
 
158
160
  const Loading = ({ alone = false }: { alone: boolean }): JSX.Element => {
159
- const image = useRef(new Animated.Value(0)).current
161
+ const image = useAnimatedValue(0)
160
162
 
161
163
  const rotate = image.interpolate({
162
164
  inputRange: [0, 1],
@@ -290,6 +292,7 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
290
292
  )
291
293
 
292
294
  const {
295
+ hasPositionFixed,
293
296
  hasSelfPercent,
294
297
  normalStyle,
295
298
  hasVarDec,
@@ -371,14 +374,13 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
371
374
  }
372
375
 
373
376
  const innerProps = useInnerProps(
374
- props,
375
377
  extendObject(
376
- {
377
- ref: nodeRef,
378
- style: extendObject({}, innerStyle, layoutStyle)
379
- },
378
+ {},
379
+ props,
380
380
  layoutProps,
381
381
  {
382
+ ref: nodeRef,
383
+ style: extendObject({}, innerStyle, layoutStyle),
382
384
  bindtap: !disabled && onTap
383
385
  }
384
386
  ),
@@ -413,9 +415,15 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
413
415
  )
414
416
  )
415
417
 
416
- return enableHover
418
+ const finalComponent = enableHover
417
419
  ? createElement(GestureDetector, { gesture: gesture as PanGesture }, baseButton)
418
420
  : baseButton
421
+
422
+ if (hasPositionFixed) {
423
+ return createElement(Portal, null, finalComponent)
424
+ }
425
+
426
+ return finalComponent
419
427
  })
420
428
 
421
429
  Button.displayName = 'MpxButton'
@@ -1,4 +1,5 @@
1
1
  import { WebviewMessage, WEBVIEW_TARGET, registerWebviewProperties, CanvasInstance } from './utils'
2
+ import { extendObject } from '../utils'
2
3
 
3
4
  const PROPERTIES = {
4
5
  crossOrigin: undefined,
@@ -60,10 +61,9 @@ export class Image {
60
61
  this[key] = value
61
62
  }
62
63
  }
63
- callbackFn({
64
- ...message.payload,
65
- target: this
66
- })
64
+ callbackFn(
65
+ extendObject({}, message.payload, { target: this })
66
+ )
67
67
  }
68
68
  })
69
69
  }