@mpxjs/webpack-plugin 2.10.7-beta.9 → 2.10.8
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/LICENSE +433 -0
- package/lib/dependencies/RequireExternalDependency.js +61 -0
- package/lib/file-loader.js +3 -2
- package/lib/index.js +60 -15
- package/lib/json-compiler/index.js +1 -0
- package/lib/parser.js +1 -1
- package/lib/platform/json/wx/index.js +43 -25
- package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
- package/lib/platform/template/wx/component-config/movable-view.js +10 -1
- package/lib/platform/template/wx/index.js +2 -1
- package/lib/react/LoadAsyncChunkModule.js +74 -0
- package/lib/react/index.js +3 -1
- package/lib/react/processJSON.js +74 -13
- package/lib/react/processScript.js +6 -6
- package/lib/react/script-helper.js +100 -41
- package/lib/runtime/components/react/context.ts +2 -12
- package/lib/runtime/components/react/dist/context.js +1 -1
- package/lib/runtime/components/react/dist/getInnerListeners.js +1 -1
- package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +135 -0
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +9 -63
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +58 -301
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +27 -53
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +14 -28
- package/lib/runtime/components/react/dist/useAnimationHooks.js +2 -87
- package/lib/runtime/components/react/getInnerListeners.ts +1 -1
- package/lib/runtime/components/react/mpx-async-suspense.tsx +180 -0
- package/lib/runtime/components/react/mpx-movable-area.tsx +11 -98
- package/lib/runtime/components/react/mpx-movable-view.tsx +60 -350
- package/lib/runtime/components/react/mpx-swiper.tsx +25 -53
- package/lib/runtime/components/react/mpx-web-view.tsx +13 -33
- package/lib/runtime/components/react/types/global.d.ts +15 -0
- package/lib/runtime/components/react/useAnimationHooks.ts +2 -85
- package/lib/runtime/optionProcessorReact.d.ts +18 -0
- package/lib/runtime/optionProcessorReact.js +30 -0
- package/lib/script-setup-compiler/index.js +27 -5
- package/lib/template-compiler/compiler.js +4 -3
- package/lib/utils/dom-tag-config.js +17 -3
- package/lib/utils/trans-async-sub-rules.js +19 -0
- package/lib/web/script-helper.js +1 -1
- package/package.json +4 -4
- package/lib/runtime/components/react/AsyncContainer.tsx +0 -189
- package/lib/runtime/components/react/dist/AsyncContainer.jsx +0 -141
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
* ✘ damping
|
|
8
8
|
* ✘ friction
|
|
9
9
|
* ✔ disabled
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* ✘ scale
|
|
11
|
+
* ✘ scale-min
|
|
12
|
+
* ✘ scale-max
|
|
13
|
+
* ✘ scale-value
|
|
14
14
|
* ✔ animation
|
|
15
15
|
* ✔ bindchange
|
|
16
|
-
*
|
|
16
|
+
* ✘ bindscale
|
|
17
17
|
* ✔ htouchmove
|
|
18
18
|
* ✔ vtouchmove
|
|
19
19
|
*/
|
|
@@ -30,8 +30,8 @@ import Animated, {
|
|
|
30
30
|
withDecay,
|
|
31
31
|
runOnJS,
|
|
32
32
|
runOnUI,
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
useAnimatedReaction,
|
|
34
|
+
withSpring
|
|
35
35
|
} from 'react-native-reanimated'
|
|
36
36
|
import { collectDataset, noop } from '@mpxjs/utils'
|
|
37
37
|
|
|
@@ -43,14 +43,9 @@ interface MovableViewProps {
|
|
|
43
43
|
y?: number
|
|
44
44
|
disabled?: boolean
|
|
45
45
|
animation?: boolean
|
|
46
|
-
scale?: boolean
|
|
47
|
-
'scale-min'?: number
|
|
48
|
-
'scale-max'?: number
|
|
49
|
-
'scale-value'?: number
|
|
50
46
|
id?: string
|
|
51
47
|
changeThrottleTime?:number
|
|
52
48
|
bindchange?: (event: unknown) => void
|
|
53
|
-
bindscale?: (event: unknown) => void
|
|
54
49
|
bindtouchstart?: (event: GestureTouchEvent) => void
|
|
55
50
|
catchtouchstart?: (event: GestureTouchEvent) => void
|
|
56
51
|
bindtouchmove?: (event: GestureTouchEvent) => void
|
|
@@ -102,10 +97,6 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
102
97
|
inertia = false,
|
|
103
98
|
disabled = false,
|
|
104
99
|
animation = true,
|
|
105
|
-
scale = false,
|
|
106
|
-
'scale-min': scaleMin = 0.1,
|
|
107
|
-
'scale-max': scaleMax = 10,
|
|
108
|
-
'scale-value': scaleValue = 1,
|
|
109
100
|
'out-of-bounds': outOfBounds = false,
|
|
110
101
|
'enable-var': enableVar,
|
|
111
102
|
'external-var-context': externalVarContext,
|
|
@@ -128,9 +119,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
128
119
|
catchtouchmove,
|
|
129
120
|
bindtouchend,
|
|
130
121
|
catchtouchend,
|
|
131
|
-
|
|
132
|
-
bindchange,
|
|
133
|
-
onLayout: propsOnLayout
|
|
122
|
+
bindchange
|
|
134
123
|
} = props
|
|
135
124
|
|
|
136
125
|
const {
|
|
@@ -140,7 +129,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
140
129
|
varContextRef,
|
|
141
130
|
setWidth,
|
|
142
131
|
setHeight
|
|
143
|
-
} = useTransformStyle(Object.assign({}, styles.container
|
|
132
|
+
} = useTransformStyle(Object.assign({}, style, styles.container), { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
144
133
|
|
|
145
134
|
const navigation = useNavigation()
|
|
146
135
|
|
|
@@ -151,8 +140,6 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
151
140
|
|
|
152
141
|
const offsetX = useSharedValue(x)
|
|
153
142
|
const offsetY = useSharedValue(y)
|
|
154
|
-
const currentScale = useSharedValue(1)
|
|
155
|
-
const layoutValue = useSharedValue<any>({})
|
|
156
143
|
|
|
157
144
|
const startPosition = useSharedValue({
|
|
158
145
|
x: 0,
|
|
@@ -215,41 +202,6 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
215
202
|
)
|
|
216
203
|
}, [])
|
|
217
204
|
|
|
218
|
-
const handleTriggerScale = useCallback(({ x, y, scale }: { x: number; y: number; scale: number }) => {
|
|
219
|
-
const { bindscale } = propsRef.current
|
|
220
|
-
if (!bindscale) return
|
|
221
|
-
bindscale(
|
|
222
|
-
getCustomEvent('scale', {}, {
|
|
223
|
-
detail: {
|
|
224
|
-
x,
|
|
225
|
-
y,
|
|
226
|
-
scale
|
|
227
|
-
},
|
|
228
|
-
layoutRef
|
|
229
|
-
}, propsRef.current)
|
|
230
|
-
)
|
|
231
|
-
}, [])
|
|
232
|
-
|
|
233
|
-
const checkBoundaryPosition = useCallback(({ positionX, positionY }: { positionX: number; positionY: number }) => {
|
|
234
|
-
'worklet'
|
|
235
|
-
let x = positionX
|
|
236
|
-
let y = positionY
|
|
237
|
-
// 计算边界限制
|
|
238
|
-
if (x > draggableXRange.value[1]) {
|
|
239
|
-
x = draggableXRange.value[1]
|
|
240
|
-
} else if (x < draggableXRange.value[0]) {
|
|
241
|
-
x = draggableXRange.value[0]
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if (y > draggableYRange.value[1]) {
|
|
245
|
-
y = draggableYRange.value[1]
|
|
246
|
-
} else if (y < draggableYRange.value[0]) {
|
|
247
|
-
y = draggableYRange.value[0]
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
return { x, y }
|
|
251
|
-
}, [])
|
|
252
|
-
|
|
253
205
|
// 节流版本的 change 事件触发
|
|
254
206
|
const handleTriggerChangeThrottled = useCallback(({ x, y, type }: { x: number; y: number; type?: string }) => {
|
|
255
207
|
'worklet'
|
|
@@ -291,223 +243,12 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
291
243
|
})()
|
|
292
244
|
}, [x, y])
|
|
293
245
|
|
|
294
|
-
// 提取通用的缩放边界计算函数
|
|
295
|
-
const calculateScaleBoundaryPosition = useCallback(({
|
|
296
|
-
currentOffsetX,
|
|
297
|
-
currentOffsetY,
|
|
298
|
-
newScale,
|
|
299
|
-
width,
|
|
300
|
-
height
|
|
301
|
-
}: {
|
|
302
|
-
currentOffsetX: number
|
|
303
|
-
currentOffsetY: number
|
|
304
|
-
newScale: number
|
|
305
|
-
width: number
|
|
306
|
-
height: number
|
|
307
|
-
}) => {
|
|
308
|
-
'worklet'
|
|
309
|
-
const prevScale = currentScale.value
|
|
310
|
-
|
|
311
|
-
// 计算元素当前中心点(在屏幕上的位置)
|
|
312
|
-
const currentCenterX = currentOffsetX + (width * prevScale) / 2
|
|
313
|
-
const currentCenterY = currentOffsetY + (height * prevScale) / 2
|
|
314
|
-
|
|
315
|
-
// 实现中心缩放:保持元素中心点不变
|
|
316
|
-
// 计算缩放后为了保持中心点不变需要的新offset位置
|
|
317
|
-
let newOffsetX = currentCenterX - (width * newScale) / 2
|
|
318
|
-
let newOffsetY = currentCenterY - (height * newScale) / 2
|
|
319
|
-
|
|
320
|
-
// 缩放过程中实时边界检测
|
|
321
|
-
// 计算新的边界范围
|
|
322
|
-
const top = (style.position === 'absolute' && style.top) || 0
|
|
323
|
-
const left = (style.position === 'absolute' && style.left) || 0
|
|
324
|
-
const scaledWidth = width * newScale
|
|
325
|
-
const scaledHeight = height * newScale
|
|
326
|
-
|
|
327
|
-
// 计算新缩放值下的边界限制
|
|
328
|
-
const maxOffsetY = MovableAreaLayout.height - scaledHeight - top
|
|
329
|
-
const maxOffsetX = MovableAreaLayout.width - scaledWidth - left
|
|
330
|
-
|
|
331
|
-
let xMin, xMax, yMin, yMax
|
|
332
|
-
|
|
333
|
-
if (MovableAreaLayout.width < scaledWidth) {
|
|
334
|
-
xMin = maxOffsetX
|
|
335
|
-
xMax = -left
|
|
336
|
-
} else {
|
|
337
|
-
xMin = -left
|
|
338
|
-
xMax = maxOffsetX < 0 ? -left : maxOffsetX
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
if (MovableAreaLayout.height < scaledHeight) {
|
|
342
|
-
yMin = maxOffsetY
|
|
343
|
-
yMax = -top
|
|
344
|
-
} else {
|
|
345
|
-
yMin = -top
|
|
346
|
-
yMax = maxOffsetY < 0 ? -top : maxOffsetY
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
// 应用边界限制
|
|
350
|
-
if (newOffsetX > xMax) {
|
|
351
|
-
newOffsetX = xMax
|
|
352
|
-
} else if (newOffsetX < xMin) {
|
|
353
|
-
newOffsetX = xMin
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
if (newOffsetY > yMax) {
|
|
357
|
-
newOffsetY = yMax
|
|
358
|
-
} else if (newOffsetY < yMin) {
|
|
359
|
-
newOffsetY = yMin
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
return { x: newOffsetX, y: newOffsetY }
|
|
363
|
-
}, [MovableAreaLayout.height, MovableAreaLayout.width, style.position, style.top, style.left])
|
|
364
|
-
|
|
365
|
-
// 提取通用的缩放处理函数
|
|
366
|
-
const handleScaleUpdate = useCallback((scaleInfo: { scale: number }) => {
|
|
367
|
-
'worklet'
|
|
368
|
-
if (disabled) return
|
|
369
|
-
|
|
370
|
-
// 判断缩放方向并计算新的缩放值
|
|
371
|
-
const isZoomingIn = scaleInfo.scale > 1
|
|
372
|
-
const isZoomingOut = scaleInfo.scale < 1
|
|
373
|
-
|
|
374
|
-
let newScale
|
|
375
|
-
if (isZoomingIn) {
|
|
376
|
-
// 放大:增加缩放值
|
|
377
|
-
newScale = currentScale.value + (scaleInfo.scale - 1) * 0.5
|
|
378
|
-
} else if (isZoomingOut) {
|
|
379
|
-
// 缩小:减少缩放值
|
|
380
|
-
newScale = currentScale.value - (1 - scaleInfo.scale) * 0.5
|
|
381
|
-
} else {
|
|
382
|
-
// 没有缩放变化
|
|
383
|
-
newScale = currentScale.value
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
// 限制缩放值在 scaleMin 和 scaleMax 之间
|
|
387
|
-
newScale = Math.max(scaleMin, Math.min(scaleMax, newScale))
|
|
388
|
-
|
|
389
|
-
// 只有当缩放值真正改变时才调整位置
|
|
390
|
-
if (Math.abs(newScale - currentScale.value) > 0.01) {
|
|
391
|
-
// 获取元素尺寸
|
|
392
|
-
const { width = 0, height = 0 } = layoutValue.value
|
|
393
|
-
|
|
394
|
-
if (width > 0 && height > 0) {
|
|
395
|
-
// 使用通用的边界计算函数
|
|
396
|
-
const { x: newOffsetX, y: newOffsetY } = calculateScaleBoundaryPosition({
|
|
397
|
-
currentOffsetX: offsetX.value,
|
|
398
|
-
currentOffsetY: offsetY.value,
|
|
399
|
-
newScale,
|
|
400
|
-
width,
|
|
401
|
-
height
|
|
402
|
-
})
|
|
403
|
-
|
|
404
|
-
offsetX.value = newOffsetX
|
|
405
|
-
offsetY.value = newOffsetY
|
|
406
|
-
|
|
407
|
-
// 更新缩放值
|
|
408
|
-
currentScale.value = newScale
|
|
409
|
-
}
|
|
410
|
-
} else {
|
|
411
|
-
currentScale.value = newScale
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
if (bindscale) {
|
|
415
|
-
runOnJS(handleTriggerScale)({
|
|
416
|
-
x: offsetX.value,
|
|
417
|
-
y: offsetY.value,
|
|
418
|
-
scale: newScale
|
|
419
|
-
})
|
|
420
|
-
}
|
|
421
|
-
}, [disabled, scaleMin, scaleMax, bindscale, handleTriggerScale, calculateScaleBoundaryPosition, style.position, style.top, style.left, MovableAreaLayout.height, MovableAreaLayout.width])
|
|
422
|
-
|
|
423
246
|
useEffect(() => {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
const clampedScale = Math.max(scaleMin, Math.min(scaleMax, scaleValue))
|
|
428
|
-
|
|
429
|
-
// 实现中心缩放的位置补偿
|
|
430
|
-
const { width = 0, height = 0 } = layoutValue.value
|
|
431
|
-
if (width > 0 && height > 0) {
|
|
432
|
-
// 使用通用的边界计算函数
|
|
433
|
-
const { x: newOffsetX, y: newOffsetY } = calculateScaleBoundaryPosition({
|
|
434
|
-
currentOffsetX: offsetX.value,
|
|
435
|
-
currentOffsetY: offsetY.value,
|
|
436
|
-
newScale: clampedScale,
|
|
437
|
-
width,
|
|
438
|
-
height
|
|
439
|
-
})
|
|
440
|
-
|
|
441
|
-
// 同时更新缩放值和位置
|
|
442
|
-
if (animation) {
|
|
443
|
-
currentScale.value = withTiming(clampedScale, {
|
|
444
|
-
duration: 1000
|
|
445
|
-
}, () => {
|
|
446
|
-
handleRestBoundaryAndCheck()
|
|
447
|
-
})
|
|
448
|
-
offsetX.value = withTiming(newOffsetX, { duration: 1000 })
|
|
449
|
-
offsetY.value = withTiming(newOffsetY, { duration: 1000 })
|
|
450
|
-
} else {
|
|
451
|
-
currentScale.value = clampedScale
|
|
452
|
-
offsetX.value = newOffsetX
|
|
453
|
-
offsetY.value = newOffsetY
|
|
454
|
-
handleRestBoundaryAndCheck()
|
|
455
|
-
}
|
|
456
|
-
} else {
|
|
457
|
-
// 如果还没有尺寸信息,只更新缩放值
|
|
458
|
-
if (animation) {
|
|
459
|
-
currentScale.value = withTiming(clampedScale, {
|
|
460
|
-
duration: 1000
|
|
461
|
-
}, () => {
|
|
462
|
-
handleRestBoundaryAndCheck()
|
|
463
|
-
})
|
|
464
|
-
} else {
|
|
465
|
-
currentScale.value = clampedScale
|
|
466
|
-
handleRestBoundaryAndCheck()
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
if (bindscale) {
|
|
471
|
-
runOnJS(handleTriggerScale)({
|
|
472
|
-
x: offsetX.value,
|
|
473
|
-
y: offsetY.value,
|
|
474
|
-
scale: clampedScale
|
|
475
|
-
})
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
})()
|
|
479
|
-
}, [scaleValue, scaleMin, scaleMax, animation])
|
|
480
|
-
|
|
481
|
-
useEffect(() => {
|
|
482
|
-
runOnUI(handleRestBoundaryAndCheck)()
|
|
483
|
-
}, [MovableAreaLayout.height, MovableAreaLayout.width])
|
|
484
|
-
|
|
485
|
-
// 生成唯一 ID
|
|
486
|
-
const viewId = useMemo(() => `movable-view-${Date.now()}-${Math.random()}`, [])
|
|
487
|
-
|
|
488
|
-
// 注册到 MovableArea(如果启用了 scale-area)
|
|
489
|
-
useEffect(() => {
|
|
490
|
-
if (MovableAreaLayout.scaleArea && MovableAreaLayout.registerMovableView && MovableAreaLayout.unregisterMovableView) {
|
|
491
|
-
const handleAreaScale = (scaleInfo: { scale: number }) => {
|
|
492
|
-
'worklet'
|
|
493
|
-
handleScaleUpdate({ scale: scaleInfo.scale })
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
const handleAreaScaleEnd = () => {
|
|
497
|
-
'worklet'
|
|
498
|
-
handleRestBoundaryAndCheck()
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
MovableAreaLayout.registerMovableView?.(viewId, {
|
|
502
|
-
onScale: scale ? handleAreaScale : noop,
|
|
503
|
-
onScaleEnd: scale ? handleAreaScaleEnd : noop
|
|
504
|
-
})
|
|
505
|
-
|
|
506
|
-
return () => {
|
|
507
|
-
MovableAreaLayout.unregisterMovableView?.(viewId)
|
|
508
|
-
}
|
|
247
|
+
const { width, height } = layoutRef.current
|
|
248
|
+
if (width && height) {
|
|
249
|
+
resetBoundaryAndCheck({ width, height })
|
|
509
250
|
}
|
|
510
|
-
}, [MovableAreaLayout.
|
|
251
|
+
}, [MovableAreaLayout.height, MovableAreaLayout.width])
|
|
511
252
|
|
|
512
253
|
const getTouchSource = useCallback((offsetX: number, offsetY: number) => {
|
|
513
254
|
const hasOverBoundary = offsetX < draggableXRange.value[0] || offsetX > draggableXRange.value[1] ||
|
|
@@ -531,50 +272,66 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
531
272
|
}, [])
|
|
532
273
|
|
|
533
274
|
const setBoundary = useCallback(({ width, height }: { width: number; height: number }) => {
|
|
534
|
-
'worklet'
|
|
535
275
|
const top = (style.position === 'absolute' && style.top) || 0
|
|
536
276
|
const left = (style.position === 'absolute' && style.left) || 0
|
|
537
277
|
|
|
538
|
-
|
|
539
|
-
const
|
|
540
|
-
const scaledWidth = (width || 0) * currentScaleVal
|
|
541
|
-
const scaledHeight = (height || 0) * currentScaleVal
|
|
278
|
+
const scaledWidth = width || 0
|
|
279
|
+
const scaledHeight = height || 0
|
|
542
280
|
|
|
543
|
-
|
|
544
|
-
const
|
|
545
|
-
const maxOffsetX = MovableAreaLayout.width - scaledWidth - left
|
|
281
|
+
const maxY = MovableAreaLayout.height - scaledHeight - top
|
|
282
|
+
const maxX = MovableAreaLayout.width - scaledWidth - left
|
|
546
283
|
|
|
547
284
|
let xRange: [min: number, max: number]
|
|
548
285
|
let yRange: [min: number, max: number]
|
|
549
286
|
|
|
550
287
|
if (MovableAreaLayout.width < scaledWidth) {
|
|
551
|
-
xRange = [
|
|
288
|
+
xRange = [maxX, 0]
|
|
552
289
|
} else {
|
|
553
|
-
xRange = [-left,
|
|
290
|
+
xRange = [left === 0 ? 0 : -left, maxX < 0 ? 0 : maxX]
|
|
554
291
|
}
|
|
555
292
|
|
|
556
293
|
if (MovableAreaLayout.height < scaledHeight) {
|
|
557
|
-
yRange = [
|
|
294
|
+
yRange = [maxY, 0]
|
|
558
295
|
} else {
|
|
559
|
-
yRange = [-top,
|
|
296
|
+
yRange = [top === 0 ? 0 : -top, maxY < 0 ? 0 : maxY]
|
|
560
297
|
}
|
|
561
|
-
|
|
562
298
|
draggableXRange.value = xRange
|
|
563
299
|
draggableYRange.value = yRange
|
|
564
300
|
}, [MovableAreaLayout.height, MovableAreaLayout.width, style.position, style.top, style.left])
|
|
565
301
|
|
|
566
|
-
const
|
|
302
|
+
const checkBoundaryPosition = useCallback(({ positionX, positionY }: { positionX: number; positionY: number }) => {
|
|
567
303
|
'worklet'
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
304
|
+
let x = positionX
|
|
305
|
+
let y = positionY
|
|
306
|
+
// 计算边界限制
|
|
307
|
+
if (x > draggableXRange.value[1]) {
|
|
308
|
+
x = draggableXRange.value[1]
|
|
309
|
+
} else if (x < draggableXRange.value[0]) {
|
|
310
|
+
x = draggableXRange.value[0]
|
|
574
311
|
}
|
|
575
|
-
|
|
576
|
-
|
|
312
|
+
|
|
313
|
+
if (y > draggableYRange.value[1]) {
|
|
314
|
+
y = draggableYRange.value[1]
|
|
315
|
+
} else if (y < draggableYRange.value[0]) {
|
|
316
|
+
y = draggableYRange.value[0]
|
|
577
317
|
}
|
|
318
|
+
|
|
319
|
+
return { x, y }
|
|
320
|
+
}, [])
|
|
321
|
+
|
|
322
|
+
const resetBoundaryAndCheck = ({ width, height }: { width: number; height: number }) => {
|
|
323
|
+
setBoundary({ width, height })
|
|
324
|
+
runOnUI(() => {
|
|
325
|
+
const positionX = offsetX.value
|
|
326
|
+
const positionY = offsetY.value
|
|
327
|
+
const { x: newX, y: newY } = checkBoundaryPosition({ positionX, positionY })
|
|
328
|
+
if (positionX !== newX) {
|
|
329
|
+
offsetX.value = newX
|
|
330
|
+
}
|
|
331
|
+
if (positionY !== newY) {
|
|
332
|
+
offsetY.value = newY
|
|
333
|
+
}
|
|
334
|
+
})()
|
|
578
335
|
}
|
|
579
336
|
|
|
580
337
|
const onLayout = (e: LayoutChangeEvent) => {
|
|
@@ -585,21 +342,16 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
585
342
|
setHeight(height || 0)
|
|
586
343
|
}
|
|
587
344
|
nodeRef.current?.measure((x: number, y: number, width: number, height: number) => {
|
|
588
|
-
const {
|
|
345
|
+
const { top: navigationY = 0 } = navigation?.layout || {}
|
|
589
346
|
layoutRef.current = { x, y: y - navigationY, width, height, offsetLeft: 0, offsetTop: 0 }
|
|
590
|
-
|
|
591
|
-
runOnUI(() => {
|
|
592
|
-
layoutValue.value = { width, height }
|
|
593
|
-
resetBoundaryAndCheck({ width: width, height: height })
|
|
594
|
-
})()
|
|
347
|
+
resetBoundaryAndCheck({ width, height })
|
|
595
348
|
})
|
|
596
|
-
|
|
349
|
+
props.onLayout && props.onLayout(e)
|
|
597
350
|
}
|
|
598
351
|
|
|
599
352
|
const extendEvent = useCallback((e: any, type: 'start' | 'move' | 'end') => {
|
|
600
|
-
const {
|
|
353
|
+
const { top: navigationY = 0 } = navigation?.layout || {}
|
|
601
354
|
const touchArr = [e.changedTouches, e.allTouches]
|
|
602
|
-
const currentProps = propsRef.current
|
|
603
355
|
touchArr.forEach(touches => {
|
|
604
356
|
touches && touches.forEach((item: { absoluteX: number; absoluteY: number; pageX: number; pageY: number; clientX: number; clientY: number }) => {
|
|
605
357
|
item.pageX = item.absoluteX
|
|
@@ -611,8 +363,8 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
611
363
|
Object.assign(e, {
|
|
612
364
|
touches: type === 'end' ? [] : e.allTouches,
|
|
613
365
|
currentTarget: {
|
|
614
|
-
id:
|
|
615
|
-
dataset: collectDataset(
|
|
366
|
+
id: props.id || '',
|
|
367
|
+
dataset: collectDataset(props),
|
|
616
368
|
offsetLeft: 0,
|
|
617
369
|
offsetTop: 0
|
|
618
370
|
},
|
|
@@ -656,14 +408,6 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
656
408
|
catchtouchend && catchtouchend(e)
|
|
657
409
|
}
|
|
658
410
|
|
|
659
|
-
const handleRestBoundaryAndCheck = () => {
|
|
660
|
-
'worklet'
|
|
661
|
-
const { width, height } = layoutValue.value
|
|
662
|
-
if (width && height) {
|
|
663
|
-
resetBoundaryAndCheck({ width, height })
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
|
|
667
411
|
const gesture = useMemo(() => {
|
|
668
412
|
const handleTriggerMove = (e: GestureTouchEvent) => {
|
|
669
413
|
'worklet'
|
|
@@ -680,8 +424,6 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
680
424
|
}
|
|
681
425
|
|
|
682
426
|
const gesturePan = Gesture.Pan()
|
|
683
|
-
.minPointers(1)
|
|
684
|
-
.maxPointers(1)
|
|
685
427
|
.onTouchesDown((e: GestureTouchEvent) => {
|
|
686
428
|
'worklet'
|
|
687
429
|
const changedTouches = e.changedTouches[0] || { x: 0, y: 0 }
|
|
@@ -832,46 +574,14 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
832
574
|
if (waitForHandlers && waitForHandlers.length) {
|
|
833
575
|
gesturePan.requireExternalGestureToFail(...waitForHandlers)
|
|
834
576
|
}
|
|
835
|
-
|
|
836
|
-
// 添加缩放手势支持
|
|
837
|
-
if (scale && !MovableAreaLayout.scaleArea) {
|
|
838
|
-
const gesturePinch = Gesture.Pinch()
|
|
839
|
-
.onUpdate((e: any) => {
|
|
840
|
-
'worklet'
|
|
841
|
-
handleScaleUpdate({ scale: e.scale })
|
|
842
|
-
})
|
|
843
|
-
.onEnd((e: any) => {
|
|
844
|
-
'worklet'
|
|
845
|
-
if (disabled) return
|
|
846
|
-
// 确保最终缩放值在有效范围内
|
|
847
|
-
const finalScale = Math.max(scaleMin, Math.min(scaleMax, currentScale.value))
|
|
848
|
-
if (finalScale !== currentScale.value) {
|
|
849
|
-
currentScale.value = finalScale
|
|
850
|
-
if (bindscale) {
|
|
851
|
-
runOnJS(handleTriggerScale)({
|
|
852
|
-
x: offsetX.value,
|
|
853
|
-
y: offsetY.value,
|
|
854
|
-
scale: finalScale
|
|
855
|
-
})
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
// 缩放结束后重新检查边界
|
|
859
|
-
handleRestBoundaryAndCheck()
|
|
860
|
-
})
|
|
861
|
-
|
|
862
|
-
// 根据手指数量自动区分手势:一指移动,两指缩放
|
|
863
|
-
return Gesture.Exclusive(gesturePan, gesturePinch)
|
|
864
|
-
}
|
|
865
|
-
|
|
866
577
|
return gesturePan
|
|
867
|
-
}, [disabled, direction, inertia, outOfBounds,
|
|
578
|
+
}, [disabled, direction, inertia, outOfBounds, gestureSwitch.current])
|
|
868
579
|
|
|
869
580
|
const animatedStyles = useAnimatedStyle(() => {
|
|
870
581
|
return {
|
|
871
582
|
transform: [
|
|
872
583
|
{ translateX: offsetX.value },
|
|
873
|
-
{ translateY: offsetY.value }
|
|
874
|
-
{ scale: currentScale.value }
|
|
584
|
+
{ translateY: offsetY.value }
|
|
875
585
|
]
|
|
876
586
|
}
|
|
877
587
|
})
|
|
@@ -918,7 +628,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
918
628
|
{
|
|
919
629
|
ref: nodeRef,
|
|
920
630
|
onLayout: onLayout,
|
|
921
|
-
style: [
|
|
631
|
+
style: [innerStyle, animatedStyles, layoutStyle]
|
|
922
632
|
},
|
|
923
633
|
rewriteCatchEvent()
|
|
924
634
|
)
|