@mpxjs/webpack-plugin 2.10.3 → 2.10.4-beta.11

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 (155) 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 -4
  4. package/lib/platform/style/wx/index.js +42 -30
  5. package/lib/platform/template/wx/component-config/button.js +20 -3
  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/index.js +5 -1
  16. package/lib/platform/template/wx/component-config/input.js +19 -4
  17. package/lib/platform/template/wx/component-config/label.js +4 -0
  18. package/lib/platform/template/wx/component-config/movable-area.js +7 -1
  19. package/lib/platform/template/wx/component-config/movable-view.js +12 -3
  20. package/lib/platform/template/wx/component-config/navigator.js +4 -0
  21. package/lib/platform/template/wx/component-config/picker-view-column.js +4 -0
  22. package/lib/platform/template/wx/component-config/picker-view.js +7 -1
  23. package/lib/platform/template/wx/component-config/picker.js +7 -1
  24. package/lib/platform/template/wx/component-config/radio-group.js +4 -0
  25. package/lib/platform/template/wx/component-config/radio.js +4 -0
  26. package/lib/platform/template/wx/component-config/rich-text.js +4 -0
  27. package/lib/platform/template/wx/component-config/root-portal.js +4 -0
  28. package/lib/platform/template/wx/component-config/scroll-view.js +10 -2
  29. package/lib/platform/template/wx/component-config/sticky-header.js +23 -0
  30. package/lib/platform/template/wx/component-config/sticky-section.js +23 -0
  31. package/lib/platform/template/wx/component-config/swiper-item.js +7 -1
  32. package/lib/platform/template/wx/component-config/swiper.js +12 -3
  33. package/lib/platform/template/wx/component-config/switch.js +4 -0
  34. package/lib/platform/template/wx/component-config/text.js +24 -3
  35. package/lib/platform/template/wx/component-config/textarea.js +17 -2
  36. package/lib/platform/template/wx/component-config/unsupported.js +7 -0
  37. package/lib/platform/template/wx/component-config/video.js +10 -2
  38. package/lib/platform/template/wx/component-config/view.js +11 -1
  39. package/lib/platform/template/wx/component-config/web-view.js +4 -0
  40. package/lib/platform/template/wx/index.js +42 -75
  41. package/lib/react/processJSON.js +7 -6
  42. package/lib/react/processScript.js +1 -18
  43. package/lib/runtime/components/react/context.ts +12 -3
  44. package/lib/runtime/components/react/dist/context.js +4 -1
  45. package/lib/runtime/components/react/dist/event.config.js +0 -1
  46. package/lib/runtime/components/react/dist/getInnerListeners.js +127 -142
  47. package/lib/runtime/components/react/dist/mpx-button.jsx +4 -5
  48. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +4 -5
  49. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +2 -2
  50. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +2 -3
  51. package/lib/runtime/components/react/dist/mpx-form.jsx +2 -2
  52. package/lib/runtime/components/react/dist/mpx-icon/index.jsx +2 -2
  53. package/lib/runtime/components/react/dist/mpx-image.jsx +2 -2
  54. package/lib/runtime/components/react/dist/mpx-inline-text.jsx +11 -0
  55. package/lib/runtime/components/react/dist/mpx-input.jsx +20 -17
  56. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +24 -31
  57. package/lib/runtime/components/react/dist/mpx-label.jsx +2 -3
  58. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +2 -2
  59. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +1 -1
  60. package/lib/runtime/components/react/dist/mpx-navigator.jsx +11 -3
  61. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +194 -68
  62. package/lib/runtime/components/react/dist/mpx-picker/dateData.js +17 -0
  63. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +180 -98
  64. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +79 -139
  65. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +190 -90
  66. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +60 -75
  67. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +100 -228
  68. package/lib/runtime/components/react/dist/{mpx-picker-view.jsx → mpx-picker-view/index.jsx} +5 -6
  69. package/lib/runtime/components/react/dist/{mpx-picker-view-column.jsx → mpx-picker-view-column/index.jsx} +66 -18
  70. package/lib/runtime/components/react/dist/{mpx-picker-view-column-item.jsx → mpx-picker-view-column/pickerViewColumnItem.jsx} +8 -5
  71. package/lib/runtime/components/react/dist/{pickerFaces.js → mpx-picker-view-column/pickerViewFaces.js} +6 -0
  72. package/lib/runtime/components/react/dist/mpx-popup/index.jsx +61 -0
  73. package/lib/runtime/components/react/dist/mpx-popup/popupBase.jsx +92 -0
  74. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +2 -2
  75. package/lib/runtime/components/react/dist/mpx-radio.jsx +2 -3
  76. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +2 -2
  77. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +207 -29
  78. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +7 -5
  79. package/lib/runtime/components/react/dist/mpx-simple-view.jsx +11 -15
  80. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +115 -0
  81. package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +45 -0
  82. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -5
  83. package/lib/runtime/components/react/dist/mpx-swiper.jsx +9 -9
  84. package/lib/runtime/components/react/dist/mpx-switch.jsx +3 -5
  85. package/lib/runtime/components/react/dist/mpx-text.jsx +4 -7
  86. package/lib/runtime/components/react/dist/mpx-video.jsx +5 -5
  87. package/lib/runtime/components/react/dist/mpx-view.jsx +23 -9
  88. package/lib/runtime/components/react/dist/mpx-web-view.jsx +16 -13
  89. package/lib/runtime/components/react/dist/useAnimationHooks.js +26 -4
  90. package/lib/runtime/components/react/dist/utils.jsx +14 -2
  91. package/lib/runtime/components/react/event.config.ts +1 -6
  92. package/lib/runtime/components/react/getInnerListeners.ts +148 -191
  93. package/lib/runtime/components/react/mpx-button.tsx +7 -7
  94. package/lib/runtime/components/react/mpx-canvas/index.tsx +25 -17
  95. package/lib/runtime/components/react/mpx-checkbox-group.tsx +4 -3
  96. package/lib/runtime/components/react/mpx-checkbox.tsx +8 -9
  97. package/lib/runtime/components/react/mpx-form.tsx +25 -19
  98. package/lib/runtime/components/react/mpx-icon/index.tsx +4 -3
  99. package/lib/runtime/components/react/mpx-image.tsx +4 -3
  100. package/lib/runtime/components/react/mpx-inline-text.tsx +18 -0
  101. package/lib/runtime/components/react/mpx-input.tsx +24 -21
  102. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +31 -42
  103. package/lib/runtime/components/react/mpx-label.tsx +4 -5
  104. package/lib/runtime/components/react/mpx-movable-area.tsx +22 -13
  105. package/lib/runtime/components/react/mpx-movable-view.tsx +47 -40
  106. package/lib/runtime/components/react/mpx-navigator.tsx +4 -6
  107. package/lib/runtime/components/react/mpx-picker/date.tsx +226 -69
  108. package/lib/runtime/components/react/mpx-picker/dateData.ts +22 -0
  109. package/lib/runtime/components/react/mpx-picker/index.tsx +242 -118
  110. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +96 -139
  111. package/lib/runtime/components/react/mpx-picker/region.tsx +217 -89
  112. package/lib/runtime/components/react/mpx-picker/selector.tsx +75 -80
  113. package/lib/runtime/components/react/mpx-picker/time.tsx +119 -236
  114. package/lib/runtime/components/react/mpx-picker/type.ts +85 -71
  115. package/lib/runtime/components/react/{mpx-picker-view.tsx → mpx-picker-view/index.tsx} +24 -21
  116. package/lib/runtime/components/react/{mpx-picker-view-column.tsx → mpx-picker-view-column/index.tsx} +72 -21
  117. package/lib/runtime/components/react/{mpx-picker-view-column-item.tsx → mpx-picker-view-column/pickerViewColumnItem.tsx} +8 -5
  118. package/lib/runtime/components/react/{pickerFaces.ts → mpx-picker-view-column/pickerViewFaces.ts} +7 -0
  119. package/lib/runtime/components/react/mpx-popup/index.tsx +86 -0
  120. package/lib/runtime/components/react/mpx-popup/popupBase.tsx +130 -0
  121. package/lib/runtime/components/react/mpx-radio-group.tsx +4 -3
  122. package/lib/runtime/components/react/mpx-radio.tsx +8 -9
  123. package/lib/runtime/components/react/mpx-rich-text/index.tsx +15 -6
  124. package/lib/runtime/components/react/mpx-scroll-view.tsx +326 -96
  125. package/lib/runtime/components/react/mpx-simple-text.tsx +17 -8
  126. package/lib/runtime/components/react/mpx-simple-view.tsx +17 -16
  127. package/lib/runtime/components/react/mpx-sticky-header.tsx +179 -0
  128. package/lib/runtime/components/react/mpx-sticky-section.tsx +96 -0
  129. package/lib/runtime/components/react/mpx-swiper-item.tsx +31 -24
  130. package/lib/runtime/components/react/mpx-swiper.tsx +67 -61
  131. package/lib/runtime/components/react/mpx-switch.tsx +19 -14
  132. package/lib/runtime/components/react/mpx-text.tsx +16 -13
  133. package/lib/runtime/components/react/mpx-video.tsx +36 -35
  134. package/lib/runtime/components/react/mpx-view.tsx +41 -17
  135. package/lib/runtime/components/react/mpx-web-view.tsx +15 -12
  136. package/lib/runtime/components/react/types/getInnerListeners.d.ts +69 -35
  137. package/lib/runtime/components/react/types/global.d.ts +1 -1
  138. package/lib/runtime/components/react/useAnimationHooks.ts +29 -9
  139. package/lib/runtime/components/react/utils.tsx +15 -3
  140. package/lib/runtime/components/web/mini-video-controls.min.js +1 -1
  141. package/lib/runtime/components/web/mpx-input.vue +1 -1
  142. package/lib/runtime/components/web/mpx-scroll-view.vue +21 -4
  143. package/lib/runtime/components/web/mpx-sticky-header.vue +91 -0
  144. package/lib/runtime/components/web/mpx-sticky-section.vue +15 -0
  145. package/lib/runtime/stringify.wxs +2 -2
  146. package/lib/template-compiler/compiler.js +8 -8
  147. package/lib/utils/env.js +1 -1
  148. package/package.json +4 -5
  149. package/LICENSE +0 -433
  150. /package/lib/runtime/components/react/dist/{pickerVIewContext.js → mpx-picker-view/pickerVIewContext.js} +0 -0
  151. /package/lib/runtime/components/react/dist/{pickerViewIndicator.jsx → mpx-picker-view-column/pickerViewIndicator.jsx} +0 -0
  152. /package/lib/runtime/components/react/dist/{pickerViewMask.jsx → mpx-picker-view-column/pickerViewMask.jsx} +0 -0
  153. /package/lib/runtime/components/react/{pickerVIewContext.ts → mpx-picker-view/pickerVIewContext.ts} +0 -0
  154. /package/lib/runtime/components/react/{pickerViewIndicator.tsx → mpx-picker-view-column/pickerViewIndicator.tsx} +0 -0
  155. /package/lib/runtime/components/react/{pickerViewMask.tsx → mpx-picker-view-column/pickerViewMask.tsx} +0 -0
@@ -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 } 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
- NativeTouchEvent,
14
- Navigation
13
+ ExtendedNativeTouchEvent
15
14
  } from './types/getInnerListeners'
16
15
 
17
16
  const globalEventState = {
@@ -20,22 +19,21 @@ const globalEventState = {
20
19
 
21
20
  const getTouchEvent = (
22
21
  type: string,
23
- event: NativeTouchEvent,
24
- props: Props,
25
- config: UseInnerPropsConfig,
26
- navigation: Navigation
22
+ event: ExtendedNativeTouchEvent,
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,183 +106,129 @@ export const getCustomEvent = (
108
106
  }
109
107
 
110
108
  function handleEmitEvent (
111
- events: string[],
112
- type: string,
113
- oe: NativeTouchEvent,
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
- if (match) {
122
- oe.stopPropagation()
123
- }
124
- propsRef.current[event](
125
- getTouchEvent(type, oe, propsRef.current, config, navigation)
126
- )
114
+ const { propsRef } = eventConfig
115
+ const eventCfg = eventConfig[name]
116
+ if (eventCfg) {
117
+ if (eventCfg.hasCatch && name !== 'tap' && name !== 'longpress') {
118
+ e.stopPropagation()
127
119
  }
128
- })
120
+ eventCfg[type].forEach((event) => {
121
+ propsRef.current[event]?.(getTouchEvent(name, e, eventConfig))
122
+ })
123
+ }
129
124
  }
130
125
 
131
- function checkIsNeedPress (e: NativeTouchEvent, type: 'bubble' | 'capture', ref: RefObject<InnerRef>) {
132
- const tapDetailInfo = ref.current!.mpxPressInfo.detail || { x: 0, y: 0 }
133
- const nativeEvent = e.nativeEvent
134
- const currentPageX = nativeEvent.changedTouches[0].pageX
135
- 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
136
130
  if (
137
131
  Math.abs(currentPageX - tapDetailInfo.x) > 3 ||
138
- Math.abs(currentPageY - tapDetailInfo.y) > 3
132
+ Math.abs(currentPageY - tapDetailInfo.y) > 3
139
133
  ) {
140
134
  globalEventState.needPress = false
141
- ref.current!.startTimer[type] &&
142
- clearTimeout(ref.current!.startTimer[type] as SetTimeoutReturnType)
143
- 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
144
137
  }
145
138
  }
146
139
 
147
- function handleTouchstart (e: NativeTouchEvent, 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 状态被保留
148
142
  e.persist()
149
- const bubbleTouchEvent = ['catchtouchstart', 'bindtouchstart']
150
- const bubblePressEvent = ['catchlongpress', 'bindlongpress']
151
- const captureTouchEvent = [
152
- 'capture-catchtouchstart',
153
- 'capture-bindtouchstart'
154
- ]
155
- const capturePressEvent = [
156
- 'capture-catchlongpress',
157
- 'capture-bindlongpress'
158
- ]
159
- ref.current!.startTimer[type] = null
143
+ const { innerRef } = eventConfig
160
144
  globalEventState.needPress = true
161
- const nativeEvent = e.nativeEvent
162
- ref.current!.mpxPressInfo.detail = {
163
- x: nativeEvent.changedTouches[0].pageX,
164
- y: nativeEvent.changedTouches[0].pageY
145
+ innerRef.current.mpxPressInfo.detail = {
146
+ x: e.nativeEvent.changedTouches[0].pageX,
147
+ y: e.nativeEvent.changedTouches[0].pageY
165
148
  }
166
- const currentTouchEvent =
167
- type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
168
- const currentPressEvent =
169
- type === 'bubble' ? bubblePressEvent : capturePressEvent
170
- handleEmitEvent(currentTouchEvent, 'touchstart', e, propsRef, config, navigation)
171
- const {
172
- catchlongpress,
173
- bindlongpress,
174
- 'capture-catchlongpress': captureCatchlongpress,
175
- 'capture-bindlongpress': captureBindlongpress
176
- } = propsRef.current
177
- if (
178
- catchlongpress ||
179
- bindlongpress ||
180
- captureCatchlongpress ||
181
- captureBindlongpress
182
- ) {
183
- 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(() => {
184
162
  // 只要触发过longpress, 全局就不再触发tap
185
163
  globalEventState.needPress = false
186
- handleEmitEvent(currentPressEvent, 'longpress', e, propsRef, config, navigation)
164
+ handleEmitEvent('longpress', e, type, eventConfig)
187
165
  }, 350)
188
166
  }
189
167
  }
190
168
 
191
- function handleTouchmove (e: NativeTouchEvent, type: 'bubble' | 'capture', ref: RefObject<InnerRef>, propsRef: Record<string, any>, config: UseInnerPropsConfig, navigation: Navigation) {
192
- const bubbleTouchEvent = ['catchtouchmove', 'bindtouchmove']
193
- const captureTouchEvent = [
194
- 'capture-catchtouchmove',
195
- 'capture-bindtouchmove'
196
- ]
197
- const currentTouchEvent =
198
- type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
199
- handleEmitEvent(currentTouchEvent, 'touchmove', e, propsRef, config, navigation)
200
- if (TAP_EVENTS.some(eventName => propsRef.current[eventName])) {
201
- 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)
202
174
  }
203
175
  }
204
176
 
205
- function handleTouchend (e: NativeTouchEvent, type: 'bubble' | 'capture', ref: RefObject<InnerRef>, propsRef: Record<string, any>, config: UseInnerPropsConfig, navigation: Navigation) {
206
- // move event may not be triggered
207
- if (TAP_EVENTS.some(eventName => propsRef.current[eventName])) {
208
- checkIsNeedPress(e, type, ref)
209
- }
210
- const bubbleTouchEvent = ['catchtouchend', 'bindtouchend']
211
- const bubbleTapEvent = ['catchtap', 'bindtap']
212
- const captureTouchEvent = [
213
- 'capture-catchtouchend',
214
- 'capture-bindtouchend'
215
- ]
216
- const captureTapEvent = ['capture-catchtap', 'capture-bindtap']
217
- const currentTouchEvent =
218
- type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
219
- const currentTapEvent =
220
- type === 'bubble' ? bubbleTapEvent : captureTapEvent
221
- ref.current!.startTimer[type] &&
222
- clearTimeout(ref.current!.startTimer[type] as SetTimeoutReturnType)
223
- ref.current!.startTimer[type] = null
224
- handleEmitEvent(currentTouchEvent, 'touchend', e, propsRef, config, navigation)
225
- if (globalEventState.needPress) {
226
- 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')) {
227
184
  return
228
185
  }
229
- 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)
230
191
  }
231
192
  }
232
193
 
233
- function handleTouchcancel (
234
- e: NativeTouchEvent,
235
- type: 'bubble' | 'capture',
236
- ref: RefObject<InnerRef>,
237
- propsRef: Record<string, any>,
238
- config: UseInnerPropsConfig,
239
- navigation: Navigation
240
- ) {
241
- const bubbleTouchEvent = ['catchtouchcancel', 'bindtouchcancel']
242
- const captureTouchEvent = [
243
- 'capture-catchtouchcancel',
244
- 'capture-bindtouchcancel'
245
- ]
246
- const currentTouchEvent =
247
- type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
248
- ref.current!.startTimer[type] &&
249
- clearTimeout(ref.current!.startTimer[type] as SetTimeoutReturnType)
250
- ref.current!.startTimer[type] = null
251
- 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)
252
198
  }
253
199
 
254
- function createTouchEventHandler (eventName: 'onTouchStart'|'onTouchMove'|'onTouchEnd'|'onTouchCancel', type: 'bubble' | 'capture') {
255
- return (e: NativeTouchEvent, ref: RefObject<InnerRef>, propsRef: Record<string, any>, config: UseInnerPropsConfig, navigation: Navigation) => {
256
- const handlerMap = {
200
+ function createTouchEventHandler (eventName: string, eventConfig: EventConfig) {
201
+ return (e: ExtendedNativeTouchEvent) => {
202
+ const bubbleHandlerMap: Record<string, any> = {
257
203
  onTouchStart: handleTouchstart,
258
204
  onTouchMove: handleTouchmove,
259
205
  onTouchEnd: handleTouchend,
260
206
  onTouchCancel: handleTouchcancel
261
207
  }
262
208
 
263
- const handler = handlerMap[eventName]
264
- if (handler) {
265
- 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)
266
222
  }
267
223
  }
268
224
  }
269
225
 
270
- const touchEventList = [
271
- { eventName: 'onTouchStart', handler: createTouchEventHandler('onTouchStart', 'bubble') },
272
- { eventName: 'onTouchMove', handler: createTouchEventHandler('onTouchMove', 'bubble') },
273
- { eventName: 'onTouchEnd', handler: createTouchEventHandler('onTouchEnd', 'bubble') },
274
- { eventName: 'onTouchCancel', handler: createTouchEventHandler('onTouchCancel', 'bubble') },
275
- { eventName: 'onTouchStartCapture', handler: createTouchEventHandler('onTouchStart', 'capture') },
276
- { eventName: 'onTouchMoveCapture', handler: createTouchEventHandler('onTouchMove', 'capture') },
277
- { eventName: 'onTouchEndCapture', handler: createTouchEventHandler('onTouchEnd', 'capture') },
278
- { eventName: 'onTouchCancelCapture', handler: createTouchEventHandler('onTouchCancel', 'capture') }
279
- ]
280
-
281
226
  const useInnerProps = (
282
227
  props: Props = {},
283
- additionalProps: AdditionalProps = {},
284
228
  userRemoveProps: RemoveProps = [],
285
- rawConfig?: UseInnerPropsConfig
229
+ rawConfig?: RawConfig
286
230
  ) => {
287
- const ref = useRef<InnerRef>({
231
+ const innerRef: InnerRef = useRef({
288
232
  startTimer: {
289
233
  bubble: null,
290
234
  capture: null
@@ -296,67 +240,80 @@ const useInnerProps = (
296
240
  }
297
241
  }
298
242
  })
299
-
300
- const propsRef = useRef<Record<string, any>>({})
301
- const eventConfig: { [key: string]: string[] } = {}
302
- const config = rawConfig || {
303
- layoutRef: { current: {} },
304
- disableTap: false
305
- }
243
+ const propsRef = useRef({})
244
+ propsRef.current = props
306
245
  const navigation = useNavigation()
307
-
308
- const removeProps = [
309
- 'children',
310
- 'enable-background',
311
- 'enable-offset',
312
- 'enable-var',
313
- 'external-var-context',
314
- 'parent-font-size',
315
- 'parent-width',
316
- 'parent-height',
317
- ...userRemoveProps
318
- ]
319
-
320
- 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)
321
255
 
322
256
  let hashEventKey = ''
323
257
  const rawEventKeys: Array<string> = []
324
-
325
- for (const key in eventConfigMap) {
326
- if (hasOwn(propsRef.current, key)) {
327
- eventConfig[key] = eventConfigMap[key].events
328
- 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
329
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
+ }
330
283
  }
331
- }
284
+ })
332
285
 
333
286
  const events = useMemo(() => {
334
- if (!rawEventKeys.length) {
287
+ if (!hashEventKey) {
335
288
  return {}
336
289
  }
337
- const transformedEventKeys = rawEventKeys.reduce((acc: string[], key) => {
338
- if (propsRef.current[key]) {
339
- return acc.concat(eventConfig[key])
340
- }
341
- return acc
342
- }, [])
343
- const finalEventKeys = [...new Set(transformedEventKeys)]
344
- const events: Record<string, (e: NativeTouchEvent) => void> = {}
345
290
 
346
- touchEventList.forEach((item) => {
347
- if (finalEventKeys.includes(item.eventName)) {
348
- events[item.eventName] = (e: NativeTouchEvent) =>
349
- item.handler(e, ref, propsRef, config, navigation)
350
- }
351
- })
291
+ const events: Record<string, (e: ExtendedNativeTouchEvent) => void> = {}
292
+
293
+ for (const eventName of transformedEventSet) {
294
+ events[eventName] = createTouchEventHandler(eventName, eventConfig)
295
+ }
352
296
 
353
297
  return events
354
298
  }, [hashEventKey])
355
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
+
356
313
  return extendObject(
357
314
  {},
358
315
  events,
359
- omit(propsRef.current, [...rawEventKeys, ...removeProps])
316
+ omit(props, removeProps)
360
317
  )
361
318
  }
362
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'
@@ -156,7 +157,7 @@ const timer = (data: any, time = 3000) => new Promise((resolve) => {
156
157
  })
157
158
 
158
159
  const Loading = ({ alone = false }: { alone: boolean }): JSX.Element => {
159
- const image = useRef(new Animated.Value(0)).current
160
+ const image = useAnimatedValue(0)
160
161
 
161
162
  const rotate = image.interpolate({
162
163
  inputRange: [0, 1],
@@ -371,14 +372,13 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
371
372
  }
372
373
 
373
374
  const innerProps = useInnerProps(
374
- props,
375
375
  extendObject(
376
- {
377
- ref: nodeRef,
378
- style: extendObject({}, innerStyle, layoutStyle)
379
- },
376
+ {},
377
+ props,
380
378
  layoutProps,
381
379
  {
380
+ ref: nodeRef,
381
+ style: extendObject({}, innerStyle, layoutStyle),
382
382
  bindtap: !disabled && onTap
383
383
  }
384
384
  ),
@@ -48,19 +48,19 @@ const stylesheet = StyleSheet.create({
48
48
  })
49
49
 
50
50
  interface CanvasProps {
51
- style?: Record<string, any>;
52
- originWhitelist?: Array<string>;
51
+ style?: Record<string, any>
52
+ originWhitelist?: Array<string>
53
53
  'enable-var'?: boolean
54
54
  'parent-font-size'?: number
55
55
  'parent-width'?: number
56
56
  'parent-height'?: number
57
57
  'external-var-context'?: Record<string, any>
58
- bindtouchstart?: (event: NativeSyntheticEvent<TouchEvent>) => void;
59
- bindtouchmove?: (event: NativeSyntheticEvent<TouchEvent>) => void;
60
- bindtouchend?: (event: NativeSyntheticEvent<TouchEvent>) => void;
61
- bindtouchcancel?: (event: NativeSyntheticEvent<TouchEvent>) => void;
62
- bindlongtap?: (event: NativeSyntheticEvent<TouchEvent>) => void;
63
- binderror?: (event: NativeSyntheticEvent<ErrorEvent>) => void;
58
+ bindtouchstart?: (event: NativeSyntheticEvent<TouchEvent>) => void
59
+ bindtouchmove?: (event: NativeSyntheticEvent<TouchEvent>) => void
60
+ bindtouchend?: (event: NativeSyntheticEvent<TouchEvent>) => void
61
+ bindtouchcancel?: (event: NativeSyntheticEvent<TouchEvent>) => void
62
+ bindlongtap?: (event: NativeSyntheticEvent<TouchEvent>) => void
63
+ binderror?: (event: NativeSyntheticEvent<ErrorEvent>) => void
64
64
  }
65
65
 
66
66
  const _Canvas = forwardRef<HandlerRef<CanvasProps & View, CanvasProps>, CanvasProps>((props: CanvasProps = {}, ref): JSX.Element => {
@@ -91,13 +91,21 @@ const _Canvas = forwardRef<HandlerRef<CanvasProps & View, CanvasProps>, CanvasPr
91
91
  const { register } = useConstructorsRegistry()
92
92
 
93
93
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
94
- const innerProps = useInnerProps(props, {
95
- ref: nodeRef,
96
- style: extendObject({}, normalStyle, layoutStyle, { opacity: isLoaded ? 1 : 0 }),
97
- ...layoutProps
98
- }, [], {
99
- layoutRef
100
- })
94
+ const innerProps = useInnerProps(
95
+ extendObject(
96
+ {},
97
+ props,
98
+ layoutProps,
99
+ {
100
+ ref: nodeRef,
101
+ style: extendObject({}, normalStyle, layoutStyle, { opacity: isLoaded ? 1 : 0 })
102
+ }
103
+ ),
104
+ [],
105
+ {
106
+ layoutRef
107
+ }
108
+ )
101
109
 
102
110
  const context2D = new CanvasRenderingContext2D(canvasRef.current) as any
103
111
 
@@ -251,8 +259,8 @@ const _Canvas = forwardRef<HandlerRef<CanvasProps & View, CanvasProps>, CanvasPr
251
259
  context: context2D
252
260
  })
253
261
 
254
- if (Platform.OS === 'android') {
255
- const isAndroid9 = Platform.Version >= 28
262
+ if (__mpx_mode__ !== 'ios') {
263
+ const isAndroid9 = Platform.Version as number >= 28
256
264
  return createElement(View, innerProps, createElement(
257
265
  WebView,
258
266
  {
@@ -116,13 +116,14 @@ const CheckboxGroup = forwardRef<
116
116
  }, [])
117
117
 
118
118
  const innerProps = useInnerProps(
119
- props,
120
119
  extendObject(
120
+ {},
121
+ props,
122
+ layoutProps,
121
123
  {
122
124
  ref: nodeRef,
123
125
  style: extendObject({}, normalStyle, layoutStyle)
124
- },
125
- layoutProps
126
+ }
126
127
  ),
127
128
  [
128
129
  'name'
@@ -42,9 +42,9 @@ export interface CheckboxProps extends Selection {
42
42
  'enable-offset'?: boolean
43
43
  'enable-var'?: boolean
44
44
  'external-var-context'?: Record<string, any>
45
- 'parent-font-size'?: number;
46
- 'parent-width'?: number;
47
- 'parent-height'?: number;
45
+ 'parent-font-size'?: number
46
+ 'parent-width'?: number
47
+ 'parent-height'?: number
48
48
  children?: ReactNode
49
49
  bindtap?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
50
50
  _onChange?: (evt: NativeSyntheticEvent<TouchEvent> | unknown, { checked }: { checked: boolean }) => void
@@ -99,7 +99,7 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
99
99
  const [isChecked, setIsChecked] = useState<boolean>(!!checked)
100
100
 
101
101
  const groupContext = useContext(CheckboxGroupContext)
102
- let groupValue: { [key: string]: { checked: boolean; setValue: Dispatch<SetStateAction<boolean>>; } } | undefined
102
+ let groupValue: { [key: string]: { checked: boolean; setValue: Dispatch<SetStateAction<boolean>> } } | undefined
103
103
  let notifyChange: (evt: NativeSyntheticEvent<TouchEvent>) => void | undefined
104
104
 
105
105
  const defaultStyle = extendObject(
@@ -163,14 +163,13 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
163
163
  }
164
164
 
165
165
  const innerProps = useInnerProps(
166
- props,
167
166
  extendObject(
168
- {
169
- ref: nodeRef,
170
- style: extendObject({}, innerStyle, layoutStyle)
171
- },
167
+ {},
168
+ props,
172
169
  layoutProps,
173
170
  {
171
+ ref: nodeRef,
172
+ style: extendObject({}, innerStyle, layoutStyle),
174
173
  bindtap: !disabled && onTap
175
174
  }
176
175
  ),
@@ -11,20 +11,20 @@ import useInnerProps, { getCustomEvent } from './getInnerListeners'
11
11
  import { FormContext } from './context'
12
12
  import { useTransformStyle, splitProps, splitStyle, useLayout, wrapChildren, extendObject } from './utils'
13
13
  interface FormProps {
14
- style?: Record<string, any>;
15
- children?: ReactNode;
16
- 'enable-offset'?: boolean;
14
+ style?: Record<string, any>
15
+ children?: ReactNode
16
+ 'enable-offset'?: boolean
17
17
  'enable-var'?: boolean
18
- 'external-var-context'?: Record<string, any>;
19
- 'parent-font-size'?: number;
20
- 'parent-width'?: number;
21
- 'parent-height'?: number;
18
+ 'external-var-context'?: Record<string, any>
19
+ 'parent-font-size'?: number
20
+ 'parent-width'?: number
21
+ 'parent-height'?: number
22
22
  bindsubmit?: (evt: {
23
23
  detail: {
24
- value: any;
25
- };
26
- }) => void;
27
- bindreset?: () => void;
24
+ value: any
25
+ }
26
+ }) => void
27
+ bindreset?: () => void
28
28
  }
29
29
 
30
30
  const _Form = forwardRef<HandlerRef<View, FormProps>, FormProps>((fromProps: FormProps, ref): JSX.Element => {
@@ -59,14 +59,20 @@ const _Form = forwardRef<HandlerRef<View, FormProps>, FormProps>((fromProps: For
59
59
 
60
60
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: formRef })
61
61
 
62
- const innerProps = useInnerProps(props, extendObject({
63
- style: extendObject({}, innerStyle, layoutStyle),
64
- ref: formRef
65
- }, layoutProps)
66
- , [
67
- 'bindsubmit',
68
- 'bindreset'
69
- ], { layoutRef })
62
+ const innerProps = useInnerProps(
63
+ extendObject(
64
+ {},
65
+ props,
66
+ layoutProps,
67
+ {
68
+ style: extendObject({}, innerStyle, layoutStyle),
69
+ ref: formRef
70
+ }
71
+ )
72
+ , [
73
+ 'bindsubmit',
74
+ 'bindreset'
75
+ ], { layoutRef })
70
76
 
71
77
  const contextValue = useMemo(() => {
72
78
  const formValuesMap = new Map()