@mpxjs/webpack-plugin 2.10.14-beta.1 → 2.10.14-beta.11
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 +69 -48
- 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 +48 -39
- 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 +1 -1
- 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 +78 -47
- 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 +48 -37
- package/lib/runtime/components/react/mpx-view.tsx +1 -1
- 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 +1 -1
- package/lib/dependencies/ImportDependencyTemplate.js +0 -50
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
* ✔ nodes
|
|
4
|
+
*/
|
|
5
|
+
import { View, ViewProps, ViewStyle } from 'react-native';
|
|
6
|
+
import { HandlerRef } from '../useNodesRef';
|
|
7
|
+
type Node = {
|
|
8
|
+
type: 'node' | 'text';
|
|
9
|
+
name?: string;
|
|
10
|
+
attrs?: any;
|
|
11
|
+
children?: Array<Node>;
|
|
12
|
+
text: string;
|
|
13
|
+
};
|
|
14
|
+
interface _RichTextProps extends ViewProps {
|
|
15
|
+
style?: ViewStyle;
|
|
16
|
+
nodes: string | Array<Node>;
|
|
17
|
+
'enable-var'?: boolean;
|
|
18
|
+
'external-var-context'?: Record<string, any>;
|
|
19
|
+
'parent-font-size'?: number;
|
|
20
|
+
'parent-width'?: number;
|
|
21
|
+
'parent-height'?: number;
|
|
22
|
+
}
|
|
23
|
+
declare const _RichText: import("react").ForwardRefExoticComponent<_RichTextProps & import("react").RefAttributes<HandlerRef<View, _RichTextProps>>>;
|
|
24
|
+
export default _RichText;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ✔ enable
|
|
3
|
+
*/
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
interface RootPortalProps {
|
|
6
|
+
enable?: boolean;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
[x: string]: any;
|
|
9
|
+
}
|
|
10
|
+
declare const _RootPortal: {
|
|
11
|
+
(props: RootPortalProps): import("react").FunctionComponentElement<import("./mpx-portal/index").PortalProps>;
|
|
12
|
+
displayName: string;
|
|
13
|
+
};
|
|
14
|
+
export default _RootPortal;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { View, NativeSyntheticEvent, NativeScrollEvent, ViewStyle } from 'react-native';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { HandlerRef } from './useNodesRef';
|
|
4
|
+
import { GestureHandler } from './utils';
|
|
5
|
+
interface ScrollViewProps {
|
|
6
|
+
children?: ReactNode;
|
|
7
|
+
enhanced?: boolean;
|
|
8
|
+
bounces?: boolean;
|
|
9
|
+
style?: ViewStyle;
|
|
10
|
+
'scroll-x'?: boolean;
|
|
11
|
+
'scroll-y'?: boolean;
|
|
12
|
+
'enable-back-to-top'?: boolean;
|
|
13
|
+
'show-scrollbar'?: boolean;
|
|
14
|
+
'paging-enabled'?: boolean;
|
|
15
|
+
'upper-threshold'?: number;
|
|
16
|
+
'lower-threshold'?: number;
|
|
17
|
+
'scroll-with-animation'?: boolean;
|
|
18
|
+
'refresher-triggered'?: boolean;
|
|
19
|
+
'refresher-enabled'?: boolean;
|
|
20
|
+
'refresher-default-style'?: 'black' | 'white' | 'none';
|
|
21
|
+
'refresher-background'?: string;
|
|
22
|
+
'refresher-threshold'?: number;
|
|
23
|
+
'scroll-top'?: number;
|
|
24
|
+
'scroll-left'?: number;
|
|
25
|
+
'enable-offset'?: boolean;
|
|
26
|
+
'scroll-into-view'?: string;
|
|
27
|
+
'enable-trigger-intersection-observer'?: boolean;
|
|
28
|
+
'enable-var'?: boolean;
|
|
29
|
+
'external-var-context'?: Record<string, any>;
|
|
30
|
+
'parent-font-size'?: number;
|
|
31
|
+
'parent-width'?: number;
|
|
32
|
+
'parent-height'?: number;
|
|
33
|
+
'enable-sticky'?: boolean;
|
|
34
|
+
'wait-for'?: Array<GestureHandler>;
|
|
35
|
+
'simultaneous-handlers'?: Array<GestureHandler>;
|
|
36
|
+
'scroll-event-throttle'?: number;
|
|
37
|
+
'scroll-into-view-offset'?: number;
|
|
38
|
+
bindscrolltoupper?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
39
|
+
bindscrolltolower?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
40
|
+
bindscroll?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
41
|
+
bindrefresherrefresh?: (event: NativeSyntheticEvent<unknown>) => void;
|
|
42
|
+
binddragstart?: (event: NativeSyntheticEvent<DragEvent>) => void;
|
|
43
|
+
binddragging?: (event: NativeSyntheticEvent<DragEvent>) => void;
|
|
44
|
+
binddragend?: (event: NativeSyntheticEvent<DragEvent>) => void;
|
|
45
|
+
bindtouchstart?: (event: NativeSyntheticEvent<TouchEvent>) => void;
|
|
46
|
+
bindtouchmove?: (event: NativeSyntheticEvent<TouchEvent>) => void;
|
|
47
|
+
bindtouchend?: (event: NativeSyntheticEvent<TouchEvent>) => void;
|
|
48
|
+
bindscrollend?: (event: NativeSyntheticEvent<TouchEvent>) => void;
|
|
49
|
+
__selectRef?: (selector: string, nodeType: 'node' | 'component', all?: boolean) => HandlerRef<any, any>;
|
|
50
|
+
}
|
|
51
|
+
declare const _ScrollView: import("react").ForwardRefExoticComponent<ScrollViewProps & import("react").RefAttributes<HandlerRef<import("react").ForwardRefExoticComponent<import("react-native").ScrollViewProps & {
|
|
52
|
+
children?: ReactNode;
|
|
53
|
+
} & import("react-native-gesture-handler").NativeViewGestureHandlerProps & import("react").RefAttributes<import("react").ComponentType<any>>> & import("react-native").ScrollView & View, ScrollViewProps>>>;
|
|
54
|
+
export default _ScrollView;
|
|
@@ -38,7 +38,7 @@ import Animated, { useSharedValue, withTiming, useAnimatedStyle, runOnJS } from
|
|
|
38
38
|
import { warn, hasOwn } from '@mpxjs/utils';
|
|
39
39
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
40
40
|
import useNodesRef from './useNodesRef';
|
|
41
|
-
import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture, HIDDEN_STYLE } from './utils';
|
|
41
|
+
import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture, HIDDEN_STYLE, useRunOnJSCallback } from './utils';
|
|
42
42
|
import { IntersectionObserverContext, ScrollViewContext } from './context';
|
|
43
43
|
import Portal from './mpx-portal';
|
|
44
44
|
const AnimatedScrollView = RNAnimated.createAnimatedComponent(ScrollView);
|
|
@@ -79,6 +79,23 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
79
79
|
const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, hasPositionFixed, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
80
80
|
const { textStyle, innerStyle = {} } = splitStyle(normalStyle);
|
|
81
81
|
const scrollViewRef = useRef(null);
|
|
82
|
+
const propsRef = useRef(props);
|
|
83
|
+
const refresherStateRef = useRef({
|
|
84
|
+
hasRefresher,
|
|
85
|
+
refresherTriggered
|
|
86
|
+
});
|
|
87
|
+
propsRef.current = props;
|
|
88
|
+
refresherStateRef.current = {
|
|
89
|
+
hasRefresher,
|
|
90
|
+
refresherTriggered
|
|
91
|
+
};
|
|
92
|
+
const runOnJSCallbackRef = useRef({
|
|
93
|
+
setEnableScroll,
|
|
94
|
+
setScrollBounces,
|
|
95
|
+
setRefreshing,
|
|
96
|
+
onRefresh
|
|
97
|
+
});
|
|
98
|
+
const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef);
|
|
82
99
|
useNodesRef(props, ref, scrollViewRef, {
|
|
83
100
|
style: normalStyle,
|
|
84
101
|
scrollOffset: scrollOptions,
|
|
@@ -343,6 +360,7 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
343
360
|
}
|
|
344
361
|
// 处理刷新
|
|
345
362
|
function onRefresh() {
|
|
363
|
+
const { hasRefresher, refresherTriggered } = refresherStateRef.current;
|
|
346
364
|
if (hasRefresher && refresherTriggered === undefined) {
|
|
347
365
|
// 处理使用了自定义刷新组件,又没设置 refresherTriggered 的情况
|
|
348
366
|
setRefreshing(true);
|
|
@@ -354,9 +372,9 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
354
372
|
}
|
|
355
373
|
}, 500);
|
|
356
374
|
}
|
|
357
|
-
const { bindrefresherrefresh } =
|
|
375
|
+
const { bindrefresherrefresh } = propsRef.current;
|
|
358
376
|
bindrefresherrefresh &&
|
|
359
|
-
bindrefresherrefresh(getCustomEvent('refresherrefresh', {}, { layoutRef },
|
|
377
|
+
bindrefresherrefresh(getCustomEvent('refresherrefresh', {}, { layoutRef }, propsRef.current));
|
|
360
378
|
}
|
|
361
379
|
function getRefresherContent(children) {
|
|
362
380
|
let refresherContent = null;
|
|
@@ -404,7 +422,7 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
404
422
|
'worklet';
|
|
405
423
|
if (enableScrollValue.value !== newValue) {
|
|
406
424
|
enableScrollValue.value = newValue;
|
|
407
|
-
runOnJS(
|
|
425
|
+
runOnJS(runOnJSCallback)('setEnableScroll', newValue);
|
|
408
426
|
}
|
|
409
427
|
}
|
|
410
428
|
const resetScrollState = (value) => {
|
|
@@ -415,7 +433,7 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
415
433
|
'worklet';
|
|
416
434
|
if (bouncesValue.value !== newValue) {
|
|
417
435
|
bouncesValue.value = newValue;
|
|
418
|
-
runOnJS(
|
|
436
|
+
runOnJS(runOnJSCallback)('setScrollBounces', newValue);
|
|
419
437
|
}
|
|
420
438
|
}
|
|
421
439
|
// 处理下拉刷新的手势
|
|
@@ -460,7 +478,7 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
460
478
|
if ((event.translationY > 0 && translateY.value < refresherThreshold) || event.translationY < 0) {
|
|
461
479
|
translateY.value = withTiming(0);
|
|
462
480
|
updateScrollState(true);
|
|
463
|
-
runOnJS(
|
|
481
|
+
runOnJS(runOnJSCallback)('setRefreshing', false);
|
|
464
482
|
}
|
|
465
483
|
else {
|
|
466
484
|
translateY.value = withTiming(refresherHeight.value);
|
|
@@ -469,13 +487,13 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
469
487
|
else if (event.translationY >= refresherHeight.value) {
|
|
470
488
|
// 触发刷新
|
|
471
489
|
translateY.value = withTiming(refresherHeight.value);
|
|
472
|
-
runOnJS(
|
|
490
|
+
runOnJS(runOnJSCallback)('onRefresh');
|
|
473
491
|
}
|
|
474
492
|
else {
|
|
475
493
|
// 回弹
|
|
476
494
|
translateY.value = withTiming(0);
|
|
477
495
|
updateScrollState(true);
|
|
478
|
-
runOnJS(
|
|
496
|
+
runOnJS(runOnJSCallback)('setRefreshing', false);
|
|
479
497
|
}
|
|
480
498
|
})
|
|
481
499
|
.simultaneousWithExternalGesture(scrollViewRef);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { View, NativeSyntheticEvent, ViewStyle } from 'react-native';
|
|
3
|
+
import { HandlerRef } from './useNodesRef';
|
|
4
|
+
interface StickyHeaderProps {
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
style?: ViewStyle;
|
|
7
|
+
padding?: [number, number, number, number];
|
|
8
|
+
'offset-top'?: number;
|
|
9
|
+
'enable-var'?: boolean;
|
|
10
|
+
'external-var-context'?: Record<string, any>;
|
|
11
|
+
'parent-font-size'?: number;
|
|
12
|
+
'parent-width'?: number;
|
|
13
|
+
'parent-height'?: number;
|
|
14
|
+
bindstickontopchange?: (e: NativeSyntheticEvent<unknown>) => void;
|
|
15
|
+
}
|
|
16
|
+
declare const _StickyHeader: import("react").ForwardRefExoticComponent<StickyHeaderProps & import("react").RefAttributes<HandlerRef<View, StickyHeaderProps>>>;
|
|
17
|
+
export default _StickyHeader;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { View, ViewStyle } from 'react-native';
|
|
3
|
+
import { HandlerRef } from './useNodesRef';
|
|
4
|
+
interface StickySectionProps {
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
style?: ViewStyle;
|
|
7
|
+
'offset-top'?: number;
|
|
8
|
+
'enable-var'?: boolean;
|
|
9
|
+
'external-var-context'?: Record<string, any>;
|
|
10
|
+
'parent-font-size'?: number;
|
|
11
|
+
'parent-width'?: number;
|
|
12
|
+
'parent-height'?: number;
|
|
13
|
+
}
|
|
14
|
+
declare const _StickySection: import("react").ForwardRefExoticComponent<StickySectionProps & import("react").RefAttributes<HandlerRef<View, StickySectionProps>>>;
|
|
15
|
+
export default _StickySection;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { View } from 'react-native';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { HandlerRef } from './useNodesRef';
|
|
4
|
+
interface SwiperItemProps {
|
|
5
|
+
'item-id'?: string;
|
|
6
|
+
'enable-offset'?: boolean;
|
|
7
|
+
'enable-var': boolean;
|
|
8
|
+
'external-var-context'?: Record<string, any>;
|
|
9
|
+
'parent-font-size'?: number;
|
|
10
|
+
'parent-width'?: number;
|
|
11
|
+
'parent-height'?: number;
|
|
12
|
+
children?: ReactNode;
|
|
13
|
+
style?: Object;
|
|
14
|
+
customStyle: Object;
|
|
15
|
+
itemIndex: number;
|
|
16
|
+
}
|
|
17
|
+
declare const _SwiperItem: import("react").ForwardRefExoticComponent<SwiperItemProps & import("react").RefAttributes<HandlerRef<View, SwiperItemProps>>>;
|
|
18
|
+
export default _SwiperItem;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { View, NativeSyntheticEvent } from 'react-native';
|
|
2
|
+
import React, { ReactNode } from 'react';
|
|
3
|
+
import { HandlerRef } from './useNodesRef';
|
|
4
|
+
import { GestureHandler } from './utils';
|
|
5
|
+
/**
|
|
6
|
+
* ✔ indicator-dots
|
|
7
|
+
* ✔ indicator-color
|
|
8
|
+
* ✔ indicator-active-color
|
|
9
|
+
* ✔ autoplay
|
|
10
|
+
* ✔ current
|
|
11
|
+
* ✔ interval
|
|
12
|
+
* ✔ duration
|
|
13
|
+
* ✔ circular
|
|
14
|
+
* ✔ vertical
|
|
15
|
+
* ✔ previous-margin
|
|
16
|
+
* ✔ next-margin
|
|
17
|
+
* ✔ easing-function ="easeOutCubic"
|
|
18
|
+
* ✘ display-multiple-items
|
|
19
|
+
* ✘ snap-to-edge
|
|
20
|
+
*/
|
|
21
|
+
type EaseType = 'default' | 'linear' | 'easeInCubic' | 'easeOutCubic' | 'easeInOutCubic';
|
|
22
|
+
interface SwiperProps {
|
|
23
|
+
children?: ReactNode;
|
|
24
|
+
circular?: boolean;
|
|
25
|
+
current?: number;
|
|
26
|
+
interval?: number;
|
|
27
|
+
autoplay?: boolean;
|
|
28
|
+
duration?: number;
|
|
29
|
+
scale?: boolean;
|
|
30
|
+
'indicator-dots'?: boolean;
|
|
31
|
+
'indicator-color'?: string;
|
|
32
|
+
'indicator-active-color'?: string;
|
|
33
|
+
vertical?: boolean;
|
|
34
|
+
style: {
|
|
35
|
+
[key: string]: any;
|
|
36
|
+
};
|
|
37
|
+
'easing-function'?: EaseType;
|
|
38
|
+
'previous-margin'?: string;
|
|
39
|
+
'next-margin'?: string;
|
|
40
|
+
'enable-offset'?: boolean;
|
|
41
|
+
'enable-var': boolean;
|
|
42
|
+
'parent-font-size'?: number;
|
|
43
|
+
'parent-width'?: number;
|
|
44
|
+
'parent-height'?: number;
|
|
45
|
+
'external-var-context'?: Record<string, any>;
|
|
46
|
+
'wait-for'?: Array<GestureHandler>;
|
|
47
|
+
'simultaneous-handlers'?: Array<GestureHandler>;
|
|
48
|
+
disableGesture?: boolean;
|
|
49
|
+
bindchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void;
|
|
50
|
+
}
|
|
51
|
+
declare const SwiperWrapper: React.ForwardRefExoticComponent<SwiperProps & React.RefAttributes<HandlerRef<View, SwiperProps>>>;
|
|
52
|
+
export default SwiperWrapper;
|
|
@@ -4,7 +4,7 @@ import Animated, { useAnimatedStyle, useSharedValue, withTiming, Easing, runOnJS
|
|
|
4
4
|
import React, { forwardRef, useRef, useEffect, useMemo, createElement } from 'react';
|
|
5
5
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
6
6
|
import useNodesRef from './useNodesRef'; // 引入辅助函数
|
|
7
|
-
import { useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren, extendObject, flatGesture } from './utils';
|
|
7
|
+
import { useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren, extendObject, flatGesture, useRunOnJSCallback } from './utils';
|
|
8
8
|
import { SwiperContext } from './context';
|
|
9
9
|
import Portal from './mpx-portal';
|
|
10
10
|
/**
|
|
@@ -71,7 +71,7 @@ const easeMap = {
|
|
|
71
71
|
easeInOutCubic: Easing.inOut(Easing.cubic)
|
|
72
72
|
};
|
|
73
73
|
const SwiperWrapper = forwardRef((props, ref) => {
|
|
74
|
-
const { 'indicator-dots': showPagination, 'indicator-color': dotColor = 'rgba(0, 0, 0, .3)', 'indicator-active-color': activeDotColor = '#000000', 'enable-var': enableVar = false, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'external-var-context': externalVarContext, 'simultaneous-handlers': originSimultaneousHandlers = [], 'wait-for': waitFor = [], style = {}, autoplay = false, circular = false, disableGesture = false, bindchange } = props;
|
|
74
|
+
const { 'indicator-dots': showPagination, 'indicator-color': dotColor = 'rgba(0, 0, 0, .3)', 'indicator-active-color': activeDotColor = '#000000', 'enable-var': enableVar = false, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'external-var-context': externalVarContext, 'simultaneous-handlers': originSimultaneousHandlers = [], 'wait-for': waitFor = [], style = {}, autoplay = false, circular = false, disableGesture = false, current: propCurrent = 0, bindchange } = props;
|
|
75
75
|
const easeingFunc = props['easing-function'] || 'default';
|
|
76
76
|
const easeDuration = props.duration || 500;
|
|
77
77
|
const horizontal = props.vertical !== undefined ? !props.vertical : true;
|
|
@@ -112,14 +112,16 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
112
112
|
// 每个元素的宽度 or 高度,有固定值直接初始化无则0
|
|
113
113
|
const step = useSharedValue(initStep);
|
|
114
114
|
// 记录选中元素的索引值
|
|
115
|
-
const currentIndex = useSharedValue(
|
|
115
|
+
const currentIndex = useSharedValue(propCurrent);
|
|
116
116
|
// const initOffset = getOffset(props.current || 0, initStep)
|
|
117
117
|
// 记录元素的偏移量
|
|
118
|
-
const offset = useSharedValue(getOffset(
|
|
118
|
+
const offset = useSharedValue(getOffset(propCurrent, initStep));
|
|
119
119
|
const strAbso = 'absolute' + dir.toUpperCase();
|
|
120
120
|
const strVelocity = 'velocity' + dir.toUpperCase();
|
|
121
121
|
// 标识手指触摸和抬起, 起点在onBegin
|
|
122
122
|
const touchfinish = useSharedValue(true);
|
|
123
|
+
// 记录onUpdate时的方向,用于进行onFinalize中的值修正
|
|
124
|
+
const preUpdateTransDir = useSharedValue(0);
|
|
123
125
|
// 记录上一帧的绝对定位坐标
|
|
124
126
|
const preAbsolutePos = useSharedValue(0);
|
|
125
127
|
// 记录从onBegin 到 onTouchesUp 时移动的距离
|
|
@@ -170,7 +172,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
170
172
|
const iStep = dir === 'x' ? realWidth : realHeight;
|
|
171
173
|
if (iStep !== step.value) {
|
|
172
174
|
step.value = iStep;
|
|
173
|
-
updateCurrent(
|
|
175
|
+
updateCurrent(propCurrent, iStep);
|
|
174
176
|
updateAutoplay();
|
|
175
177
|
}
|
|
176
178
|
}
|
|
@@ -272,7 +274,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
272
274
|
easing: easeMap[easeingFunc]
|
|
273
275
|
}, () => {
|
|
274
276
|
currentIndex.value = nextIndex;
|
|
275
|
-
runOnJS(
|
|
277
|
+
runOnJS(runOnJSCallback)('loop');
|
|
276
278
|
});
|
|
277
279
|
}
|
|
278
280
|
else {
|
|
@@ -288,7 +290,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
288
290
|
// 将开始位置设置为真正的位置
|
|
289
291
|
offset.value = initOffset;
|
|
290
292
|
currentIndex.value = nextIndex;
|
|
291
|
-
runOnJS(
|
|
293
|
+
runOnJS(runOnJSCallback)('loop');
|
|
292
294
|
});
|
|
293
295
|
}
|
|
294
296
|
else {
|
|
@@ -300,7 +302,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
300
302
|
easing: easeMap[easeingFunc]
|
|
301
303
|
}, () => {
|
|
302
304
|
currentIndex.value = nextIndex;
|
|
303
|
-
runOnJS(
|
|
305
|
+
runOnJS(runOnJSCallback)('loop');
|
|
304
306
|
});
|
|
305
307
|
}
|
|
306
308
|
}
|
|
@@ -326,11 +328,16 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
326
328
|
};
|
|
327
329
|
}, []);
|
|
328
330
|
function handleSwiperChange(current) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
bindchange && bindchange(eventData);
|
|
332
|
-
}
|
|
331
|
+
const eventData = getCustomEvent('change', {}, { detail: { current, source: 'touch' }, layoutRef: layoutRef });
|
|
332
|
+
bindchange && bindchange(eventData);
|
|
333
333
|
}
|
|
334
|
+
const runOnJSCallbackRef = useRef({
|
|
335
|
+
loop,
|
|
336
|
+
pauseLoop,
|
|
337
|
+
resumeLoop,
|
|
338
|
+
handleSwiperChange
|
|
339
|
+
});
|
|
340
|
+
const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef);
|
|
334
341
|
function getOffset(index, stepValue) {
|
|
335
342
|
if (!stepValue)
|
|
336
343
|
return 0;
|
|
@@ -348,12 +355,12 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
348
355
|
const targetOffset = getOffset(index || 0, stepValue);
|
|
349
356
|
if (targetOffset !== offset.value) {
|
|
350
357
|
// 内部基于props.current!==currentIndex.value决定是否使用动画及更新currentIndex.value
|
|
351
|
-
if (
|
|
358
|
+
if (propCurrent !== undefined && propCurrent !== currentIndex.value) {
|
|
352
359
|
offset.value = withTiming(targetOffset, {
|
|
353
360
|
duration: easeDuration,
|
|
354
361
|
easing: easeMap[easeingFunc]
|
|
355
362
|
}, () => {
|
|
356
|
-
currentIndex.value =
|
|
363
|
+
currentIndex.value = propCurrent;
|
|
357
364
|
});
|
|
358
365
|
}
|
|
359
366
|
else {
|
|
@@ -372,8 +379,8 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
372
379
|
// 1. 用户在当前页切换选中项,动画;用户携带选中index打开到swiper页直接选中不走动画
|
|
373
380
|
useAnimatedReaction(() => currentIndex.value, (newIndex, preIndex) => {
|
|
374
381
|
// 这里必须传递函数名, 直接写()=> {}形式会报 访问了未sharedValue信息
|
|
375
|
-
if (newIndex !== preIndex && bindchange) {
|
|
376
|
-
runOnJS(
|
|
382
|
+
if (newIndex !== preIndex && preIndex !== null && preIndex !== undefined && bindchange) {
|
|
383
|
+
runOnJS(runOnJSCallback)('handleSwiperChange', newIndex, propCurrent);
|
|
377
384
|
}
|
|
378
385
|
});
|
|
379
386
|
useEffect(() => {
|
|
@@ -404,12 +411,12 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
404
411
|
}
|
|
405
412
|
}, [children.length]);
|
|
406
413
|
useEffect(() => {
|
|
407
|
-
// 1. 如果用户在touch的过程中, 外部更新了current
|
|
414
|
+
// 1. 如果用户在touch的过程中, 外部更新了current以内部为准(小程序表现)
|
|
408
415
|
// 2. 手指滑动过程中更新索引,外部会把current再传入进来,导致offset直接更新,增加判断不同才更新
|
|
409
|
-
if (
|
|
410
|
-
updateCurrent(
|
|
416
|
+
if (propCurrent !== currentIndex.value && touchfinish.value) {
|
|
417
|
+
updateCurrent(propCurrent, step.value);
|
|
411
418
|
}
|
|
412
|
-
}, [
|
|
419
|
+
}, [propCurrent]);
|
|
413
420
|
useEffect(() => {
|
|
414
421
|
autoplayShared.value = autoplay;
|
|
415
422
|
updateAutoplay();
|
|
@@ -502,7 +509,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
502
509
|
if (touchfinish.value !== false) {
|
|
503
510
|
currentIndex.value = selectedIndex;
|
|
504
511
|
offset.value = resetOffset;
|
|
505
|
-
runOnJS(
|
|
512
|
+
runOnJS(runOnJSCallback)('resumeLoop');
|
|
506
513
|
}
|
|
507
514
|
});
|
|
508
515
|
}
|
|
@@ -513,7 +520,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
513
520
|
}, () => {
|
|
514
521
|
if (touchfinish.value !== false) {
|
|
515
522
|
currentIndex.value = selectedIndex;
|
|
516
|
-
runOnJS(
|
|
523
|
+
runOnJS(runOnJSCallback)('resumeLoop');
|
|
517
524
|
}
|
|
518
525
|
});
|
|
519
526
|
}
|
|
@@ -535,7 +542,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
535
542
|
}, () => {
|
|
536
543
|
if (touchfinish.value !== false) {
|
|
537
544
|
currentIndex.value = moveToIndex;
|
|
538
|
-
runOnJS(
|
|
545
|
+
runOnJS(runOnJSCallback)('resumeLoop');
|
|
539
546
|
}
|
|
540
547
|
});
|
|
541
548
|
}
|
|
@@ -562,20 +569,11 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
562
569
|
'worklet';
|
|
563
570
|
const { diffOffset, half, isTriggerUpdateHalf } = computeHalf(eventData);
|
|
564
571
|
if (+diffOffset === 0) {
|
|
565
|
-
runOnJS(
|
|
572
|
+
runOnJS(runOnJSCallback)('resumeLoop');
|
|
566
573
|
}
|
|
567
574
|
else if (isTriggerUpdateHalf) {
|
|
568
|
-
// 如果触发了onUpdate
|
|
569
|
-
|
|
570
|
-
offset.value = withTiming(-targetIndex * step.value, {
|
|
571
|
-
duration: easeDuration,
|
|
572
|
-
easing: easeMap[easeingFunc]
|
|
573
|
-
}, () => {
|
|
574
|
-
if (touchfinish.value !== false) {
|
|
575
|
-
currentIndex.value = targetIndex;
|
|
576
|
-
runOnJS(resumeLoop)();
|
|
577
|
-
}
|
|
578
|
-
});
|
|
575
|
+
// 如果触发了onUpdate时的索引变更
|
|
576
|
+
handleEnd(eventData);
|
|
579
577
|
}
|
|
580
578
|
else if (half) {
|
|
581
579
|
handleEnd(eventData);
|
|
@@ -651,19 +649,20 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
651
649
|
return;
|
|
652
650
|
touchfinish.value = false;
|
|
653
651
|
cancelAnimation(offset);
|
|
654
|
-
runOnJS(
|
|
652
|
+
runOnJS(runOnJSCallback)('pauseLoop');
|
|
655
653
|
preAbsolutePos.value = e[strAbso];
|
|
656
654
|
moveTranstion.value = e[strAbso];
|
|
657
655
|
})
|
|
658
656
|
.onUpdate((e) => {
|
|
659
657
|
'worklet';
|
|
660
|
-
if (touchfinish.value)
|
|
661
|
-
return;
|
|
662
658
|
const moveDistance = e[strAbso] - preAbsolutePos.value;
|
|
659
|
+
if (touchfinish.value || moveDistance === 0)
|
|
660
|
+
return;
|
|
663
661
|
const eventData = {
|
|
664
662
|
translation: moveDistance,
|
|
665
663
|
transdir: moveDistance
|
|
666
664
|
};
|
|
665
|
+
preUpdateTransDir.value = moveDistance;
|
|
667
666
|
// 1. 支持滑动中超出一半更新索引的能力:只更新索引并不会影响onFinalize依据当前offset计算的索引
|
|
668
667
|
const { half } = computeHalf(eventData);
|
|
669
668
|
if (childrenLength.value > 1 && half) {
|
|
@@ -698,17 +697,27 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
698
697
|
offset.value = moveDistance + offset.value;
|
|
699
698
|
}
|
|
700
699
|
preAbsolutePos.value = e[strAbso];
|
|
700
|
+
})
|
|
701
|
+
.onEnd((e) => {
|
|
702
|
+
// 修复某些安卓机型小米 onFinalize拿到的absolute值不正确的问题, onUpdate并不是最终的值
|
|
703
|
+
preAbsolutePos.value = e[strAbso];
|
|
701
704
|
})
|
|
702
705
|
.onFinalize((e) => {
|
|
703
706
|
'worklet';
|
|
704
707
|
if (touchfinish.value)
|
|
705
708
|
return;
|
|
706
709
|
touchfinish.value = true;
|
|
710
|
+
/**
|
|
711
|
+
* 安卓修正
|
|
712
|
+
* 问题:部分安卓机型onFinalize中拿到的absoluteX 有问题
|
|
713
|
+
* 案例:比如手指从右向左滑的时候,onUpdate拿到的是241.64346313476562, 而onFinalize中拿到的是241.81817626953125,理论上onFinalize中应该比onUpdate小才对吧
|
|
714
|
+
* 解决方式:修正
|
|
715
|
+
*/
|
|
707
716
|
// 触发过onUpdate正常情况下e[strAbso] - preAbsolutePos.value=0; 未触发过onUpdate的情况下e[strAbso] - preAbsolutePos.value 不为0
|
|
708
717
|
const moveDistance = e[strAbso] - preAbsolutePos.value;
|
|
709
718
|
const eventData = {
|
|
710
719
|
translation: moveDistance,
|
|
711
|
-
transdir: moveDistance
|
|
720
|
+
transdir: Math.abs(moveDistance) > 1 ? moveDistance : preUpdateTransDir.value
|
|
712
721
|
};
|
|
713
722
|
// 1. 只有一个元素:循环 和 非循环状态,都走回弹效果
|
|
714
723
|
if (childrenLength.value === 1) {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
* ✔ checked
|
|
4
|
+
* ✔ type
|
|
5
|
+
* ✔ disabled
|
|
6
|
+
* ✔ color
|
|
7
|
+
*/
|
|
8
|
+
import { Switch, SwitchProps, ViewStyle, NativeSyntheticEvent } from 'react-native';
|
|
9
|
+
import { HandlerRef } from './useNodesRef';
|
|
10
|
+
interface _SwitchProps extends SwitchProps {
|
|
11
|
+
style?: ViewStyle;
|
|
12
|
+
name?: string;
|
|
13
|
+
checked?: boolean;
|
|
14
|
+
type: 'switch' | 'checkbox';
|
|
15
|
+
disabled: boolean;
|
|
16
|
+
color: string;
|
|
17
|
+
'enable-var'?: boolean;
|
|
18
|
+
'parent-font-size'?: number;
|
|
19
|
+
'parent-width'?: number;
|
|
20
|
+
'parent-height'?: number;
|
|
21
|
+
'external-var-context'?: Record<string, any>;
|
|
22
|
+
bindchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void;
|
|
23
|
+
catchchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void;
|
|
24
|
+
}
|
|
25
|
+
declare const _Switch: import("react").ForwardRefExoticComponent<_SwitchProps & import("react").RefAttributes<HandlerRef<Switch, _SwitchProps>>>;
|
|
26
|
+
export default _Switch;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ✔ selectable
|
|
3
|
+
* ✘ space
|
|
4
|
+
* ✘ decode
|
|
5
|
+
*/
|
|
6
|
+
import { Text, TextStyle, TextProps } from 'react-native';
|
|
7
|
+
import { ReactNode } from 'react';
|
|
8
|
+
import { HandlerRef } from './useNodesRef';
|
|
9
|
+
interface _TextProps extends TextProps {
|
|
10
|
+
style?: TextStyle;
|
|
11
|
+
children?: ReactNode;
|
|
12
|
+
selectable?: boolean;
|
|
13
|
+
'user-select'?: boolean;
|
|
14
|
+
'enable-var'?: boolean;
|
|
15
|
+
'external-var-context'?: Record<string, any>;
|
|
16
|
+
'parent-font-size'?: number;
|
|
17
|
+
'parent-width'?: number;
|
|
18
|
+
'parent-height'?: number;
|
|
19
|
+
}
|
|
20
|
+
declare const _Text: import("react").ForwardRefExoticComponent<_TextProps & import("react").RefAttributes<HandlerRef<Text, _TextProps>>>;
|
|
21
|
+
export default _Text;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { TextInput } from 'react-native';
|
|
3
|
+
import { InputProps, PrivateInputProps } from './mpx-input';
|
|
4
|
+
import { HandlerRef } from './useNodesRef';
|
|
5
|
+
export type TextareProps = Omit<InputProps & PrivateInputProps, 'type' | 'password' | 'multiline' | 'confirm-hold'>;
|
|
6
|
+
declare const Textarea: import("react").ForwardRefExoticComponent<TextareProps & import("react").RefAttributes<HandlerRef<TextInput, TextareProps>>>;
|
|
7
|
+
export default Textarea;
|