@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
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
* ✔ bindscroll
|
|
33
33
|
*/
|
|
34
34
|
import { ScrollView, RefreshControl, Gesture, GestureDetector } from 'react-native-gesture-handler';
|
|
35
|
-
import { Animated as RNAnimated } from 'react-native';
|
|
36
35
|
import { isValidElement, Children, useRef, useState, useEffect, forwardRef, useContext, useMemo, createElement } from 'react';
|
|
37
36
|
import Animated, { useAnimatedRef, useSharedValue, withTiming, useAnimatedStyle, runOnJS } from 'react-native-reanimated';
|
|
38
37
|
import { warn, hasOwn } from '@mpxjs/utils';
|
|
@@ -41,11 +40,9 @@ import useNodesRef from './useNodesRef';
|
|
|
41
40
|
import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture, HIDDEN_STYLE } from './utils';
|
|
42
41
|
import { IntersectionObserverContext, ScrollViewContext } from './context';
|
|
43
42
|
import Portal from './mpx-portal';
|
|
44
|
-
const AnimatedScrollView = RNAnimated.createAnimatedComponent(ScrollView);
|
|
45
43
|
const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
46
44
|
const { textProps, innerProps: props = {} } = splitProps(scrollViewProps);
|
|
47
|
-
const { enhanced = false, bounces = true, style = {}, binddragstart, binddragging, binddragend, bindtouchstart, bindtouchmove, bindtouchend, 'scroll-x': scrollX = false, 'scroll-y': scrollY = false, 'enable-back-to-top': enableBackToTop = false, 'enable-trigger-intersection-observer': enableTriggerIntersectionObserver = false, 'paging-enabled': pagingEnabled = false, 'upper-threshold': upperThreshold = 50, 'lower-threshold': lowerThreshold = 50, 'scroll-with-animation': scrollWithAnimation = false, 'refresher-enabled': refresherEnabled, 'refresher-default-style': refresherDefaultStyle, 'refresher-background': refresherBackground, 'refresher-threshold': refresherThreshold = 45, 'show-scrollbar': showScrollbar = true, 'scroll-into-view': scrollIntoView = '', 'scroll-top': scrollTop = 0, 'scroll-left': scrollLeft = 0, 'refresher-triggered': refresherTriggered, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'simultaneous-handlers': originSimultaneousHandlers, 'wait-for': waitFor, '
|
|
48
|
-
const scrollOffset = useRef(new RNAnimated.Value(0)).current;
|
|
45
|
+
const { enhanced = false, bounces = true, style = {}, binddragstart, binddragging, binddragend, bindtouchstart, bindtouchmove, bindtouchend, 'scroll-x': scrollX = false, 'scroll-y': scrollY = false, 'enable-back-to-top': enableBackToTop = false, 'enable-trigger-intersection-observer': enableTriggerIntersectionObserver = false, 'paging-enabled': pagingEnabled = false, 'upper-threshold': upperThreshold = 50, 'lower-threshold': lowerThreshold = 50, 'scroll-with-animation': scrollWithAnimation = false, 'refresher-enabled': refresherEnabled, 'refresher-default-style': refresherDefaultStyle, 'refresher-background': refresherBackground, 'refresher-threshold': refresherThreshold = 45, 'show-scrollbar': showScrollbar = true, 'scroll-into-view': scrollIntoView = '', 'scroll-top': scrollTop = 0, 'scroll-left': scrollLeft = 0, 'refresher-triggered': refresherTriggered, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'simultaneous-handlers': originSimultaneousHandlers, 'wait-for': waitFor, 'scroll-event-throttle': scrollEventThrottle = 0, __selectRef } = props;
|
|
49
46
|
const simultaneousHandlers = flatGesture(originSimultaneousHandlers);
|
|
50
47
|
const waitForHandlers = flatGesture(waitFor);
|
|
51
48
|
const snapScrollTop = useRef(0);
|
|
@@ -69,7 +66,7 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
69
66
|
const hasCallScrollToLower = useRef(false);
|
|
70
67
|
const initialTimeout = useRef(null);
|
|
71
68
|
const intersectionObservers = useContext(IntersectionObserverContext);
|
|
72
|
-
const firstScrollIntoViewChange = useRef(
|
|
69
|
+
const firstScrollIntoViewChange = useRef(false);
|
|
73
70
|
const refreshColor = {
|
|
74
71
|
black: ['#000'],
|
|
75
72
|
white: ['#fff']
|
|
@@ -89,18 +86,16 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
89
86
|
pagingEnabled,
|
|
90
87
|
fastDeceleration: false,
|
|
91
88
|
decelerationDisabled: false,
|
|
92
|
-
scrollTo
|
|
93
|
-
scrollIntoView: handleScrollIntoView
|
|
89
|
+
scrollTo
|
|
94
90
|
},
|
|
95
91
|
gestureRef: scrollViewRef
|
|
96
92
|
});
|
|
97
|
-
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout });
|
|
98
93
|
const contextValue = useMemo(() => {
|
|
99
94
|
return {
|
|
100
|
-
gestureRef: scrollViewRef
|
|
101
|
-
scrollOffset
|
|
95
|
+
gestureRef: scrollViewRef
|
|
102
96
|
};
|
|
103
97
|
}, []);
|
|
98
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout });
|
|
104
99
|
const hasRefresherLayoutRef = useRef(false);
|
|
105
100
|
// layout 完成前先隐藏,避免安卓闪烁问题
|
|
106
101
|
const refresherLayoutStyle = useMemo(() => { return !hasRefresherLayoutRef.current ? HIDDEN_STYLE : {}; }, [hasRefresherLayoutRef.current]);
|
|
@@ -120,16 +115,14 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
120
115
|
}, [scrollTop, scrollLeft]);
|
|
121
116
|
useEffect(() => {
|
|
122
117
|
if (scrollIntoView && __selectRef) {
|
|
123
|
-
if (firstScrollIntoViewChange.current) {
|
|
124
|
-
setTimeout(
|
|
125
|
-
handleScrollIntoView(scrollIntoView, { offset: scrollIntoViewOffset, animated: scrollWithAnimation });
|
|
126
|
-
});
|
|
118
|
+
if (!firstScrollIntoViewChange.current) {
|
|
119
|
+
setTimeout(handleScrollIntoView);
|
|
127
120
|
}
|
|
128
121
|
else {
|
|
129
|
-
handleScrollIntoView(
|
|
122
|
+
handleScrollIntoView();
|
|
130
123
|
}
|
|
131
124
|
}
|
|
132
|
-
firstScrollIntoViewChange.current =
|
|
125
|
+
firstScrollIntoViewChange.current = true;
|
|
133
126
|
}, [scrollIntoView]);
|
|
134
127
|
useEffect(() => {
|
|
135
128
|
if (refresherEnabled) {
|
|
@@ -149,15 +142,13 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
149
142
|
function scrollTo({ top = 0, left = 0, animated = false }) {
|
|
150
143
|
scrollToOffset(left, top, animated);
|
|
151
144
|
}
|
|
152
|
-
function handleScrollIntoView(
|
|
153
|
-
const refs = __selectRef(`#${
|
|
145
|
+
function handleScrollIntoView() {
|
|
146
|
+
const refs = __selectRef(`#${scrollIntoView}`, 'node');
|
|
154
147
|
if (!refs)
|
|
155
148
|
return;
|
|
156
149
|
const { nodeRef } = refs.getNodeInstance();
|
|
157
150
|
nodeRef.current?.measureLayout(scrollViewRef.current, (left, top) => {
|
|
158
|
-
|
|
159
|
-
const adjustedTop = scrollY ? top + offset : top;
|
|
160
|
-
scrollToOffset(adjustedLeft, adjustedTop, animated);
|
|
151
|
+
scrollToOffset(left, top);
|
|
161
152
|
});
|
|
162
153
|
}
|
|
163
154
|
function selectLength(size) {
|
|
@@ -330,12 +321,6 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
330
321
|
updateScrollOptions(e, { scrollLeft, scrollTop });
|
|
331
322
|
updateIntersection();
|
|
332
323
|
}
|
|
333
|
-
const scrollHandler = RNAnimated.event([{ nativeEvent: { contentOffset: { y: scrollOffset } } }], {
|
|
334
|
-
useNativeDriver: true,
|
|
335
|
-
listener: (event) => {
|
|
336
|
-
onScroll(event);
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
324
|
function onScrollDragStart(e) {
|
|
340
325
|
hasCallScrollToLower.current = false;
|
|
341
326
|
hasCallScrollToUpper.current = false;
|
|
@@ -496,7 +481,7 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
496
481
|
scrollEnabled: !enableScroll ? false : !!(scrollX || scrollY),
|
|
497
482
|
bounces: false,
|
|
498
483
|
ref: scrollViewRef,
|
|
499
|
-
onScroll:
|
|
484
|
+
onScroll: onScroll,
|
|
500
485
|
onContentSizeChange: onContentSizeChange,
|
|
501
486
|
bindtouchstart: ((enhanced && binddragstart) || bindtouchstart) && onScrollTouchStart,
|
|
502
487
|
bindtouchmove: ((enhanced && binddragging) || bindtouchmove) && onScrollTouchMove,
|
|
@@ -538,14 +523,13 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
538
523
|
'bindscrolltolower',
|
|
539
524
|
'bindrefresherrefresh'
|
|
540
525
|
], { layoutRef });
|
|
541
|
-
const
|
|
542
|
-
const withRefresherScrollView = createElement(GestureDetector, { gesture: panGesture }, createElement(ScrollViewComponent, innerProps, createElement(Animated.View, { style: [refresherAnimatedStyle, refresherLayoutStyle], onLayout: onRefresherLayout }, refresherContent), createElement(Animated.View, { style: contentAnimatedStyle }, createElement(ScrollViewContext.Provider, { value: contextValue }, wrapChildren(extendObject({}, props, { children: otherContent }), {
|
|
526
|
+
const withRefresherScrollView = createElement(GestureDetector, { gesture: panGesture }, createElement(ScrollView, innerProps, createElement(Animated.View, { style: [refresherAnimatedStyle, refresherLayoutStyle], onLayout: onRefresherLayout }, refresherContent), createElement(Animated.View, { style: contentAnimatedStyle }, createElement(ScrollViewContext.Provider, { value: contextValue }, wrapChildren(extendObject({}, props, { children: otherContent }), {
|
|
543
527
|
hasVarDec,
|
|
544
528
|
varContext: varContextRef.current,
|
|
545
529
|
textStyle,
|
|
546
530
|
textProps
|
|
547
531
|
})))));
|
|
548
|
-
const commonScrollView = createElement(
|
|
532
|
+
const commonScrollView = createElement(ScrollView, extendObject(innerProps, {
|
|
549
533
|
refreshControl: refresherEnabled
|
|
550
534
|
? createElement(RefreshControl, extendObject({
|
|
551
535
|
progressBackgroundColor: refresherBackground,
|
|
@@ -125,10 +125,6 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
125
125
|
const moveTranstion = useSharedValue(0);
|
|
126
126
|
// 记录从onBegin 到 onTouchesUp 的时间
|
|
127
127
|
const moveTime = useSharedValue(0);
|
|
128
|
-
// 记录从onBegin 到 onTouchesCancelled 另外一个方向移动的距离
|
|
129
|
-
const anotherDirectionMove = useSharedValue(0);
|
|
130
|
-
// 另一个方向的
|
|
131
|
-
const anotherAbso = 'absolute' + (dir === 'x' ? 'y' : 'x').toUpperCase();
|
|
132
128
|
const timerId = useRef(0);
|
|
133
129
|
const intervalTimer = props.interval || 500;
|
|
134
130
|
const simultaneousHandlers = flatGesture(originSimultaneousHandlers);
|
|
@@ -409,11 +405,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
409
405
|
}
|
|
410
406
|
}, [children.length]);
|
|
411
407
|
useEffect(() => {
|
|
412
|
-
|
|
413
|
-
// 2. 手指滑动过程中更新索引,外部会把current再穿进来,导致offset直接更新了
|
|
414
|
-
if (props.current !== currentIndex.value) {
|
|
415
|
-
updateCurrent(props.current || 0, step.value);
|
|
416
|
-
}
|
|
408
|
+
updateCurrent(props.current || 0, step.value);
|
|
417
409
|
}, [props.current]);
|
|
418
410
|
useEffect(() => {
|
|
419
411
|
autoplayShared.value = autoplay;
|
|
@@ -476,26 +468,20 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
476
468
|
targetOffset: -moveToTargetPos
|
|
477
469
|
};
|
|
478
470
|
}
|
|
479
|
-
function
|
|
471
|
+
function canMove(eventData) {
|
|
480
472
|
'worklet';
|
|
481
473
|
const { translation } = eventData;
|
|
482
474
|
const currentOffset = Math.abs(offset.value);
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
canMove: currentOffset < boundaryOffset
|
|
491
|
-
};
|
|
475
|
+
if (!circularShared.value) {
|
|
476
|
+
if (translation < 0) {
|
|
477
|
+
return currentOffset < step.value * (childrenLength.value - 1);
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
return currentOffset > 0;
|
|
481
|
+
}
|
|
492
482
|
}
|
|
493
483
|
else {
|
|
494
|
-
|
|
495
|
-
return {
|
|
496
|
-
targetOffset: gestureMovePos < 0 ? 0 : offset.value + translation,
|
|
497
|
-
canMove: currentOffset > 0
|
|
498
|
-
};
|
|
484
|
+
return true;
|
|
499
485
|
}
|
|
500
486
|
}
|
|
501
487
|
function handleEnd(eventData) {
|
|
@@ -555,7 +541,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
555
541
|
}
|
|
556
542
|
});
|
|
557
543
|
}
|
|
558
|
-
function
|
|
544
|
+
function handleLongPress() {
|
|
559
545
|
'worklet';
|
|
560
546
|
const currentOffset = Math.abs(offset.value);
|
|
561
547
|
let preOffset = (currentIndex.value + patchElmNumShared.value) * step.value;
|
|
@@ -565,14 +551,6 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
565
551
|
// 正常事件中拿到的transition值(正向滑动<0,倒着滑>0)
|
|
566
552
|
const diffOffset = preOffset - currentOffset;
|
|
567
553
|
const half = Math.abs(diffOffset) > step.value / 2;
|
|
568
|
-
return {
|
|
569
|
-
diffOffset,
|
|
570
|
-
half
|
|
571
|
-
};
|
|
572
|
-
}
|
|
573
|
-
function handleLongPress() {
|
|
574
|
-
'worklet';
|
|
575
|
-
const { diffOffset, half } = computeHalf();
|
|
576
554
|
if (+diffOffset === 0) {
|
|
577
555
|
runOnJS(resumeLoop)();
|
|
578
556
|
}
|
|
@@ -632,30 +610,19 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
632
610
|
runOnJS(pauseLoop)();
|
|
633
611
|
preAbsolutePos.value = e[strAbso];
|
|
634
612
|
moveTranstion.value = e[strAbso];
|
|
635
|
-
anotherDirectionMove.value = e[anotherAbso];
|
|
636
613
|
moveTime.value = new Date().getTime();
|
|
637
614
|
})
|
|
638
|
-
.
|
|
615
|
+
.onTouchesMove((e) => {
|
|
639
616
|
'worklet';
|
|
640
617
|
if (touchfinish.value)
|
|
641
618
|
return;
|
|
642
|
-
const
|
|
619
|
+
const touchEventData = e.changedTouches[0];
|
|
620
|
+
const moveDistance = touchEventData[strAbso] - preAbsolutePos.value;
|
|
643
621
|
const eventData = {
|
|
644
622
|
translation: moveDistance
|
|
645
623
|
};
|
|
646
|
-
//
|
|
647
|
-
|
|
648
|
-
if (half) {
|
|
649
|
-
const { selectedIndex } = getTargetPosition(eventData);
|
|
650
|
-
currentIndex.value = selectedIndex;
|
|
651
|
-
}
|
|
652
|
-
// 2. 处理用户一直拖拽到临界点的场景, 不会执行onEnd
|
|
653
|
-
const { canMove, targetOffset } = checkUnCircular(eventData);
|
|
654
|
-
if (!circularShared.value) {
|
|
655
|
-
if (canMove) {
|
|
656
|
-
offset.value = targetOffset;
|
|
657
|
-
preAbsolutePos.value = e[strAbso];
|
|
658
|
-
}
|
|
624
|
+
// 处理用户一直拖拽到临界点的场景, 不会执行onEnd
|
|
625
|
+
if (!circularShared.value && !canMove(eventData)) {
|
|
659
626
|
return;
|
|
660
627
|
}
|
|
661
628
|
const { isBoundary, resetOffset } = reachBoundary(eventData);
|
|
@@ -665,23 +632,30 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
665
632
|
else {
|
|
666
633
|
offset.value = moveDistance + offset.value;
|
|
667
634
|
}
|
|
668
|
-
preAbsolutePos.value =
|
|
635
|
+
preAbsolutePos.value = touchEventData[strAbso];
|
|
669
636
|
})
|
|
670
|
-
.
|
|
637
|
+
.onTouchesUp((e) => {
|
|
671
638
|
'worklet';
|
|
672
639
|
if (touchfinish.value)
|
|
673
640
|
return;
|
|
674
|
-
const
|
|
641
|
+
const touchEventData = e.changedTouches[0];
|
|
642
|
+
const moveDistance = touchEventData[strAbso] - moveTranstion.value;
|
|
675
643
|
touchfinish.value = true;
|
|
676
644
|
const eventData = {
|
|
677
645
|
translation: moveDistance
|
|
678
646
|
};
|
|
647
|
+
if (childrenLength.value === 1) {
|
|
648
|
+
return handleBackInit();
|
|
649
|
+
}
|
|
650
|
+
// 用户手指按下起来, 需要计算正确的位置, 比如在滑动过程中突然按下然后起来,需要计算到正确的位置
|
|
651
|
+
if (!circularShared.value && !canMove(eventData)) {
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
679
654
|
const strVelocity = moveDistance / (new Date().getTime() - moveTime.value) * 1000;
|
|
680
655
|
if (Math.abs(strVelocity) < longPressRatio) {
|
|
681
656
|
handleLongPress();
|
|
682
657
|
}
|
|
683
658
|
else {
|
|
684
|
-
// 如果触发了onTouchesCancelled,不会触发onUpdate不会更新offset值, 索引不会变更
|
|
685
659
|
handleEnd(eventData);
|
|
686
660
|
}
|
|
687
661
|
})
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { forwardRef, useRef, useContext, useMemo, useState } from 'react';
|
|
2
2
|
import { warn, isFunction } from '@mpxjs/utils';
|
|
3
3
|
import Portal from './mpx-portal/index';
|
|
4
|
+
import { usePreventRemove } from '@react-navigation/native';
|
|
4
5
|
import { getCustomEvent } from './getInnerListeners';
|
|
5
6
|
import { promisify, redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy';
|
|
6
7
|
import { WebView } from 'react-native-webview';
|
|
@@ -55,8 +56,8 @@ const _WebView = forwardRef((props, ref) => {
|
|
|
55
56
|
const webViewRef = useRef(null);
|
|
56
57
|
const fristLoaded = useRef(false);
|
|
57
58
|
const isLoadError = useRef(false);
|
|
59
|
+
const isNavigateBack = useRef(false);
|
|
58
60
|
const statusCode = useRef('');
|
|
59
|
-
const [isLoaded, setIsLoaded] = useState(true);
|
|
60
61
|
const defaultWebViewStyle = {
|
|
61
62
|
position: 'absolute',
|
|
62
63
|
left: 0,
|
|
@@ -64,27 +65,18 @@ const _WebView = forwardRef((props, ref) => {
|
|
|
64
65
|
top: 0,
|
|
65
66
|
bottom: 0
|
|
66
67
|
};
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
const navigation = useNavigation();
|
|
69
|
+
const [isIntercept, setIsIntercept] = useState(false);
|
|
70
|
+
usePreventRemove(isIntercept, (event) => {
|
|
71
|
+
const { data } = event;
|
|
72
|
+
if (isNavigateBack.current) {
|
|
73
|
+
navigation?.dispatch(data.action);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
71
76
|
webViewRef.current?.goBack();
|
|
72
|
-
e.preventDefault();
|
|
73
77
|
}
|
|
74
78
|
isNavigateBack.current = false;
|
|
75
|
-
};
|
|
76
|
-
const navigation = useNavigation();
|
|
77
|
-
// useEffect(() => {
|
|
78
|
-
// let beforeRemoveSubscription:any
|
|
79
|
-
// if (__mpx_mode__ !== 'ios') {
|
|
80
|
-
// beforeRemoveSubscription = navigation?.addListener?.('beforeRemove', beforeRemoveHandle)
|
|
81
|
-
// }
|
|
82
|
-
// return () => {
|
|
83
|
-
// if (isFunction(beforeRemoveSubscription)) {
|
|
84
|
-
// beforeRemoveSubscription()
|
|
85
|
-
// }
|
|
86
|
-
// }
|
|
87
|
-
// }, [])
|
|
79
|
+
});
|
|
88
80
|
useNodesRef(props, ref, webViewRef, {
|
|
89
81
|
style: defaultWebViewStyle
|
|
90
82
|
});
|
|
@@ -131,13 +123,13 @@ const _WebView = forwardRef((props, ref) => {
|
|
|
131
123
|
};
|
|
132
124
|
const _changeUrl = function (navState) {
|
|
133
125
|
if (navState.navigationType) { // navigationType这个事件在页面开始加载时和页面加载完成时都会被触发所以判断这个避免其他无效触发执行该逻辑
|
|
134
|
-
canGoBack.current = navState.canGoBack;
|
|
135
126
|
currentPage.__webViewUrl = navState.url;
|
|
127
|
+
setIsIntercept(navState.canGoBack);
|
|
136
128
|
}
|
|
137
129
|
};
|
|
138
130
|
const _onLoadProgress = function (event) {
|
|
139
131
|
if (__mpx_mode__ !== 'ios') {
|
|
140
|
-
|
|
132
|
+
setIsIntercept(event.nativeEvent.canGoBack);
|
|
141
133
|
}
|
|
142
134
|
};
|
|
143
135
|
const _message = function (res) {
|
|
@@ -227,7 +219,6 @@ const _WebView = forwardRef((props, ref) => {
|
|
|
227
219
|
};
|
|
228
220
|
const onLoadEndHandle = function (res) {
|
|
229
221
|
fristLoaded.current = true;
|
|
230
|
-
setIsLoaded(true);
|
|
231
222
|
const src = res.nativeEvent?.url;
|
|
232
223
|
if (isLoadError.current) {
|
|
233
224
|
isLoadError.current = false;
|
|
@@ -275,18 +266,13 @@ const _WebView = forwardRef((props, ref) => {
|
|
|
275
266
|
setPageLoadErr(true);
|
|
276
267
|
}
|
|
277
268
|
};
|
|
278
|
-
const onLoadStart = function () {
|
|
279
|
-
if (!fristLoaded.current) {
|
|
280
|
-
setIsLoaded(false);
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
269
|
return (<Portal>
|
|
284
270
|
{pageLoadErr
|
|
285
271
|
? (<View style={[styles.loadErrorContext, defaultWebViewStyle]}>
|
|
286
272
|
<View style={styles.loadErrorText}><Text style={{ fontSize: 14, color: '#999999' }}>{currentErrorText.text}</Text></View>
|
|
287
273
|
<View style={styles.loadErrorButton} onTouchEnd={_reload}><Text style={{ fontSize: 12, color: '#666666' }}>{currentErrorText.button}</Text></View>
|
|
288
274
|
</View>)
|
|
289
|
-
: (<WebView style={defaultWebViewStyle}
|
|
275
|
+
: (<WebView style={defaultWebViewStyle} source={{ uri: src }} ref={webViewRef} javaScriptEnabled={true} onNavigationStateChange={_changeUrl} onMessage={_message} injectedJavaScript={injectedJavaScript} onLoadProgress={_onLoadProgress} onLoadEnd={onLoadEnd} onHttpError={onHttpError} onError={onError} allowsBackForwardNavigationGestures={true}></WebView>)}
|
|
290
276
|
</Portal>);
|
|
291
277
|
});
|
|
292
278
|
_WebView.displayName = 'MpxWebview';
|
|
@@ -48,90 +48,6 @@ const InitialValue = Object.assign({
|
|
|
48
48
|
const TransformOrigin = 'transformOrigin';
|
|
49
49
|
// transform
|
|
50
50
|
const isTransform = (key) => Object.keys(TransformInitial).includes(key);
|
|
51
|
-
// 多value解析
|
|
52
|
-
const parseValues = (str, char = ' ') => {
|
|
53
|
-
let stack = 0;
|
|
54
|
-
let temp = '';
|
|
55
|
-
const result = [];
|
|
56
|
-
for (let i = 0; i < str.length; i++) {
|
|
57
|
-
if (str[i] === '(') {
|
|
58
|
-
stack++;
|
|
59
|
-
}
|
|
60
|
-
else if (str[i] === ')') {
|
|
61
|
-
stack--;
|
|
62
|
-
}
|
|
63
|
-
// 非括号内 或者 非分隔字符且非空
|
|
64
|
-
if (stack !== 0 || (str[i] !== char && str[i] !== ' ')) {
|
|
65
|
-
temp += str[i];
|
|
66
|
-
}
|
|
67
|
-
if ((stack === 0 && str[i] === char) || i === str.length - 1) {
|
|
68
|
-
result.push(temp);
|
|
69
|
-
temp = '';
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return result;
|
|
73
|
-
};
|
|
74
|
-
// parse string transform, eg: transform: 'rotateX(45deg) rotateZ(0.785398rad)'
|
|
75
|
-
const parseTransform = (transformStr) => {
|
|
76
|
-
const values = parseValues(transformStr);
|
|
77
|
-
const transform = [];
|
|
78
|
-
values.forEach(item => {
|
|
79
|
-
const match = item.match(/([/\w]+)\((.+)\)/);
|
|
80
|
-
if (match && match.length >= 3) {
|
|
81
|
-
let key = match[1];
|
|
82
|
-
const val = match[2];
|
|
83
|
-
switch (key) {
|
|
84
|
-
case 'translateX':
|
|
85
|
-
case 'translateY':
|
|
86
|
-
case 'scaleX':
|
|
87
|
-
case 'scaleY':
|
|
88
|
-
case 'rotateX':
|
|
89
|
-
case 'rotateY':
|
|
90
|
-
case 'rotateZ':
|
|
91
|
-
case 'rotate':
|
|
92
|
-
case 'skewX':
|
|
93
|
-
case 'skewY':
|
|
94
|
-
case 'perspective':
|
|
95
|
-
// rotate 处理成 rotateZ
|
|
96
|
-
key = key === 'rotate' ? 'rotateZ' : key;
|
|
97
|
-
// 单个值处理
|
|
98
|
-
transform.push({ [key]: global.__formatValue(val) });
|
|
99
|
-
break;
|
|
100
|
-
case 'matrix':
|
|
101
|
-
transform.push({ [key]: parseValues(val, ',').map(val => +val) });
|
|
102
|
-
break;
|
|
103
|
-
case 'translate':
|
|
104
|
-
case 'scale':
|
|
105
|
-
case 'skew':
|
|
106
|
-
case 'translate3d': // x y 支持 z不支持
|
|
107
|
-
case 'scale3d': // x y 支持 z不支持
|
|
108
|
-
{
|
|
109
|
-
// 2 个以上的值处理
|
|
110
|
-
key = key.replace('3d', '');
|
|
111
|
-
const vals = parseValues(val, ',').splice(0, 3);
|
|
112
|
-
// scale(.5) === scaleX(.5) scaleY(.5)
|
|
113
|
-
if (vals.length === 1 && key === 'scale') {
|
|
114
|
-
vals.push(vals[0]);
|
|
115
|
-
}
|
|
116
|
-
const xyz = ['X', 'Y', 'Z'];
|
|
117
|
-
transform.push(...vals.map((v, index) => {
|
|
118
|
-
return { [`${key}${xyz[index] || ''}`]: global.__formatValue(v.trim()) };
|
|
119
|
-
}));
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
return transform;
|
|
126
|
-
};
|
|
127
|
-
// format style
|
|
128
|
-
const formatStyle = (style) => {
|
|
129
|
-
if (!style.transform || Array.isArray(style.transform))
|
|
130
|
-
return style;
|
|
131
|
-
return Object.assign({}, style, {
|
|
132
|
-
transform: parseTransform(style.transform)
|
|
133
|
-
});
|
|
134
|
-
};
|
|
135
51
|
// transform 数组转对象
|
|
136
52
|
function getTransformObj(transforms) {
|
|
137
53
|
'worklet';
|
|
@@ -140,7 +56,7 @@ function getTransformObj(transforms) {
|
|
|
140
56
|
}, {});
|
|
141
57
|
}
|
|
142
58
|
export default function useAnimationHooks(props) {
|
|
143
|
-
const { style = {}, animation, enableAnimation, transitionend, layoutRef } = props;
|
|
59
|
+
const { style: originalStyle = {}, animation, enableAnimation, transitionend, layoutRef } = props;
|
|
144
60
|
const enableStyleAnimation = enableAnimation || !!animation;
|
|
145
61
|
const enableAnimationRef = useRef(enableStyleAnimation);
|
|
146
62
|
if (enableAnimationRef.current !== enableStyleAnimation) {
|
|
@@ -148,7 +64,6 @@ export default function useAnimationHooks(props) {
|
|
|
148
64
|
}
|
|
149
65
|
if (!enableAnimationRef.current)
|
|
150
66
|
return { enableStyleAnimation: false };
|
|
151
|
-
const originalStyle = formatStyle(style);
|
|
152
67
|
// id 标识
|
|
153
68
|
const id = animation?.id || -1;
|
|
154
69
|
// 有动画样式的 style key
|
|
@@ -177,7 +92,7 @@ export default function useAnimationHooks(props) {
|
|
|
177
92
|
useEffect(() => {
|
|
178
93
|
// style 更新后同步更新 lastStyleRef & shareValMap
|
|
179
94
|
updateStyleVal();
|
|
180
|
-
}, [
|
|
95
|
+
}, [originalStyle]);
|
|
181
96
|
// ** 获取动画样式prop & 驱动动画
|
|
182
97
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
183
98
|
useEffect(() => {
|
|
@@ -24,7 +24,7 @@ const getTouchEvent = (
|
|
|
24
24
|
) => {
|
|
25
25
|
const { navigation, propsRef, layoutRef } = config
|
|
26
26
|
const props = propsRef.current
|
|
27
|
-
const {
|
|
27
|
+
const { top: navigationY = 0 } = navigation?.layout || {}
|
|
28
28
|
const nativeEvent = event.nativeEvent
|
|
29
29
|
const { timestamp, pageX, pageY, touches, changedTouches } = nativeEvent
|
|
30
30
|
const { id } = props
|
|
@@ -42,8 +42,7 @@ import {
|
|
|
42
42
|
TextStyle,
|
|
43
43
|
Animated,
|
|
44
44
|
Easing,
|
|
45
|
-
NativeSyntheticEvent
|
|
46
|
-
useAnimatedValue
|
|
45
|
+
NativeSyntheticEvent
|
|
47
46
|
} from 'react-native'
|
|
48
47
|
import { warn } from '@mpxjs/utils'
|
|
49
48
|
import { GestureDetector, PanGesture } from 'react-native-gesture-handler'
|
|
@@ -158,7 +157,7 @@ const timer = (data: any, time = 3000) => new Promise((resolve) => {
|
|
|
158
157
|
})
|
|
159
158
|
|
|
160
159
|
const Loading = ({ alone = false }: { alone: boolean }): JSX.Element => {
|
|
161
|
-
const image =
|
|
160
|
+
const image = useRef(new Animated.Value(0)).current
|
|
162
161
|
|
|
163
162
|
const rotate = image.interpolate({
|
|
164
163
|
inputRange: [0, 1],
|