@mpxjs/webpack-plugin 2.10.13 → 2.10.14-beta.10
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/dependencies/ImportDependency.js +102 -0
- package/lib/index.js +9 -9
- package/lib/platform/style/wx/index.js +7 -1
- package/lib/platform/template/wx/component-config/button.js +13 -4
- package/lib/platform/template/wx/component-config/index.js +3 -1
- package/lib/platform/template/wx/component-config/nav-container.js +27 -0
- package/lib/react/processScript.js +4 -2
- package/lib/react/script-helper.js +3 -3
- package/lib/runtime/components/ali/mpx-nav-container.mpx +3 -0
- package/lib/runtime/components/react/context.ts +17 -6
- package/lib/runtime/components/react/dist/context.d.ts +78 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/event.config.d.ts +7 -0
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +12 -0
- package/lib/runtime/components/react/dist/mpx-button.d.ts +68 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +23 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +10 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +2 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +32 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +52 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +32 -0
- package/lib/runtime/components/react/dist/mpx-form.d.ts +27 -0
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +18 -0
- package/lib/runtime/components/react/dist/mpx-image.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts +50 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +36 -17
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +12 -0
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +66 -47
- package/lib/runtime/components/react/dist/mpx-label.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +63 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +24 -17
- package/lib/runtime/components/react/dist/mpx-nav-container.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-nav-container.jsx +23 -0
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +2 -0
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +106 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +31 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +22 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +14 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +16 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +12 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +11 -0
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +22 -0
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +16 -0
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +15 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +29 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-radio.d.ts +26 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +1 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +24 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +14 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +54 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +26 -8
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +17 -0
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +15 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +18 -0
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts +52 -0
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +49 -40
- package/lib/runtime/components/react/dist/mpx-switch.d.ts +26 -0
- package/lib/runtime/components/react/dist/mpx-text.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-video.d.ts +101 -0
- package/lib/runtime/components/react/dist/mpx-view.d.ts +34 -0
- package/lib/runtime/components/react/dist/mpx-view.jsx +8 -11
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts +22 -0
- package/lib/runtime/components/react/dist/nav.d.ts +8 -0
- package/lib/runtime/components/react/dist/nav.jsx +137 -0
- package/lib/runtime/components/react/dist/parser.d.ts +39 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +32 -0
- package/lib/runtime/components/react/dist/useNavShared.d.ts +2 -0
- package/lib/runtime/components/react/dist/useNavShared.js +6 -0
- package/lib/runtime/components/react/dist/useNodesRef.d.ts +11 -0
- package/lib/runtime/components/react/dist/utils.d.ts +122 -0
- package/lib/runtime/components/react/mpx-input.tsx +46 -24
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +75 -46
- package/lib/runtime/components/react/mpx-movable-view.tsx +26 -20
- package/lib/runtime/components/react/mpx-nav-container.tsx +33 -0
- package/lib/runtime/components/react/mpx-scroll-view.tsx +30 -8
- package/lib/runtime/components/react/mpx-swiper.tsx +49 -38
- package/lib/runtime/components/react/mpx-view.tsx +8 -11
- package/lib/runtime/components/react/nav.tsx +163 -0
- package/lib/runtime/components/react/types/common.d.ts +19 -0
- package/lib/runtime/components/react/useNavShared.ts +8 -0
- package/lib/runtime/components/web/mpx-nav-container.vue +13 -0
- package/lib/runtime/components/wx/mpx-nav-container.mpx +9 -0
- package/lib/utils/dom-tag-config.js +2 -2
- package/package.json +2 -2
- package/LICENSE +0 -433
- package/lib/dependencies/ImportDependencyTemplate.js +0 -50
|
@@ -5,7 +5,7 @@ import Animated, { useAnimatedStyle, useSharedValue, withTiming, Easing, runOnJS
|
|
|
5
5
|
import React, { JSX, forwardRef, useRef, useEffect, ReactNode, ReactElement, useMemo, createElement } from 'react'
|
|
6
6
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
7
7
|
import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
|
|
8
|
-
import { useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren, extendObject, GestureHandler, flatGesture } from './utils'
|
|
8
|
+
import { useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren, extendObject, GestureHandler, flatGesture, useRunOnJSCallback } from './utils'
|
|
9
9
|
import { SwiperContext } from './context'
|
|
10
10
|
import Portal from './mpx-portal'
|
|
11
11
|
/**
|
|
@@ -148,6 +148,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
148
148
|
autoplay = false,
|
|
149
149
|
circular = false,
|
|
150
150
|
disableGesture = false,
|
|
151
|
+
current: propCurrent = 0,
|
|
151
152
|
bindchange
|
|
152
153
|
} = props
|
|
153
154
|
const easeingFunc = props['easing-function'] || 'default'
|
|
@@ -198,14 +199,16 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
198
199
|
// 每个元素的宽度 or 高度,有固定值直接初始化无则0
|
|
199
200
|
const step = useSharedValue(initStep)
|
|
200
201
|
// 记录选中元素的索引值
|
|
201
|
-
const currentIndex = useSharedValue(
|
|
202
|
+
const currentIndex = useSharedValue(propCurrent)
|
|
202
203
|
// const initOffset = getOffset(props.current || 0, initStep)
|
|
203
204
|
// 记录元素的偏移量
|
|
204
|
-
const offset = useSharedValue(getOffset(
|
|
205
|
+
const offset = useSharedValue(getOffset(propCurrent, initStep))
|
|
205
206
|
const strAbso = 'absolute' + dir.toUpperCase() as StrAbsoType
|
|
206
207
|
const strVelocity = 'velocity' + dir.toUpperCase() as StrVelocityType
|
|
207
208
|
// 标识手指触摸和抬起, 起点在onBegin
|
|
208
209
|
const touchfinish = useSharedValue(true)
|
|
210
|
+
// 记录onUpdate时的方向,用于进行onFinalize中的值修正
|
|
211
|
+
const preUpdateTransDir = useSharedValue(0)
|
|
209
212
|
// 记录上一帧的绝对定位坐标
|
|
210
213
|
const preAbsolutePos = useSharedValue(0)
|
|
211
214
|
// 记录从onBegin 到 onTouchesUp 时移动的距离
|
|
@@ -270,7 +273,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
270
273
|
const iStep = dir === 'x' ? realWidth : realHeight
|
|
271
274
|
if (iStep !== step.value) {
|
|
272
275
|
step.value = iStep
|
|
273
|
-
updateCurrent(
|
|
276
|
+
updateCurrent(propCurrent, iStep)
|
|
274
277
|
updateAutoplay()
|
|
275
278
|
}
|
|
276
279
|
}
|
|
@@ -374,7 +377,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
374
377
|
easing: easeMap[easeingFunc]
|
|
375
378
|
}, () => {
|
|
376
379
|
currentIndex.value = nextIndex
|
|
377
|
-
runOnJS(
|
|
380
|
+
runOnJS(runOnJSCallback)('loop')
|
|
378
381
|
})
|
|
379
382
|
} else {
|
|
380
383
|
// 默认向右, 向下
|
|
@@ -389,7 +392,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
389
392
|
// 将开始位置设置为真正的位置
|
|
390
393
|
offset.value = initOffset
|
|
391
394
|
currentIndex.value = nextIndex
|
|
392
|
-
runOnJS(
|
|
395
|
+
runOnJS(runOnJSCallback)('loop')
|
|
393
396
|
})
|
|
394
397
|
} else {
|
|
395
398
|
nextIndex = currentIndex.value + 1
|
|
@@ -400,7 +403,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
400
403
|
easing: easeMap[easeingFunc]
|
|
401
404
|
}, () => {
|
|
402
405
|
currentIndex.value = nextIndex
|
|
403
|
-
runOnJS(
|
|
406
|
+
runOnJS(runOnJSCallback)('loop')
|
|
404
407
|
})
|
|
405
408
|
}
|
|
406
409
|
}
|
|
@@ -429,12 +432,18 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
429
432
|
}, [])
|
|
430
433
|
|
|
431
434
|
function handleSwiperChange (current: number) {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
bindchange && bindchange(eventData)
|
|
435
|
-
}
|
|
435
|
+
const eventData = getCustomEvent('change', {}, { detail: { current, source: 'touch' }, layoutRef: layoutRef })
|
|
436
|
+
bindchange && bindchange(eventData)
|
|
436
437
|
}
|
|
437
438
|
|
|
439
|
+
const runOnJSCallbackRef = useRef({
|
|
440
|
+
loop,
|
|
441
|
+
pauseLoop,
|
|
442
|
+
resumeLoop,
|
|
443
|
+
handleSwiperChange
|
|
444
|
+
})
|
|
445
|
+
const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef)
|
|
446
|
+
|
|
438
447
|
function getOffset (index: number, stepValue: number) {
|
|
439
448
|
if (!stepValue) return 0
|
|
440
449
|
let targetOffset = 0
|
|
@@ -451,12 +460,12 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
451
460
|
const targetOffset = getOffset(index || 0, stepValue)
|
|
452
461
|
if (targetOffset !== offset.value) {
|
|
453
462
|
// 内部基于props.current!==currentIndex.value决定是否使用动画及更新currentIndex.value
|
|
454
|
-
if (
|
|
463
|
+
if (propCurrent !== undefined && propCurrent !== currentIndex.value) {
|
|
455
464
|
offset.value = withTiming(targetOffset, {
|
|
456
465
|
duration: easeDuration,
|
|
457
466
|
easing: easeMap[easeingFunc]
|
|
458
467
|
}, () => {
|
|
459
|
-
currentIndex.value =
|
|
468
|
+
currentIndex.value = propCurrent
|
|
460
469
|
})
|
|
461
470
|
} else {
|
|
462
471
|
offset.value = targetOffset
|
|
@@ -473,8 +482,8 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
473
482
|
// 1. 用户在当前页切换选中项,动画;用户携带选中index打开到swiper页直接选中不走动画
|
|
474
483
|
useAnimatedReaction(() => currentIndex.value, (newIndex: number, preIndex: number) => {
|
|
475
484
|
// 这里必须传递函数名, 直接写()=> {}形式会报 访问了未sharedValue信息
|
|
476
|
-
if (newIndex !== preIndex && bindchange) {
|
|
477
|
-
runOnJS(
|
|
485
|
+
if (newIndex !== preIndex && preIndex !== null && preIndex !== undefined && bindchange) {
|
|
486
|
+
runOnJS(runOnJSCallback)('handleSwiperChange', newIndex, propCurrent)
|
|
478
487
|
}
|
|
479
488
|
})
|
|
480
489
|
|
|
@@ -508,12 +517,12 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
508
517
|
}, [children.length])
|
|
509
518
|
|
|
510
519
|
useEffect(() => {
|
|
511
|
-
// 1. 如果用户在touch的过程中, 外部更新了current
|
|
520
|
+
// 1. 如果用户在touch的过程中, 外部更新了current以内部为准(小程序表现)
|
|
512
521
|
// 2. 手指滑动过程中更新索引,外部会把current再传入进来,导致offset直接更新,增加判断不同才更新
|
|
513
|
-
if (
|
|
514
|
-
updateCurrent(
|
|
522
|
+
if (propCurrent !== currentIndex.value && touchfinish.value) {
|
|
523
|
+
updateCurrent(propCurrent, step.value)
|
|
515
524
|
}
|
|
516
|
-
}, [
|
|
525
|
+
}, [propCurrent])
|
|
517
526
|
|
|
518
527
|
useEffect(() => {
|
|
519
528
|
autoplayShared.value = autoplay
|
|
@@ -603,7 +612,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
603
612
|
if (touchfinish.value !== false) {
|
|
604
613
|
currentIndex.value = selectedIndex
|
|
605
614
|
offset.value = resetOffset
|
|
606
|
-
runOnJS(
|
|
615
|
+
runOnJS(runOnJSCallback)('resumeLoop')
|
|
607
616
|
}
|
|
608
617
|
})
|
|
609
618
|
} else {
|
|
@@ -613,7 +622,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
613
622
|
}, () => {
|
|
614
623
|
if (touchfinish.value !== false) {
|
|
615
624
|
currentIndex.value = selectedIndex
|
|
616
|
-
runOnJS(
|
|
625
|
+
runOnJS(runOnJSCallback)('resumeLoop')
|
|
617
626
|
}
|
|
618
627
|
})
|
|
619
628
|
}
|
|
@@ -635,7 +644,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
635
644
|
}, () => {
|
|
636
645
|
if (touchfinish.value !== false) {
|
|
637
646
|
currentIndex.value = moveToIndex
|
|
638
|
-
runOnJS(
|
|
647
|
+
runOnJS(runOnJSCallback)('resumeLoop')
|
|
639
648
|
}
|
|
640
649
|
})
|
|
641
650
|
}
|
|
@@ -662,19 +671,10 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
662
671
|
'worklet'
|
|
663
672
|
const { diffOffset, half, isTriggerUpdateHalf } = computeHalf(eventData)
|
|
664
673
|
if (+diffOffset === 0) {
|
|
665
|
-
runOnJS(
|
|
674
|
+
runOnJS(runOnJSCallback)('resumeLoop')
|
|
666
675
|
} else if (isTriggerUpdateHalf) {
|
|
667
|
-
// 如果触发了onUpdate
|
|
668
|
-
|
|
669
|
-
offset.value = withTiming(-targetIndex * step.value, {
|
|
670
|
-
duration: easeDuration,
|
|
671
|
-
easing: easeMap[easeingFunc]
|
|
672
|
-
}, () => {
|
|
673
|
-
if (touchfinish.value !== false) {
|
|
674
|
-
currentIndex.value = targetIndex
|
|
675
|
-
runOnJS(resumeLoop)()
|
|
676
|
-
}
|
|
677
|
-
})
|
|
676
|
+
// 如果触发了onUpdate时的索引变更
|
|
677
|
+
handleEnd(eventData)
|
|
678
678
|
} else if (half) {
|
|
679
679
|
handleEnd(eventData)
|
|
680
680
|
} else {
|
|
@@ -745,18 +745,19 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
745
745
|
if (!step.value) return
|
|
746
746
|
touchfinish.value = false
|
|
747
747
|
cancelAnimation(offset)
|
|
748
|
-
runOnJS(
|
|
748
|
+
runOnJS(runOnJSCallback)('pauseLoop')
|
|
749
749
|
preAbsolutePos.value = e[strAbso]
|
|
750
750
|
moveTranstion.value = e[strAbso]
|
|
751
751
|
})
|
|
752
752
|
.onUpdate((e: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
|
|
753
753
|
'worklet'
|
|
754
|
-
if (touchfinish.value) return
|
|
755
754
|
const moveDistance = e[strAbso] - preAbsolutePos.value
|
|
755
|
+
if (touchfinish.value || moveDistance === 0) return
|
|
756
756
|
const eventData = {
|
|
757
757
|
translation: moveDistance,
|
|
758
|
-
transdir: moveDistance
|
|
758
|
+
transdir: moveDistance
|
|
759
759
|
}
|
|
760
|
+
preUpdateTransDir.value = moveDistance
|
|
760
761
|
// 1. 支持滑动中超出一半更新索引的能力:只更新索引并不会影响onFinalize依据当前offset计算的索引
|
|
761
762
|
const { half } = computeHalf(eventData)
|
|
762
763
|
if (childrenLength.value > 1 && half) {
|
|
@@ -790,15 +791,25 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
790
791
|
}
|
|
791
792
|
preAbsolutePos.value = e[strAbso]
|
|
792
793
|
})
|
|
794
|
+
.onEnd((e: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
|
|
795
|
+
// 修复某些安卓机型小米 onFinalize拿到的absolute值不正确的问题, onUpdate并不是最终的值
|
|
796
|
+
preAbsolutePos.value = e[strAbso]
|
|
797
|
+
})
|
|
793
798
|
.onFinalize((e: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
|
|
794
799
|
'worklet'
|
|
795
800
|
if (touchfinish.value) return
|
|
796
801
|
touchfinish.value = true
|
|
802
|
+
/**
|
|
803
|
+
* 安卓修正
|
|
804
|
+
* 问题:部分安卓机型onFinalize中拿到的absoluteX 有问题
|
|
805
|
+
* 案例:比如手指从右向左滑的时候,onUpdate拿到的是241.64346313476562, 而onFinalize中拿到的是241.81817626953125,理论上onFinalize中应该比onUpdate小才对吧
|
|
806
|
+
* 解决方式:修正
|
|
807
|
+
*/
|
|
797
808
|
// 触发过onUpdate正常情况下e[strAbso] - preAbsolutePos.value=0; 未触发过onUpdate的情况下e[strAbso] - preAbsolutePos.value 不为0
|
|
798
809
|
const moveDistance = e[strAbso] - preAbsolutePos.value
|
|
799
810
|
const eventData = {
|
|
800
811
|
translation: moveDistance,
|
|
801
|
-
transdir: moveDistance
|
|
812
|
+
transdir: Math.abs(moveDistance) > 1 ? moveDistance : preUpdateTransDir.value
|
|
802
813
|
}
|
|
803
814
|
// 1. 只有一个元素:循环 和 非循环状态,都走回弹效果
|
|
804
815
|
if (childrenLength.value === 1) {
|
|
@@ -287,16 +287,13 @@ function backgroundSize (imageProps: ImageProps, preImageInfo: PreImageInfo, ima
|
|
|
287
287
|
} else { // 数值类型 ImageStyle
|
|
288
288
|
// 数值类型设置为 stretch
|
|
289
289
|
imageProps.resizeMode = 'stretch'
|
|
290
|
-
if (type === 'linear') {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
height: dimensionHeight
|
|
298
|
-
} as { width: NumberVal, height: NumberVal }
|
|
299
|
-
}
|
|
290
|
+
if (type === 'linear' && (!layoutWidth || !layoutHeight)) {
|
|
291
|
+
// ios 上 linear 组件只要重新触发渲染,在渲染过程中外层容器 width 或者 height 被设置为 0,通过设置 % 的方式会渲染不出来,即使后面再更新为正常宽高也渲染不出来
|
|
292
|
+
// 所以 hack 手动先将 linear 宽高也设置为 0,后面再更新为正确的数值或 %。
|
|
293
|
+
dimensions = {
|
|
294
|
+
width: 0,
|
|
295
|
+
height: 0
|
|
296
|
+
} as { width: NumberVal, height: NumberVal }
|
|
300
297
|
} else {
|
|
301
298
|
dimensions = {
|
|
302
299
|
width: isPercent(width) ? width : +width,
|
|
@@ -504,7 +501,7 @@ function parseBgImage (text: string): {
|
|
|
504
501
|
type?: 'image' | 'linear'
|
|
505
502
|
src?: string
|
|
506
503
|
} {
|
|
507
|
-
if (!text) return {}
|
|
504
|
+
if (!text || text === 'none') return {}
|
|
508
505
|
|
|
509
506
|
const src = parseUrl(text)
|
|
510
507
|
if (src) return { src, type: 'image' }
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/* eslint-disable space-before-function-paren */
|
|
2
|
+
import { createElement, useState, useMemo, memo, useContext, useLayoutEffect } from 'react'
|
|
3
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
4
|
+
import { StatusBar, processColor, TouchableWithoutFeedback, Image, View, StyleSheet, Text } from 'react-native'
|
|
5
|
+
import { useNavShared } from './useNavShared'
|
|
6
|
+
|
|
7
|
+
function convertToHex(color?: string) {
|
|
8
|
+
try {
|
|
9
|
+
const intColor = processColor(color) as number | null | undefined
|
|
10
|
+
if (intColor === null || intColor === undefined) {
|
|
11
|
+
return null
|
|
12
|
+
}
|
|
13
|
+
// 将32位整数颜色值转换为RGBA
|
|
14
|
+
const r = (intColor >> 16) & 255
|
|
15
|
+
const g = (intColor >> 8) & 255
|
|
16
|
+
const b = intColor & 255
|
|
17
|
+
// 转换为十六进制
|
|
18
|
+
const hexR = r.toString(16).padStart(2, '0')
|
|
19
|
+
const hexG = g.toString(16).padStart(2, '0')
|
|
20
|
+
const hexB = b.toString(16).padStart(2, '0')
|
|
21
|
+
return `#${hexR}${hexG}${hexB}`
|
|
22
|
+
} catch (error) {
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const titleHeight = 44
|
|
28
|
+
export function useInnerHeaderHeight(pageConfig: PageConfig) {
|
|
29
|
+
const safeArea = useSafeAreaInsets()
|
|
30
|
+
if (pageConfig.navigationStyle === 'custom') {
|
|
31
|
+
return 0
|
|
32
|
+
} else {
|
|
33
|
+
const safeAreaTop = safeArea?.top || 0
|
|
34
|
+
const headerHeight = safeAreaTop + titleHeight
|
|
35
|
+
return headerHeight
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const styles = StyleSheet.create({
|
|
40
|
+
header: {
|
|
41
|
+
elevation: 3
|
|
42
|
+
},
|
|
43
|
+
headerContent: {
|
|
44
|
+
flexDirection: 'row',
|
|
45
|
+
alignItems: 'center',
|
|
46
|
+
justifyContent: 'center'
|
|
47
|
+
},
|
|
48
|
+
backButton: {
|
|
49
|
+
position: 'absolute',
|
|
50
|
+
height: '100%',
|
|
51
|
+
width: 40,
|
|
52
|
+
left: 0,
|
|
53
|
+
top: 0,
|
|
54
|
+
alignItems: 'center',
|
|
55
|
+
justifyContent: 'center'
|
|
56
|
+
},
|
|
57
|
+
backButtonImage: {
|
|
58
|
+
width: 22,
|
|
59
|
+
height: 22
|
|
60
|
+
},
|
|
61
|
+
title: {
|
|
62
|
+
fontSize: 17,
|
|
63
|
+
fontWeight: 600,
|
|
64
|
+
width: '60%',
|
|
65
|
+
textAlign: 'center'
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
const NavColor = {
|
|
69
|
+
White: '#ffffff',
|
|
70
|
+
Black: '#000000'
|
|
71
|
+
}
|
|
72
|
+
// navigationBarTextStyle 只支持黑白 'white'/'black
|
|
73
|
+
const validBarTextStyle = (textStyle?: string) => {
|
|
74
|
+
const textStyleColor = convertToHex(textStyle)
|
|
75
|
+
if (textStyle && textStyleColor && [NavColor.White, NavColor.Black].includes(textStyleColor)) {
|
|
76
|
+
return textStyleColor
|
|
77
|
+
} else {
|
|
78
|
+
return NavColor.White
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface MpxNavProps {
|
|
83
|
+
pageConfig: PageConfig
|
|
84
|
+
navigation: any
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const BACK_ICON =
|
|
88
|
+
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAABICAYAAACqT5alAAAA2UlEQVR4nO3bMQrCUBRE0Yla6AYEN2nnBrTL+izcitW3MRDkEUWSvPzJvfCqgMwhZbAppWhNbbIHzB1g9wATERFRVyvpkj1irlpJ5X326D7WHh1hbdFD2CLpLmmftm7kfsEe09aNHFiBrT+wAlt/YAW2/sAKbP2BFdj6Ayuwy+ufz6XPL893krZ//O6iu2n4LT8kndLWTRTo4EC7BDo40C6BDg60S6CDA+0S6OBAuwQ6uNWiD2nrJmoIfU7cNWkR2hbb1UfbY7uuWhGWiIg+a/iHuHmA3QPs3gu4JW9Gan+OJAAAAABJRU5ErkJggg=='
|
|
89
|
+
|
|
90
|
+
const MpxNav = memo(({ pageConfig, navigation }: MpxNavProps) => {
|
|
91
|
+
const [innerPageConfig, setPageConfig] = useState<PageConfig>(pageConfig || {})
|
|
92
|
+
const [customNav] = useNavShared()
|
|
93
|
+
const safeAreaTop = useSafeAreaInsets()?.top || 0
|
|
94
|
+
|
|
95
|
+
navigation.setPageConfig = (config: PageConfig) => {
|
|
96
|
+
setPageConfig(Object.assign({}, innerPageConfig, config))
|
|
97
|
+
}
|
|
98
|
+
const isCustom = innerPageConfig.navigationStyle === 'custom'
|
|
99
|
+
const navigationBarTextStyle = useMemo(() => validBarTextStyle(innerPageConfig.navigationBarTextStyle), [innerPageConfig.navigationBarTextStyle])
|
|
100
|
+
// 状态栏的颜色
|
|
101
|
+
const statusBarElement = (
|
|
102
|
+
<StatusBar
|
|
103
|
+
translucent
|
|
104
|
+
backgroundColor='transparent'
|
|
105
|
+
barStyle={navigationBarTextStyle === NavColor.White ? 'light-content' : 'dark-content'}></StatusBar>
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
if (isCustom)
|
|
109
|
+
return (
|
|
110
|
+
<>
|
|
111
|
+
{statusBarElement}
|
|
112
|
+
{customNav}
|
|
113
|
+
</>
|
|
114
|
+
)
|
|
115
|
+
// 假设是栈导航,获取栈的长度
|
|
116
|
+
const stackLength = navigation.getState()?.routes?.length
|
|
117
|
+
const onStackTopBack = mpxGlobal?.__mpx?.config?.rnConfig?.onStackTopBack
|
|
118
|
+
const isHandleStackTopBack = typeof onStackTopBack === 'function'
|
|
119
|
+
|
|
120
|
+
// 回退按钮与图标
|
|
121
|
+
// prettier-ignore
|
|
122
|
+
const backElement = stackLength > 1 || isHandleStackTopBack
|
|
123
|
+
? (
|
|
124
|
+
<TouchableWithoutFeedback
|
|
125
|
+
onPress={() => {
|
|
126
|
+
if (stackLength <= 1 && isHandleStackTopBack) {
|
|
127
|
+
onStackTopBack()
|
|
128
|
+
return
|
|
129
|
+
}
|
|
130
|
+
navigation.goBack()
|
|
131
|
+
}}>
|
|
132
|
+
<View style={[styles.backButton]}>
|
|
133
|
+
<Image style={[styles.backButtonImage, { tintColor: navigationBarTextStyle }]} source={{ uri: BACK_ICON }}></Image>
|
|
134
|
+
</View>
|
|
135
|
+
</TouchableWithoutFeedback>
|
|
136
|
+
)
|
|
137
|
+
: null
|
|
138
|
+
|
|
139
|
+
return (
|
|
140
|
+
<View
|
|
141
|
+
style={[
|
|
142
|
+
styles.header,
|
|
143
|
+
{
|
|
144
|
+
paddingTop: safeAreaTop,
|
|
145
|
+
backgroundColor: innerPageConfig.navigationBarBackgroundColor || '#000000'
|
|
146
|
+
}
|
|
147
|
+
]}>
|
|
148
|
+
{statusBarElement}
|
|
149
|
+
{/* TODO: 确定 height 的有效性 */}
|
|
150
|
+
{/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
|
|
151
|
+
{/* @ts-expect-error */}
|
|
152
|
+
<View style={styles.headerContent} height={titleHeight}>
|
|
153
|
+
{backElement}
|
|
154
|
+
<Text style={[styles.title, { color: navigationBarTextStyle }]} numberOfLines={1}>
|
|
155
|
+
{innerPageConfig.navigationBarTitleText?.trim() || ''}
|
|
156
|
+
</Text>
|
|
157
|
+
</View>
|
|
158
|
+
</View>
|
|
159
|
+
)
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
MpxNav.displayName = 'MpxNav'
|
|
163
|
+
export default MpxNav
|
|
@@ -18,3 +18,22 @@ export type ExtendedFunctionComponent = FunctionComponent & {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export type AnyFunc = (...args: ReadonlyArray<any>) => any
|
|
21
|
+
|
|
22
|
+
declare global {
|
|
23
|
+
interface PageConfig {
|
|
24
|
+
/**
|
|
25
|
+
* 是否自定义导航栏
|
|
26
|
+
*/
|
|
27
|
+
navigationStyle?: 'custom'
|
|
28
|
+
/**
|
|
29
|
+
* 标题栏样式
|
|
30
|
+
*/
|
|
31
|
+
navigationBarTextStyle?: 'white' | 'black' | '#ffffff' | '#000000'
|
|
32
|
+
/**
|
|
33
|
+
* 页面标题
|
|
34
|
+
*/
|
|
35
|
+
navigationBarTitleText?: string
|
|
36
|
+
|
|
37
|
+
[key: string]: any
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -78,7 +78,7 @@ const isBuildInWebTag = makeMap(
|
|
|
78
78
|
'mpx-swiper,mpx-view,mpx-checkbox-group,mpx-movable-area,mpx-radio-group,' +
|
|
79
79
|
'mpx-switch,mpx-web-view,mpx-checkbox,mpx-movable-view,mpx-radio,' +
|
|
80
80
|
'mpx-tab-bar-container,mpx-form,mpx-navigator,mpx-rich-text,mpx-tab-bar,' +
|
|
81
|
-
'mpx-icon,mpx-picker-view-column,mpx-scroll-view,mpx-text'
|
|
81
|
+
'mpx-icon,mpx-picker-view-column,mpx-scroll-view,mpx-text,mpx-nav-container'
|
|
82
82
|
)
|
|
83
83
|
|
|
84
84
|
/**
|
|
@@ -91,7 +91,7 @@ const isBuildInReactTag = makeMap(
|
|
|
91
91
|
'mpx-movable-area,mpx-label,mpx-keyboard-avoiding-view,mpx-input,mpx-inline-text,' +
|
|
92
92
|
'mpx-image,mpx-form,mpx-checkbox,mpx-checkbox-group,mpx-button,' +
|
|
93
93
|
'mpx-rich-text,mpx-portal,mpx-popup,mpx-picker-view-column,mpx-picker-view,mpx-picker,' +
|
|
94
|
-
'mpx-icon,mpx-canvas'
|
|
94
|
+
'mpx-icon,mpx-canvas,mpx-nav-container'
|
|
95
95
|
)
|
|
96
96
|
|
|
97
97
|
const isSpace = makeMap('ensp,emsp,nbsp')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.14-beta.10",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -100,5 +100,5 @@
|
|
|
100
100
|
"engines": {
|
|
101
101
|
"node": ">=14.14.0"
|
|
102
102
|
},
|
|
103
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "2d37697869b9bdda3efab92dda8c910b68fd05c0"
|
|
104
104
|
}
|