@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.
- package/lib/index.js +10 -1
- package/lib/json-compiler/helper.js +1 -4
- package/lib/platform/json/wx/index.js +0 -1
- package/lib/platform/style/wx/index.js +22 -21
- package/lib/platform/template/wx/component-config/button.js +1 -1
- package/lib/platform/template/wx/component-config/index.js +5 -1
- package/lib/platform/template/wx/component-config/input.js +1 -1
- package/lib/platform/template/wx/component-config/sticky-header.js +23 -0
- package/lib/platform/template/wx/component-config/sticky-section.js +23 -0
- package/lib/platform/template/wx/index.js +21 -1
- package/lib/react/processJSON.js +7 -6
- package/lib/react/processScript.js +9 -1
- package/lib/react/script-helper.js +5 -1
- package/lib/resolver/PackageEntryPlugin.js +3 -1
- package/lib/runtime/components/react/context.ts +12 -3
- package/lib/runtime/components/react/dist/context.js +4 -1
- package/lib/runtime/components/react/dist/event.config.js +0 -2
- package/lib/runtime/components/react/dist/getInnerListeners.js +127 -153
- package/lib/runtime/components/react/dist/mpx-button.jsx +11 -7
- package/lib/runtime/components/react/dist/mpx-canvas/Image.js +2 -4
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +23 -21
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +9 -4
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +9 -5
- package/lib/runtime/components/react/dist/mpx-form.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-icon/index.jsx +9 -4
- package/lib/runtime/components/react/dist/mpx-image.jsx +11 -4
- package/lib/runtime/components/react/dist/mpx-input.jsx +24 -13
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +23 -30
- package/lib/runtime/components/react/dist/mpx-label.jsx +9 -5
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +9 -4
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +77 -43
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +11 -3
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +12 -14
- package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +10 -10
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +28 -10
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -4
- package/lib/runtime/components/react/dist/mpx-radio.jsx +9 -5
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +9 -4
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +31 -11
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +3 -2
- package/lib/runtime/components/react/dist/mpx-simple-view.jsx +3 -3
- package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +115 -0
- package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +45 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +15 -14
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +86 -40
- package/lib/runtime/components/react/dist/mpx-switch.jsx +10 -7
- package/lib/runtime/components/react/dist/mpx-text.jsx +11 -9
- package/lib/runtime/components/react/dist/mpx-video.jsx +9 -4
- package/lib/runtime/components/react/dist/mpx-view.jsx +15 -10
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +13 -13
- package/lib/runtime/components/react/dist/useAnimationHooks.js +27 -4
- package/lib/runtime/components/react/dist/utils.jsx +99 -98
- package/lib/runtime/components/react/event.config.ts +1 -8
- package/lib/runtime/components/react/getInnerListeners.ts +146 -192
- package/lib/runtime/components/react/mpx-button.tsx +16 -8
- package/lib/runtime/components/react/mpx-canvas/Image.ts +4 -4
- package/lib/runtime/components/react/mpx-canvas/index.tsx +47 -32
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +13 -4
- package/lib/runtime/components/react/mpx-checkbox.tsx +17 -10
- package/lib/runtime/components/react/mpx-form.tsx +25 -19
- package/lib/runtime/components/react/mpx-icon/index.tsx +13 -4
- package/lib/runtime/components/react/mpx-image.tsx +42 -22
- package/lib/runtime/components/react/mpx-input.tsx +32 -16
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +31 -42
- package/lib/runtime/components/react/mpx-label.tsx +13 -6
- package/lib/runtime/components/react/mpx-movable-area.tsx +29 -14
- package/lib/runtime/components/react/mpx-movable-view.tsx +121 -81
- package/lib/runtime/components/react/mpx-navigator.tsx +4 -6
- package/lib/runtime/components/react/mpx-picker/index.tsx +24 -19
- package/lib/runtime/components/react/mpx-picker-view/index.tsx +39 -22
- package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +36 -32
- package/lib/runtime/components/react/mpx-radio-group.tsx +24 -12
- package/lib/runtime/components/react/mpx-radio.tsx +17 -10
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +25 -8
- package/lib/runtime/components/react/mpx-scroll-view.tsx +95 -60
- package/lib/runtime/components/react/mpx-simple-text.tsx +10 -3
- package/lib/runtime/components/react/mpx-simple-view.tsx +10 -4
- package/lib/runtime/components/react/mpx-sticky-header.tsx +179 -0
- package/lib/runtime/components/react/mpx-sticky-section.tsx +96 -0
- package/lib/runtime/components/react/mpx-swiper-item.tsx +42 -43
- package/lib/runtime/components/react/mpx-swiper.tsx +142 -79
- package/lib/runtime/components/react/mpx-switch.tsx +29 -16
- package/lib/runtime/components/react/mpx-text.tsx +26 -15
- package/lib/runtime/components/react/mpx-video.tsx +41 -35
- package/lib/runtime/components/react/mpx-view.tsx +38 -18
- package/lib/runtime/components/react/mpx-web-view.tsx +12 -12
- package/lib/runtime/components/react/types/getInnerListeners.d.ts +65 -35
- package/lib/runtime/components/react/useAnimationHooks.ts +30 -9
- package/lib/runtime/components/react/utils.tsx +107 -103
- package/lib/runtime/components/web/mpx-scroll-view.vue +21 -4
- package/lib/runtime/components/web/mpx-sticky-header.vue +91 -0
- package/lib/runtime/components/web/mpx-sticky-section.vue +15 -0
- package/lib/runtime/components/web/mpx-web-view.vue +1 -1
- package/lib/runtime/mpxGlobal.js +1 -0
- package/lib/runtime/optionProcessor.d.ts +5 -0
- package/lib/template-compiler/bind-this.js +8 -7
- package/lib/template-compiler/compiler.js +1 -1
- package/lib/wxs/pre-loader.js +1 -0
- package/package.json +3 -3
- package/LICENSE +0 -433
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { useRef, useMemo
|
|
2
|
-
import {
|
|
1
|
+
import { useRef, useMemo } from 'react'
|
|
2
|
+
import { collectDataset } from '@mpxjs/utils'
|
|
3
3
|
import { omit, extendObject, useNavigation } from './utils'
|
|
4
|
-
import eventConfigMap
|
|
4
|
+
import eventConfigMap from './event.config'
|
|
5
5
|
import {
|
|
6
6
|
Props,
|
|
7
|
-
|
|
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
|
-
|
|
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
|
|
38
|
-
offsetTop: layoutRef
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
config: UseInnerPropsConfig,
|
|
116
|
-
navigation: Navigation
|
|
109
|
+
name: string,
|
|
110
|
+
e: ExtendedNativeTouchEvent,
|
|
111
|
+
type: EventType,
|
|
112
|
+
eventConfig: EventConfig
|
|
117
113
|
) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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:
|
|
146
|
-
const tapDetailInfo = ref.current
|
|
147
|
-
const
|
|
148
|
-
const
|
|
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
|
-
|
|
132
|
+
Math.abs(currentPageY - tapDetailInfo.y) > 3
|
|
153
133
|
) {
|
|
154
134
|
globalEventState.needPress = false
|
|
155
|
-
ref.current
|
|
156
|
-
|
|
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:
|
|
140
|
+
function handleTouchstart (e: ExtendedNativeTouchEvent, type: EventType, eventConfig: EventConfig) {
|
|
141
|
+
// 阻止事件被释放放回对象池,导致对象复用 _stoppedEventTypes 状态被保留
|
|
162
142
|
e.persist()
|
|
163
|
-
const
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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(
|
|
164
|
+
handleEmitEvent('longpress', e, type, eventConfig)
|
|
190
165
|
}, 350)
|
|
191
166
|
}
|
|
192
167
|
}
|
|
193
168
|
|
|
194
|
-
function handleTouchmove (e: ExtendedNativeTouchEvent, type:
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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:
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
|
|
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
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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:
|
|
258
|
-
return (e: ExtendedNativeTouchEvent
|
|
259
|
-
const
|
|
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
|
|
267
|
-
|
|
268
|
-
|
|
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?:
|
|
229
|
+
rawConfig?: RawConfig
|
|
289
230
|
) => {
|
|
290
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
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
|
-
|
|
329
|
-
if (
|
|
330
|
-
|
|
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 (!
|
|
287
|
+
if (!hashEventKey) {
|
|
338
288
|
return {}
|
|
339
289
|
}
|
|
340
|
-
|
|
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
|
-
|
|
350
|
-
|
|
351
|
-
|
|
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(
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
})
|
|
64
|
+
callbackFn(
|
|
65
|
+
extendObject({}, message.payload, { target: this })
|
|
66
|
+
)
|
|
67
67
|
}
|
|
68
68
|
})
|
|
69
69
|
}
|