@mpxjs/webpack-plugin 2.10.7-beta.9 → 2.10.7
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/RecordPageConfigsMapDependency.js +1 -1
- package/lib/index.js +5 -6
- package/lib/platform/style/wx/index.js +0 -7
- package/lib/platform/template/wx/component-config/index.js +1 -5
- package/lib/platform/template/wx/component-config/movable-view.js +10 -1
- package/lib/platform/template/wx/index.js +2 -1
- package/lib/runtime/components/react/context.ts +4 -23
- package/lib/runtime/components/react/dist/context.js +2 -5
- package/lib/runtime/components/react/dist/getInnerListeners.js +1 -1
- package/lib/runtime/components/react/dist/mpx-button.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +9 -63
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +63 -308
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +15 -31
- 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-button.tsx +2 -3
- package/lib/runtime/components/react/mpx-movable-area.tsx +11 -98
- package/lib/runtime/components/react/mpx-movable-view.tsx +64 -358
- package/lib/runtime/components/react/mpx-scroll-view.tsx +59 -84
- 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/components/web/mpx-scroll-view.vue +4 -18
- package/lib/template-compiler/bind-this.js +1 -2
- package/lib/template-compiler/compiler.js +2 -2
- package/package.json +4 -4
- package/lib/platform/template/wx/component-config/sticky-header.js +0 -23
- package/lib/platform/template/wx/component-config/sticky-section.js +0 -23
- package/lib/runtime/components/react/AsyncContainer.tsx +0 -189
- package/lib/runtime/components/react/dist/AsyncContainer.jsx +0 -141
- package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +0 -117
- package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +0 -45
- package/lib/runtime/components/react/mpx-sticky-header.tsx +0 -181
- package/lib/runtime/components/react/mpx-sticky-section.tsx +0 -96
- package/lib/runtime/components/web/mpx-sticky-header.vue +0 -99
- package/lib/runtime/components/web/mpx-sticky-section.vue +0 -15
|
@@ -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
|
|
@@ -75,7 +70,6 @@ interface MovableViewProps {
|
|
|
75
70
|
'parent-font-size'?: number
|
|
76
71
|
'parent-width'?: number
|
|
77
72
|
'parent-height'?: number
|
|
78
|
-
'disable-event-passthrough'?: boolean
|
|
79
73
|
}
|
|
80
74
|
|
|
81
75
|
const styles = StyleSheet.create({
|
|
@@ -102,10 +96,6 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
102
96
|
inertia = false,
|
|
103
97
|
disabled = false,
|
|
104
98
|
animation = true,
|
|
105
|
-
scale = false,
|
|
106
|
-
'scale-min': scaleMin = 0.1,
|
|
107
|
-
'scale-max': scaleMax = 10,
|
|
108
|
-
'scale-value': scaleValue = 1,
|
|
109
99
|
'out-of-bounds': outOfBounds = false,
|
|
110
100
|
'enable-var': enableVar,
|
|
111
101
|
'external-var-context': externalVarContext,
|
|
@@ -113,7 +103,6 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
113
103
|
'parent-width': parentWidth,
|
|
114
104
|
'parent-height': parentHeight,
|
|
115
105
|
direction = 'none',
|
|
116
|
-
'disable-event-passthrough': disableEventPassthrough = false,
|
|
117
106
|
'simultaneous-handlers': originSimultaneousHandlers = [],
|
|
118
107
|
'wait-for': waitFor = [],
|
|
119
108
|
style = {},
|
|
@@ -128,9 +117,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
128
117
|
catchtouchmove,
|
|
129
118
|
bindtouchend,
|
|
130
119
|
catchtouchend,
|
|
131
|
-
|
|
132
|
-
bindchange,
|
|
133
|
-
onLayout: propsOnLayout
|
|
120
|
+
bindchange
|
|
134
121
|
} = props
|
|
135
122
|
|
|
136
123
|
const {
|
|
@@ -140,7 +127,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
140
127
|
varContextRef,
|
|
141
128
|
setWidth,
|
|
142
129
|
setHeight
|
|
143
|
-
} = useTransformStyle(Object.assign({}, styles.container
|
|
130
|
+
} = useTransformStyle(Object.assign({}, style, styles.container), { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
144
131
|
|
|
145
132
|
const navigation = useNavigation()
|
|
146
133
|
|
|
@@ -151,8 +138,6 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
151
138
|
|
|
152
139
|
const offsetX = useSharedValue(x)
|
|
153
140
|
const offsetY = useSharedValue(y)
|
|
154
|
-
const currentScale = useSharedValue(1)
|
|
155
|
-
const layoutValue = useSharedValue<any>({})
|
|
156
141
|
|
|
157
142
|
const startPosition = useSharedValue({
|
|
158
143
|
x: 0,
|
|
@@ -215,41 +200,6 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
215
200
|
)
|
|
216
201
|
}, [])
|
|
217
202
|
|
|
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
203
|
// 节流版本的 change 事件触发
|
|
254
204
|
const handleTriggerChangeThrottled = useCallback(({ x, y, type }: { x: number; y: number; type?: string }) => {
|
|
255
205
|
'worklet'
|
|
@@ -291,223 +241,12 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
291
241
|
})()
|
|
292
242
|
}, [x, y])
|
|
293
243
|
|
|
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
|
-
useEffect(() => {
|
|
424
|
-
runOnUI(() => {
|
|
425
|
-
if (currentScale.value !== scaleValue) {
|
|
426
|
-
// 限制缩放值在 scaleMin 和 scaleMax 之间
|
|
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
244
|
useEffect(() => {
|
|
482
|
-
|
|
483
|
-
|
|
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
|
-
}
|
|
245
|
+
const { width, height } = layoutRef.current
|
|
246
|
+
if (width && height) {
|
|
247
|
+
resetBoundaryAndCheck({ width, height })
|
|
509
248
|
}
|
|
510
|
-
}, [MovableAreaLayout.
|
|
249
|
+
}, [MovableAreaLayout.height, MovableAreaLayout.width])
|
|
511
250
|
|
|
512
251
|
const getTouchSource = useCallback((offsetX: number, offsetY: number) => {
|
|
513
252
|
const hasOverBoundary = offsetX < draggableXRange.value[0] || offsetX > draggableXRange.value[1] ||
|
|
@@ -531,50 +270,66 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
531
270
|
}, [])
|
|
532
271
|
|
|
533
272
|
const setBoundary = useCallback(({ width, height }: { width: number; height: number }) => {
|
|
534
|
-
'worklet'
|
|
535
273
|
const top = (style.position === 'absolute' && style.top) || 0
|
|
536
274
|
const left = (style.position === 'absolute' && style.left) || 0
|
|
537
275
|
|
|
538
|
-
|
|
539
|
-
const
|
|
540
|
-
const scaledWidth = (width || 0) * currentScaleVal
|
|
541
|
-
const scaledHeight = (height || 0) * currentScaleVal
|
|
276
|
+
const scaledWidth = width || 0
|
|
277
|
+
const scaledHeight = height || 0
|
|
542
278
|
|
|
543
|
-
|
|
544
|
-
const
|
|
545
|
-
const maxOffsetX = MovableAreaLayout.width - scaledWidth - left
|
|
279
|
+
const maxY = MovableAreaLayout.height - scaledHeight - top
|
|
280
|
+
const maxX = MovableAreaLayout.width - scaledWidth - left
|
|
546
281
|
|
|
547
282
|
let xRange: [min: number, max: number]
|
|
548
283
|
let yRange: [min: number, max: number]
|
|
549
284
|
|
|
550
285
|
if (MovableAreaLayout.width < scaledWidth) {
|
|
551
|
-
xRange = [
|
|
286
|
+
xRange = [maxX, 0]
|
|
552
287
|
} else {
|
|
553
|
-
xRange = [-left,
|
|
288
|
+
xRange = [left === 0 ? 0 : -left, maxX < 0 ? 0 : maxX]
|
|
554
289
|
}
|
|
555
290
|
|
|
556
291
|
if (MovableAreaLayout.height < scaledHeight) {
|
|
557
|
-
yRange = [
|
|
292
|
+
yRange = [maxY, 0]
|
|
558
293
|
} else {
|
|
559
|
-
yRange = [-top,
|
|
294
|
+
yRange = [top === 0 ? 0 : -top, maxY < 0 ? 0 : maxY]
|
|
560
295
|
}
|
|
561
|
-
|
|
562
296
|
draggableXRange.value = xRange
|
|
563
297
|
draggableYRange.value = yRange
|
|
564
298
|
}, [MovableAreaLayout.height, MovableAreaLayout.width, style.position, style.top, style.left])
|
|
565
299
|
|
|
566
|
-
const
|
|
300
|
+
const checkBoundaryPosition = useCallback(({ positionX, positionY }: { positionX: number; positionY: number }) => {
|
|
567
301
|
'worklet'
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
302
|
+
let x = positionX
|
|
303
|
+
let y = positionY
|
|
304
|
+
// 计算边界限制
|
|
305
|
+
if (x > draggableXRange.value[1]) {
|
|
306
|
+
x = draggableXRange.value[1]
|
|
307
|
+
} else if (x < draggableXRange.value[0]) {
|
|
308
|
+
x = draggableXRange.value[0]
|
|
574
309
|
}
|
|
575
|
-
|
|
576
|
-
|
|
310
|
+
|
|
311
|
+
if (y > draggableYRange.value[1]) {
|
|
312
|
+
y = draggableYRange.value[1]
|
|
313
|
+
} else if (y < draggableYRange.value[0]) {
|
|
314
|
+
y = draggableYRange.value[0]
|
|
577
315
|
}
|
|
316
|
+
|
|
317
|
+
return { x, y }
|
|
318
|
+
}, [])
|
|
319
|
+
|
|
320
|
+
const resetBoundaryAndCheck = ({ width, height }: { width: number; height: number }) => {
|
|
321
|
+
setBoundary({ width, height })
|
|
322
|
+
runOnUI(() => {
|
|
323
|
+
const positionX = offsetX.value
|
|
324
|
+
const positionY = offsetY.value
|
|
325
|
+
const { x: newX, y: newY } = checkBoundaryPosition({ positionX, positionY })
|
|
326
|
+
if (positionX !== newX) {
|
|
327
|
+
offsetX.value = newX
|
|
328
|
+
}
|
|
329
|
+
if (positionY !== newY) {
|
|
330
|
+
offsetY.value = newY
|
|
331
|
+
}
|
|
332
|
+
})()
|
|
578
333
|
}
|
|
579
334
|
|
|
580
335
|
const onLayout = (e: LayoutChangeEvent) => {
|
|
@@ -585,21 +340,16 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
585
340
|
setHeight(height || 0)
|
|
586
341
|
}
|
|
587
342
|
nodeRef.current?.measure((x: number, y: number, width: number, height: number) => {
|
|
588
|
-
const {
|
|
343
|
+
const { top: navigationY = 0 } = navigation?.layout || {}
|
|
589
344
|
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
|
-
})()
|
|
345
|
+
resetBoundaryAndCheck({ width, height })
|
|
595
346
|
})
|
|
596
|
-
|
|
347
|
+
props.onLayout && props.onLayout(e)
|
|
597
348
|
}
|
|
598
349
|
|
|
599
350
|
const extendEvent = useCallback((e: any, type: 'start' | 'move' | 'end') => {
|
|
600
|
-
const {
|
|
351
|
+
const { top: navigationY = 0 } = navigation?.layout || {}
|
|
601
352
|
const touchArr = [e.changedTouches, e.allTouches]
|
|
602
|
-
const currentProps = propsRef.current
|
|
603
353
|
touchArr.forEach(touches => {
|
|
604
354
|
touches && touches.forEach((item: { absoluteX: number; absoluteY: number; pageX: number; pageY: number; clientX: number; clientY: number }) => {
|
|
605
355
|
item.pageX = item.absoluteX
|
|
@@ -611,8 +361,8 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
611
361
|
Object.assign(e, {
|
|
612
362
|
touches: type === 'end' ? [] : e.allTouches,
|
|
613
363
|
currentTarget: {
|
|
614
|
-
id:
|
|
615
|
-
dataset: collectDataset(
|
|
364
|
+
id: props.id || '',
|
|
365
|
+
dataset: collectDataset(props),
|
|
616
366
|
offsetLeft: 0,
|
|
617
367
|
offsetTop: 0
|
|
618
368
|
},
|
|
@@ -656,14 +406,6 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
656
406
|
catchtouchend && catchtouchend(e)
|
|
657
407
|
}
|
|
658
408
|
|
|
659
|
-
const handleRestBoundaryAndCheck = () => {
|
|
660
|
-
'worklet'
|
|
661
|
-
const { width, height } = layoutValue.value
|
|
662
|
-
if (width && height) {
|
|
663
|
-
resetBoundaryAndCheck({ width, height })
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
|
|
667
409
|
const gesture = useMemo(() => {
|
|
668
410
|
const handleTriggerMove = (e: GestureTouchEvent) => {
|
|
669
411
|
'worklet'
|
|
@@ -680,8 +422,6 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
680
422
|
}
|
|
681
423
|
|
|
682
424
|
const gesturePan = Gesture.Pan()
|
|
683
|
-
.minPointers(1)
|
|
684
|
-
.maxPointers(1)
|
|
685
425
|
.onTouchesDown((e: GestureTouchEvent) => {
|
|
686
426
|
'worklet'
|
|
687
427
|
const changedTouches = e.changedTouches[0] || { x: 0, y: 0 }
|
|
@@ -817,12 +557,10 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
817
557
|
})
|
|
818
558
|
.withRef(movableGestureRef)
|
|
819
559
|
|
|
820
|
-
if (
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
gesturePan.activeOffsetY([-5, 5]).failOffsetX([-5, 5])
|
|
825
|
-
}
|
|
560
|
+
if (direction === 'horizontal') {
|
|
561
|
+
gesturePan.activeOffsetX([-5, 5]).failOffsetY([-5, 5])
|
|
562
|
+
} else if (direction === 'vertical') {
|
|
563
|
+
gesturePan.activeOffsetY([-5, 5]).failOffsetX([-5, 5])
|
|
826
564
|
}
|
|
827
565
|
|
|
828
566
|
if (simultaneousHandlers && simultaneousHandlers.length) {
|
|
@@ -832,46 +570,14 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
832
570
|
if (waitForHandlers && waitForHandlers.length) {
|
|
833
571
|
gesturePan.requireExternalGestureToFail(...waitForHandlers)
|
|
834
572
|
}
|
|
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
573
|
return gesturePan
|
|
867
|
-
}, [disabled, direction, inertia, outOfBounds,
|
|
574
|
+
}, [disabled, direction, inertia, outOfBounds, gestureSwitch.current])
|
|
868
575
|
|
|
869
576
|
const animatedStyles = useAnimatedStyle(() => {
|
|
870
577
|
return {
|
|
871
578
|
transform: [
|
|
872
579
|
{ translateX: offsetX.value },
|
|
873
|
-
{ translateY: offsetY.value }
|
|
874
|
-
{ scale: currentScale.value }
|
|
580
|
+
{ translateY: offsetY.value }
|
|
875
581
|
]
|
|
876
582
|
}
|
|
877
583
|
})
|
|
@@ -918,7 +624,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
918
624
|
{
|
|
919
625
|
ref: nodeRef,
|
|
920
626
|
onLayout: onLayout,
|
|
921
|
-
style: [
|
|
627
|
+
style: [innerStyle, animatedStyles, layoutStyle]
|
|
922
628
|
},
|
|
923
629
|
rewriteCatchEvent()
|
|
924
630
|
)
|