@mpxjs/webpack-plugin 2.10.17-beta.2 → 2.10.17-beta.4
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/config.js +60 -0
- package/lib/file-loader.js +4 -1
- package/lib/global.d.ts +16 -0
- package/lib/index.js +22 -2
- package/lib/json-compiler/index.js +13 -4
- package/lib/platform/json/wx/index.js +6 -0
- package/lib/platform/style/wx/index.js +57 -33
- package/lib/platform/template/wx/component-config/ad.js +5 -0
- package/lib/platform/template/wx/component-config/button.js +9 -2
- package/lib/platform/template/wx/component-config/camera.js +25 -3
- package/lib/platform/template/wx/component-config/canvas.js +8 -1
- package/lib/platform/template/wx/component-config/cover-image.js +7 -2
- package/lib/platform/template/wx/component-config/cover-view.js +3 -1
- package/lib/platform/template/wx/component-config/form.js +27 -2
- package/lib/platform/template/wx/component-config/image.js +5 -0
- package/lib/platform/template/wx/component-config/input.js +10 -0
- package/lib/platform/template/wx/component-config/label.js +10 -2
- package/lib/platform/template/wx/component-config/map.js +11 -0
- package/lib/platform/template/wx/component-config/movable-area.js +4 -1
- package/lib/platform/template/wx/component-config/movable-view.js +17 -2
- package/lib/platform/template/wx/component-config/navigator.js +26 -0
- package/lib/platform/template/wx/component-config/picker-view.js +12 -0
- package/lib/platform/template/wx/component-config/picker.js +3 -1
- package/lib/platform/template/wx/component-config/progress.js +11 -1
- package/lib/platform/template/wx/component-config/rich-text.js +5 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +12 -1
- package/lib/platform/template/wx/component-config/slider.js +8 -0
- package/lib/platform/template/wx/component-config/swiper-item.js +5 -2
- package/lib/platform/template/wx/component-config/swiper.js +10 -0
- package/lib/platform/template/wx/component-config/text.js +5 -0
- package/lib/platform/template/wx/component-config/textarea.js +19 -2
- package/lib/platform/template/wx/component-config/unsupported.js +10 -1
- package/lib/platform/template/wx/component-config/video.js +10 -0
- package/lib/platform/template/wx/index.js +21 -1
- package/lib/react/LoadAsyncChunkModule.js +1 -1
- package/lib/react/processStyles.js +21 -9
- package/lib/react/style-helper.js +76 -13
- package/lib/resolver/AddModePlugin.js +23 -8
- package/lib/runtime/components/react/animationHooks/index.ts +75 -0
- package/lib/runtime/components/react/animationHooks/useAnimationAPIHooks.ts +198 -0
- package/lib/runtime/components/react/animationHooks/useTransitionHooks.ts +297 -0
- package/lib/runtime/components/react/animationHooks/utils.ts +196 -0
- package/lib/runtime/components/react/context.ts +7 -1
- package/lib/runtime/components/react/dist/animationHooks/index.d.ts +16 -0
- package/lib/runtime/components/react/dist/animationHooks/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/animationHooks/index.js +67 -0
- package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts +4 -0
- package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.js +182 -0
- package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts +4 -0
- package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.js +274 -0
- package/lib/runtime/components/react/dist/animationHooks/utils.d.ts +110 -0
- package/lib/runtime/components/react/dist/animationHooks/utils.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/animationHooks/utils.js +150 -0
- package/lib/runtime/components/react/dist/context.d.ts +6 -1
- package/lib/runtime/components/react/dist/context.d.ts.map +1 -1
- package/lib/runtime/components/react/dist/mpx-camera.d.ts +32 -0
- package/lib/runtime/components/react/dist/mpx-camera.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-camera.jsx +236 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts +2 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts.map +1 -1
- package/lib/runtime/components/react/dist/mpx-input.jsx +21 -10
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +1 -1
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +3 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts +10 -0
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +1 -1
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +28 -16
- package/lib/runtime/components/react/dist/mpx-view.d.ts +3 -2
- package/lib/runtime/components/react/dist/mpx-view.d.ts.map +1 -1
- package/lib/runtime/components/react/dist/mpx-view.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
- package/lib/runtime/components/react/dist/utils.d.ts +1 -0
- package/lib/runtime/components/react/dist/utils.d.ts.map +1 -1
- package/lib/runtime/components/react/dist/utils.jsx +34 -13
- package/lib/runtime/components/react/mpx-camera.tsx +327 -0
- package/lib/runtime/components/react/mpx-input.tsx +26 -10
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +3 -0
- package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +2 -2
- package/lib/runtime/components/react/mpx-swiper.tsx +43 -15
- package/lib/runtime/components/react/mpx-view.tsx +4 -5
- package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
- package/lib/runtime/components/react/types/global.d.ts +1 -0
- package/lib/runtime/components/react/utils.tsx +34 -16
- package/lib/runtime/optionProcessor.js +5 -0
- package/lib/runtime/optionProcessorReact.js +7 -0
- package/lib/runtime/stringify.wxs +2 -2
- package/lib/style-compiler/strip-conditional-loader/rebaseUrl.js +225 -0
- package/lib/style-compiler/strip-conditional-loader.js +55 -180
- package/lib/template-compiler/compiler.js +1 -3
- package/lib/utils/dom-tag-config.js +1 -1
- package/lib/utils/string.js +25 -1
- package/package.json +2 -1
- package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +0 -33
- package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/useAnimationHooks.js +0 -289
- package/lib/runtime/components/react/useAnimationHooks.ts +0 -320
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Easing, withTiming, withDelay } from 'react-native-reanimated';
|
|
2
|
+
import { hasOwn } from '@mpxjs/utils';
|
|
3
|
+
// ms s 单位匹配
|
|
4
|
+
export const secondRegExp = /^\s*(\d*(?:\.\d+)?)(s|ms)?\s*$/;
|
|
5
|
+
export const cubicBezierExp = /cubic-bezier\(["']?(.*?)["']?\)/;
|
|
6
|
+
export const percentExp = /^((-?(\d+(\.\d+)?|\.\d+))%)$/;
|
|
7
|
+
// export const PropNameColorExp = /^c|Color$/
|
|
8
|
+
// export const NumberExp = /^((opacity|flex-grow|flex-shrink|gap|left|right|top|bottom)|(.+-(width|height|left|right|top|bottom|radius|spacing|size|gap|index|offset|opacity)))$/
|
|
9
|
+
// export const ColorExp = /^(color|(.+Color))$/
|
|
10
|
+
// transform
|
|
11
|
+
// export const transform = 'transform'
|
|
12
|
+
// export const transformOrigin = 'transformOrigin'
|
|
13
|
+
// export const transition = 'transition'
|
|
14
|
+
// 微信 timingFunction 和 RN Easing 对应关系
|
|
15
|
+
export const easingKey = {
|
|
16
|
+
linear: Easing.linear,
|
|
17
|
+
ease: Easing.inOut(Easing.ease),
|
|
18
|
+
'ease-in': Easing.in(Easing.poly(3)),
|
|
19
|
+
'ease-in-out': Easing.inOut(Easing.poly(3)),
|
|
20
|
+
'ease-out': Easing.out(Easing.poly(3))
|
|
21
|
+
// 'step-start': '',
|
|
22
|
+
// 'step-end': ''
|
|
23
|
+
};
|
|
24
|
+
export const transformInitial = {
|
|
25
|
+
// matrix: 0,
|
|
26
|
+
// matrix3d: 0,
|
|
27
|
+
// rotate: '0deg',
|
|
28
|
+
rotateX: '0deg',
|
|
29
|
+
rotateY: '0deg',
|
|
30
|
+
rotateZ: '0deg',
|
|
31
|
+
// rotate3d:[0,0,0]
|
|
32
|
+
// scale: 1,
|
|
33
|
+
// scale3d: [1, 1, 1],
|
|
34
|
+
scaleX: 1,
|
|
35
|
+
scaleY: 1,
|
|
36
|
+
// scaleZ: 1,
|
|
37
|
+
// skew: 0,
|
|
38
|
+
skewX: '0deg',
|
|
39
|
+
skewY: '0deg',
|
|
40
|
+
// translate: 0,
|
|
41
|
+
// translate3d: 0,
|
|
42
|
+
translateX: 0,
|
|
43
|
+
translateY: 0
|
|
44
|
+
// translateZ: 0,
|
|
45
|
+
};
|
|
46
|
+
// animation api 动画默认初始值
|
|
47
|
+
export const animationAPIInitialValue = Object.assign({
|
|
48
|
+
opacity: 1,
|
|
49
|
+
backgroundColor: 'transparent',
|
|
50
|
+
width: 0,
|
|
51
|
+
height: 0,
|
|
52
|
+
top: 0,
|
|
53
|
+
right: 0,
|
|
54
|
+
bottom: 0,
|
|
55
|
+
left: 0,
|
|
56
|
+
transformOrigin: ['50%', '50%', 0]
|
|
57
|
+
}, transformInitial);
|
|
58
|
+
// transition property
|
|
59
|
+
export const transitionSupportedProperty = Object.assign({
|
|
60
|
+
color: 'transparent',
|
|
61
|
+
borderColor: 'transparent',
|
|
62
|
+
borderBottomColor: 'transparent',
|
|
63
|
+
borderLeftColor: 'transparent',
|
|
64
|
+
borderRightColor: 'transparent',
|
|
65
|
+
borderTopColor: 'transparent',
|
|
66
|
+
borderTopLeftRadius: 0,
|
|
67
|
+
borderTopRightRadius: 0,
|
|
68
|
+
borderBottomLeftRadius: 0,
|
|
69
|
+
borderBottomRightRadius: 0,
|
|
70
|
+
borderRadius: 0,
|
|
71
|
+
borderBottomWidth: 0,
|
|
72
|
+
borderLeftWidth: 0,
|
|
73
|
+
borderRightWidth: 0,
|
|
74
|
+
borderTopWidth: 0,
|
|
75
|
+
borderWidth: 0,
|
|
76
|
+
margin: 0,
|
|
77
|
+
marginBottom: 0,
|
|
78
|
+
marginLeft: 0,
|
|
79
|
+
marginRight: 0,
|
|
80
|
+
marginTop: 0,
|
|
81
|
+
marginHorizontal: 0,
|
|
82
|
+
marginVertical: 0,
|
|
83
|
+
maxHeight: 0,
|
|
84
|
+
maxWidth: 0,
|
|
85
|
+
minHeight: 0,
|
|
86
|
+
minWidth: 0,
|
|
87
|
+
padding: 0,
|
|
88
|
+
paddingBottom: 0,
|
|
89
|
+
paddingLeft: 0,
|
|
90
|
+
paddingRight: 0,
|
|
91
|
+
paddingTop: 0,
|
|
92
|
+
paddingHorizontal: 0,
|
|
93
|
+
paddingVertical: 0,
|
|
94
|
+
fontSize: 0,
|
|
95
|
+
letterSpacing: 0 // Todo
|
|
96
|
+
}, animationAPIInitialValue);
|
|
97
|
+
// export type PropertyType = keyof transitionSupportedProperty
|
|
98
|
+
// transform
|
|
99
|
+
export const isTransform = (key) => hasOwn(transformInitial, key);
|
|
100
|
+
// transform 数组转对象
|
|
101
|
+
export function getTransformObj(transforms) {
|
|
102
|
+
'worklet';
|
|
103
|
+
return (transforms || []).reduce((transformObj, item) => {
|
|
104
|
+
return Object.assign(transformObj, item);
|
|
105
|
+
}, {});
|
|
106
|
+
}
|
|
107
|
+
// 获取样式初始值(prop style or 默认值)
|
|
108
|
+
export function getInitialVal(style, key) {
|
|
109
|
+
if (isTransform(key) && Array.isArray(style.transform)) {
|
|
110
|
+
let initialVal = transitionSupportedProperty[key];
|
|
111
|
+
// 仅支持 { transform: [{rotateX: '45deg'}, {rotateZ: '0.785398rad'}] } 格式的初始样式
|
|
112
|
+
style.transform.forEach(item => {
|
|
113
|
+
if (item[key] !== undefined)
|
|
114
|
+
initialVal = item[key];
|
|
115
|
+
});
|
|
116
|
+
return initialVal;
|
|
117
|
+
}
|
|
118
|
+
return style[key] === undefined ? transitionSupportedProperty[key] : style[key];
|
|
119
|
+
}
|
|
120
|
+
// animated key transform 格式化
|
|
121
|
+
export function formatAnimatedKeys(keys) {
|
|
122
|
+
// console.log('formatAnimatedKeys keys=', keys)
|
|
123
|
+
const animatedKeys = [];
|
|
124
|
+
const transforms = [];
|
|
125
|
+
keys.forEach(key => {
|
|
126
|
+
if (isTransform(key)) {
|
|
127
|
+
transforms.push(key);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
animatedKeys.push(key);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
if (transforms.length)
|
|
134
|
+
animatedKeys.push(transforms);
|
|
135
|
+
// console.log('formatAnimatedKeys animatedKeys=', animatedKeys)
|
|
136
|
+
return animatedKeys;
|
|
137
|
+
}
|
|
138
|
+
// 解析动画时长
|
|
139
|
+
export function getUnit(duration) {
|
|
140
|
+
const match = secondRegExp.exec(duration);
|
|
141
|
+
return match ? match[2] === 's' ? +match[1] * 1000 : +match[1] : 0;
|
|
142
|
+
}
|
|
143
|
+
// 根据动画数据创建单个animation
|
|
144
|
+
export function getAnimation({ key, value }, { delay = 0, duration, easing }, callback) {
|
|
145
|
+
// console.log('getAnimation', key, value, delay, duration, easing)
|
|
146
|
+
const animation = typeof callback === 'function'
|
|
147
|
+
? withTiming(value, { duration, easing }, callback)
|
|
148
|
+
: withTiming(value, { duration, easing });
|
|
149
|
+
return delay ? withDelay(delay, animation) : animation;
|
|
150
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Dispatch, MutableRefObject, SetStateAction } from 'react';
|
|
2
|
-
import { NativeSyntheticEvent, Animated } from 'react-native';
|
|
2
|
+
import { NativeSyntheticEvent, Animated, ScaledSize } from 'react-native';
|
|
3
3
|
export type LabelContextValue = MutableRefObject<{
|
|
4
4
|
triggerChange: (evt: NativeSyntheticEvent<TouchEvent>) => void;
|
|
5
5
|
}>;
|
|
@@ -7,6 +7,7 @@ export type KeyboardAvoidContextValue = MutableRefObject<{
|
|
|
7
7
|
cursorSpacing: number;
|
|
8
8
|
ref: MutableRefObject<any>;
|
|
9
9
|
adjustPosition: boolean;
|
|
10
|
+
holdKeyboard?: boolean;
|
|
10
11
|
keyboardHeight?: number;
|
|
11
12
|
onKeyboardShow?: () => void;
|
|
12
13
|
} | null>;
|
|
@@ -50,6 +51,10 @@ export interface RouteContextValue {
|
|
|
50
51
|
pageId: number;
|
|
51
52
|
navigation: Record<string, any>;
|
|
52
53
|
}
|
|
54
|
+
export interface DimensionsValue {
|
|
55
|
+
window: ScaledSize;
|
|
56
|
+
screen: ScaledSize;
|
|
57
|
+
}
|
|
53
58
|
export interface StickyContextValue {
|
|
54
59
|
registerStickyHeader: Function;
|
|
55
60
|
unregisterStickyHeader: Function;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,QAAQ,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AACjF,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,QAAQ,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AACjF,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAGzE,MAAM,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;IAC/C,aAAa,EAAE,CAAC,GAAG,EAAE,oBAAoB,CAAC,UAAU,CAAC,KAAK,IAAI,CAAA;CAC/D,CAAC,CAAA;AAEF,MAAM,MAAM,yBAAyB,GAAG,gBAAgB,CAAC;IACvD,aAAa,EAAE,MAAM,CAAA;IACrB,GAAG,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAA;IAC1B,cAAc,EAAE,OAAO,CAAA;IACvB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,MAAM,IAAI,CAAA;CAC5B,GAAG,IAAI,CAAC,CAAA;AAET,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,QAAQ,CAAC,cAAc,CAAC,OAAO,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E,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAChC;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,oBAAoB,EAAE,QAAQ,CAAA;IAC9B,sBAAsB,EAAE,QAAQ,CAAA;CACjC;AAED,eAAO,MAAM,kBAAkB;;;EAAyC,CAAA;AAExE,eAAO,MAAM,WAAW,kDAA+C,CAAA;AAEvE,eAAO,MAAM,oBAAoB,mDAAgD,CAAA;AAEjF,eAAO,MAAM,iBAAiB,mDAAgD,CAAA;AAE9E,eAAO,MAAM,YAAY,mDAAgD,CAAA;AAEzE,eAAO,MAAM,aAAa,+BAAsB,CAAA;AAEhD,eAAO,MAAM,UAAU,6BAAoB,CAAA;AAE3C,eAAO,MAAM,2BAA2B,sDAAmD,CAAA;AAE3F,eAAO,MAAM,YAAY,mDAAgD,CAAA;AAEzE,eAAO,MAAM,aAAa,6BAAoB,CAAA;AAE9C,eAAO,MAAM,oBAAoB,2DAAwD,CAAA;AAEzF,eAAO,MAAM,iBAAiB,iDAAmG,CAAA;AAEjI,eAAO,MAAM,aAAa,6CAAiD,CAAA;AAE3E,eAAO,MAAM,aAAa,6CAAkG,CAAA;AAE5H,eAAO,MAAM,eAAe,+BAAsB,CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface CameraProps {
|
|
3
|
+
mode?: 'normal' | 'scanCode';
|
|
4
|
+
resolution?: 'low' | 'medium' | 'high';
|
|
5
|
+
devicePosition?: 'front' | 'back';
|
|
6
|
+
flash?: 'auto' | 'on' | 'off';
|
|
7
|
+
frameSize?: 'small' | 'medium' | 'large';
|
|
8
|
+
style?: Record<string, any>;
|
|
9
|
+
bindstop?: () => void;
|
|
10
|
+
binderror?: (error: {
|
|
11
|
+
message: string;
|
|
12
|
+
}) => void;
|
|
13
|
+
bindinitdone?: (result: {
|
|
14
|
+
type: string;
|
|
15
|
+
data: string;
|
|
16
|
+
}) => void;
|
|
17
|
+
bindscancode?: (result: {
|
|
18
|
+
type: string;
|
|
19
|
+
data: string;
|
|
20
|
+
}) => void;
|
|
21
|
+
'parent-font-size'?: number;
|
|
22
|
+
'parent-width'?: number;
|
|
23
|
+
'parent-height'?: number;
|
|
24
|
+
'enable-var'?: boolean;
|
|
25
|
+
'external-var-context'?: any;
|
|
26
|
+
}
|
|
27
|
+
type HandlerRef<T, P> = {
|
|
28
|
+
current: T | null;
|
|
29
|
+
};
|
|
30
|
+
declare const _camera: React.ForwardRefExoticComponent<CameraProps & React.RefAttributes<HandlerRef<any, CameraProps>>>;
|
|
31
|
+
export default _camera;
|
|
32
|
+
//# sourceMappingURL=mpx-camera.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mpx-camera.d.ts","sourceRoot":"","sources":["../mpx-camera.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA0F,MAAM,OAAO,CAAA;AAa9G,UAAU,WAAW;IACnB,IAAI,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAA;IAC5B,UAAU,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAA;IACtC,cAAc,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IACjC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,KAAK,CAAA;IAC7B,SAAS,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAA;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC3B,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IACrB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;IAChD,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;IAC/D,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;IAC/D,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,sBAAsB,CAAC,EAAE,GAAG,CAAA;CAC7B;AA8BD,KAAK,UAAU,CAAC,CAAC,EAAE,CAAC,IAAI;IACtB,OAAO,EAAE,CAAC,GAAG,IAAI,CAAA;CAClB,CAAA;AAID,QAAA,MAAM,OAAO,kGAiQX,CAAA;AAIF,eAAe,OAAO,CAAA"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { createElement, forwardRef, useRef, useCallback, useContext, useState, useEffect } from 'react';
|
|
2
|
+
import { useTransformStyle, useLayout, extendObject } from './utils';
|
|
3
|
+
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
4
|
+
import { noop } from '@mpxjs/utils';
|
|
5
|
+
import { RouteContext } from './context';
|
|
6
|
+
const qualityValue = {
|
|
7
|
+
high: 90,
|
|
8
|
+
normal: 75,
|
|
9
|
+
low: 50,
|
|
10
|
+
original: 100
|
|
11
|
+
};
|
|
12
|
+
let RecordRes = null;
|
|
13
|
+
const _camera = forwardRef((props, ref) => {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
15
|
+
const { Camera, useCameraDevice, useCodeScanner, useCameraFormat } = require('react-native-vision-camera');
|
|
16
|
+
const cameraRef = useRef(null);
|
|
17
|
+
const { mode = 'normal', resolution = 'medium', devicePosition = 'back', flash = 'auto', frameSize = 'medium', bindinitdone, bindstop, bindscancode, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'enable-var': enableVar, 'external-var-context': externalVarContext, style = {} } = props;
|
|
18
|
+
const styleObj = extendObject({}, style);
|
|
19
|
+
const { normalStyle, hasSelfPercent, setWidth, setHeight } = useTransformStyle(styleObj, {
|
|
20
|
+
enableVar,
|
|
21
|
+
externalVarContext,
|
|
22
|
+
parentFontSize,
|
|
23
|
+
parentWidth,
|
|
24
|
+
parentHeight
|
|
25
|
+
});
|
|
26
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: cameraRef });
|
|
27
|
+
const isPhoto = mode === 'normal';
|
|
28
|
+
const device = useCameraDevice(devicePosition || 'back');
|
|
29
|
+
const { navigation } = useContext(RouteContext) || {};
|
|
30
|
+
const [zoomValue, setZoomValue] = useState(1);
|
|
31
|
+
const [hasPermission, setHasPermission] = useState(null);
|
|
32
|
+
const hasCamera = useRef(false);
|
|
33
|
+
// 先定义常量,避免在条件判断后使用
|
|
34
|
+
const maxZoom = device?.maxZoom || 1;
|
|
35
|
+
const RESOLUTION_MAPPING = {
|
|
36
|
+
low: { width: 640, height: 480 },
|
|
37
|
+
medium: { width: 1280, height: 720 },
|
|
38
|
+
high: { width: 1920, height: 1080 }
|
|
39
|
+
};
|
|
40
|
+
const FRAME_SIZE_MAPPING = {
|
|
41
|
+
small: { width: 480, height: 360 },
|
|
42
|
+
medium: { width: 720, height: 540 },
|
|
43
|
+
large: { width: 1080, height: 810 }
|
|
44
|
+
};
|
|
45
|
+
const format = useCameraFormat(device, [
|
|
46
|
+
{
|
|
47
|
+
photoResolution: RESOLUTION_MAPPING[resolution],
|
|
48
|
+
videoResolution: FRAME_SIZE_MAPPING[frameSize] || RESOLUTION_MAPPING[resolution]
|
|
49
|
+
}
|
|
50
|
+
]);
|
|
51
|
+
const codeScanner = useCodeScanner({
|
|
52
|
+
codeTypes: ['qr', 'ean-13'],
|
|
53
|
+
onCodeScanned: (codes) => {
|
|
54
|
+
const result = codes.map(code => code.value).join(',');
|
|
55
|
+
bindscancode && bindscancode(getCustomEvent('scancode', {}, {
|
|
56
|
+
detail: {
|
|
57
|
+
result: codes.map(code => code.value).join(',')
|
|
58
|
+
}
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const onInitialized = useCallback(() => {
|
|
63
|
+
bindinitdone && bindinitdone(getCustomEvent('initdone', {}, {
|
|
64
|
+
detail: {
|
|
65
|
+
maxZoom
|
|
66
|
+
}
|
|
67
|
+
}));
|
|
68
|
+
}, [bindinitdone, maxZoom]);
|
|
69
|
+
const onStopped = useCallback(() => {
|
|
70
|
+
bindstop && bindstop();
|
|
71
|
+
}, [bindstop]);
|
|
72
|
+
const camera = {
|
|
73
|
+
setZoom: (zoom) => {
|
|
74
|
+
setZoomValue(zoom);
|
|
75
|
+
},
|
|
76
|
+
takePhoto: (options = {}) => {
|
|
77
|
+
const { success = noop, fail = noop, complete = noop } = options;
|
|
78
|
+
cameraRef.current?.takePhoto?.({
|
|
79
|
+
flash,
|
|
80
|
+
quality: qualityValue[options.quality || 'normal']
|
|
81
|
+
}).then((res) => {
|
|
82
|
+
const result = {
|
|
83
|
+
errMsg: 'takePhoto:ok',
|
|
84
|
+
tempImagePath: res.path
|
|
85
|
+
};
|
|
86
|
+
success(result);
|
|
87
|
+
complete(result);
|
|
88
|
+
}).catch(() => {
|
|
89
|
+
const result = {
|
|
90
|
+
errMsg: 'takePhoto:fail'
|
|
91
|
+
};
|
|
92
|
+
fail(result);
|
|
93
|
+
complete(result);
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
startRecord: (options = {}) => {
|
|
97
|
+
let { timeout = 30, success = noop, fail = noop, complete = noop, timeoutCallback = noop } = options;
|
|
98
|
+
timeout = timeout > 300 ? 300 : timeout;
|
|
99
|
+
let recordTimer = null;
|
|
100
|
+
let isTimeout = false;
|
|
101
|
+
try {
|
|
102
|
+
const result = {
|
|
103
|
+
errMsg: 'startRecord:ok'
|
|
104
|
+
};
|
|
105
|
+
success(result);
|
|
106
|
+
complete(result);
|
|
107
|
+
cameraRef.current?.startRecording?.({
|
|
108
|
+
flash,
|
|
109
|
+
onRecordingError: (error) => {
|
|
110
|
+
if (recordTimer)
|
|
111
|
+
clearTimeout(recordTimer);
|
|
112
|
+
const errorResult = {
|
|
113
|
+
errMsg: 'startRecord:fail during recording',
|
|
114
|
+
error: error
|
|
115
|
+
};
|
|
116
|
+
timeoutCallback(errorResult);
|
|
117
|
+
},
|
|
118
|
+
onRecordingFinished: (video) => {
|
|
119
|
+
RecordRes = video;
|
|
120
|
+
if (recordTimer)
|
|
121
|
+
clearTimeout(recordTimer);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
recordTimer = setTimeout(() => {
|
|
125
|
+
isTimeout = true;
|
|
126
|
+
cameraRef.current?.stopRecording().catch(() => {
|
|
127
|
+
// 忽略停止录制时的错误
|
|
128
|
+
});
|
|
129
|
+
}, timeout * 1000);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
if (recordTimer)
|
|
133
|
+
clearTimeout(recordTimer);
|
|
134
|
+
const result = {
|
|
135
|
+
errMsg: 'startRecord:fail ' + (error.message || 'unknown error')
|
|
136
|
+
};
|
|
137
|
+
fail(result);
|
|
138
|
+
complete(result);
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
stopRecord: (options = {}) => {
|
|
142
|
+
const { success = noop, fail = noop, complete = noop } = options;
|
|
143
|
+
try {
|
|
144
|
+
cameraRef.current?.stopRecording().then(() => {
|
|
145
|
+
setTimeout(() => {
|
|
146
|
+
if (RecordRes) {
|
|
147
|
+
const result = {
|
|
148
|
+
errMsg: 'stopRecord:ok',
|
|
149
|
+
tempVideoPath: RecordRes?.path,
|
|
150
|
+
duration: RecordRes.duration * 1000 // 转成ms
|
|
151
|
+
};
|
|
152
|
+
RecordRes = null;
|
|
153
|
+
success(result);
|
|
154
|
+
complete(result);
|
|
155
|
+
}
|
|
156
|
+
}, 200); // 延时200ms,确保录制结果已准备好
|
|
157
|
+
}).catch((e) => {
|
|
158
|
+
const result = {
|
|
159
|
+
errMsg: 'stopRecord:fail ' + (e.message || 'promise rejected')
|
|
160
|
+
};
|
|
161
|
+
fail(result);
|
|
162
|
+
complete(result);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
const result = {
|
|
167
|
+
errMsg: 'stopRecord:fail ' + (error.message || 'unknown error')
|
|
168
|
+
};
|
|
169
|
+
fail(result);
|
|
170
|
+
complete(result);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
useEffect(() => {
|
|
175
|
+
if (navigation) {
|
|
176
|
+
if (navigation && !navigation.camera) {
|
|
177
|
+
navigation.camera = camera;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
hasCamera.current = true;
|
|
181
|
+
navigation.camera.multi = true;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const checkCameraPermission = async () => {
|
|
185
|
+
try {
|
|
186
|
+
const cameraPermission = global?.__mpx?.config?.rnConfig?.cameraPermission;
|
|
187
|
+
if (typeof cameraPermission === 'function') {
|
|
188
|
+
const permissionResult = await cameraPermission();
|
|
189
|
+
setHasPermission(permissionResult === true);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
setHasPermission(true);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
setHasPermission(false);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
checkCameraPermission();
|
|
200
|
+
return () => {
|
|
201
|
+
if (navigation && navigation.camera) {
|
|
202
|
+
navigation.camera = null;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}, []);
|
|
206
|
+
const innerProps = useInnerProps(extendObject({}, props, layoutProps, {
|
|
207
|
+
ref: cameraRef,
|
|
208
|
+
style: extendObject({}, normalStyle, layoutStyle),
|
|
209
|
+
isActive: true,
|
|
210
|
+
photo: true,
|
|
211
|
+
video: true,
|
|
212
|
+
onInitialized,
|
|
213
|
+
onStopped,
|
|
214
|
+
device,
|
|
215
|
+
format,
|
|
216
|
+
codeScanner: !isPhoto ? codeScanner : undefined,
|
|
217
|
+
zoom: zoomValue
|
|
218
|
+
}), [
|
|
219
|
+
'mode',
|
|
220
|
+
'resolution',
|
|
221
|
+
'frame-size',
|
|
222
|
+
'bindinitdone',
|
|
223
|
+
'bindstop',
|
|
224
|
+
'flash',
|
|
225
|
+
'bindscancode',
|
|
226
|
+
'binderror'
|
|
227
|
+
], {
|
|
228
|
+
layoutRef
|
|
229
|
+
});
|
|
230
|
+
if (!hasPermission || hasCamera.current || !device) {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
return createElement(Camera, innerProps);
|
|
234
|
+
});
|
|
235
|
+
_camera.displayName = 'MpxCamera';
|
|
236
|
+
export default _camera;
|
|
@@ -31,7 +31,9 @@ export interface InputProps {
|
|
|
31
31
|
'parent-font-size'?: number;
|
|
32
32
|
'parent-width'?: number;
|
|
33
33
|
'parent-height'?: number;
|
|
34
|
+
'keyboard-type'?: string;
|
|
34
35
|
'adjust-position': boolean;
|
|
36
|
+
'hold-keyboard'?: boolean;
|
|
35
37
|
bindinput?: (evt: NativeSyntheticEvent<TextInputTextInputEventData> | unknown) => void;
|
|
36
38
|
bindfocus?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void;
|
|
37
39
|
bindblur?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mpx-input.d.ts","sourceRoot":"","sources":["../mpx-input.tsx"],"names":[],"mappings":";AAwCA,OAAO,EACL,SAAS,EACT,SAAS,EACT,SAAS,EACT,oBAAoB,EACpB,2BAA2B,EAC3B,0BAA0B,EAC1B,mCAAmC,EACnC,SAAS,EACT,iCAAiC,EACjC,uBAAuB,EAEvB,+BAA+B,EAEhC,MAAM,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CAAA;IAC1B,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,oBAAoB,CAAC,mCAAmC,CAAC,GAAG,OAAO,KAAK,IAAI,CAAA;CACpG;AAED,KAAK,eAAe,GAAG,UAAU,GAAG,iBAAiB,CAAA;AASrD,QAAA,MAAM,KAAK,mJAkZT,CAAA;AAIF,eAAe,KAAK,CAAA"}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* ✔ selection-start
|
|
19
19
|
* ✔ selection-end
|
|
20
20
|
* ✔ adjust-position
|
|
21
|
-
*
|
|
21
|
+
* ✔ hold-keyboard
|
|
22
22
|
* ✘ safe-password-cert-path
|
|
23
23
|
* ✘ safe-password-length
|
|
24
24
|
* ✘ safe-password-time-stamp
|
|
@@ -40,19 +40,19 @@
|
|
|
40
40
|
import { forwardRef, useRef, useState, useContext, useEffect, createElement } from 'react';
|
|
41
41
|
import { TextInput } from 'react-native';
|
|
42
42
|
import { warn } from '@mpxjs/utils';
|
|
43
|
-
import { useUpdateEffect, useTransformStyle, useLayout, extendObject
|
|
43
|
+
import { useUpdateEffect, useTransformStyle, useLayout, extendObject } from './utils';
|
|
44
44
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
45
45
|
import useNodesRef from './useNodesRef';
|
|
46
46
|
import { FormContext, KeyboardAvoidContext } from './context';
|
|
47
47
|
import Portal from './mpx-portal';
|
|
48
|
-
const
|
|
49
|
-
text: '
|
|
48
|
+
const inputModeMap = {
|
|
49
|
+
text: 'text',
|
|
50
50
|
number: 'numeric',
|
|
51
|
-
idcard: '
|
|
52
|
-
digit:
|
|
51
|
+
idcard: 'text',
|
|
52
|
+
digit: 'decimal'
|
|
53
53
|
};
|
|
54
54
|
const Input = forwardRef((props, ref) => {
|
|
55
|
-
const { style = {}, allowFontScaling = false, type = 'text', value, password, 'placeholder-style': placeholderStyle = {}, disabled, maxlength = 140, 'cursor-spacing': cursorSpacing = 0, 'auto-focus': autoFocus, focus, 'confirm-type': confirmType = 'done', 'confirm-hold': confirmHold = false, cursor, 'cursor-color': cursorColor, 'selection-start': selectionStart = -1, 'selection-end': selectionEnd = -1, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'adjust-position': adjustPosition = true, bindinput, bindfocus, bindblur, bindconfirm, bindselectionchange,
|
|
55
|
+
const { style = {}, allowFontScaling = false, type = 'text', value, password, 'placeholder-style': placeholderStyle = {}, disabled, maxlength = 140, 'cursor-spacing': cursorSpacing = 0, 'auto-focus': autoFocus, focus, 'confirm-type': confirmType = 'done', 'confirm-hold': confirmHold = false, cursor, 'cursor-color': cursorColor, 'selection-start': selectionStart = -1, 'selection-end': selectionEnd = -1, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'adjust-position': adjustPosition = true, 'keyboard-type': originalKeyboardType, 'hold-keyboard': holdKeyboard = false, bindinput, bindfocus, bindblur, bindconfirm, bindselectionchange,
|
|
56
56
|
// private
|
|
57
57
|
multiline, 'auto-height': autoHeight, bindlinechange } = props;
|
|
58
58
|
const formContext = useContext(FormContext);
|
|
@@ -72,7 +72,6 @@ const Input = forwardRef((props, ref) => {
|
|
|
72
72
|
return value + '';
|
|
73
73
|
return '';
|
|
74
74
|
};
|
|
75
|
-
const keyboardType = keyboardTypeMap[type];
|
|
76
75
|
const defaultValue = parseValue(value);
|
|
77
76
|
const textAlignVertical = multiline ? 'top' : 'auto';
|
|
78
77
|
const tmpValue = useRef(defaultValue);
|
|
@@ -145,7 +144,15 @@ const Input = forwardRef((props, ref) => {
|
|
|
145
144
|
};
|
|
146
145
|
const setKeyboardAvoidContext = () => {
|
|
147
146
|
if (keyboardAvoid) {
|
|
148
|
-
keyboardAvoid.current = { cursorSpacing, ref: nodeRef, adjustPosition };
|
|
147
|
+
keyboardAvoid.current = { cursorSpacing, ref: nodeRef, adjustPosition, holdKeyboard };
|
|
148
|
+
keyboardAvoid.current = {
|
|
149
|
+
cursorSpacing,
|
|
150
|
+
ref: nodeRef,
|
|
151
|
+
adjustPosition,
|
|
152
|
+
// fix: iOS 会在 onFocus 之前触发 keyboardWillShow 并且赋值 keyboardHeight
|
|
153
|
+
// 这里手动同步下 keyboardHeight,防止 onFocus setKeyboardAvoidContext 删掉 keyboardHeight
|
|
154
|
+
keyboardHeight: keyboardAvoid?.current?.keyboardHeight
|
|
155
|
+
};
|
|
149
156
|
}
|
|
150
157
|
};
|
|
151
158
|
const onTouchStart = () => {
|
|
@@ -169,6 +176,9 @@ const Input = forwardRef((props, ref) => {
|
|
|
169
176
|
if (keyboardAvoid?.current?.onKeyboardShow) {
|
|
170
177
|
keyboardAvoid.current.onKeyboardShow = undefined;
|
|
171
178
|
}
|
|
179
|
+
if (keyboardAvoid?.current?.keyboardHeight) {
|
|
180
|
+
keyboardAvoid.current.keyboardHeight = undefined;
|
|
181
|
+
}
|
|
172
182
|
};
|
|
173
183
|
if (keyboardAvoid?.current) {
|
|
174
184
|
// 有 keyboardAvoiding
|
|
@@ -276,7 +286,8 @@ const Input = forwardRef((props, ref) => {
|
|
|
276
286
|
ref: nodeRef,
|
|
277
287
|
style: extendObject({}, normalStyle, layoutStyle),
|
|
278
288
|
allowFontScaling,
|
|
279
|
-
|
|
289
|
+
inputMode: originalKeyboardType ? undefined : inputModeMap[type],
|
|
290
|
+
keyboardType: originalKeyboardType,
|
|
280
291
|
secureTextEntry: !!password,
|
|
281
292
|
defaultValue: defaultValue,
|
|
282
293
|
value: inputValue,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mpx-keyboard-avoiding-view.d.ts","sourceRoot":"","sources":["../mpx-keyboard-avoiding-view.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAiC,MAAM,OAAO,CAAA;AACvE,OAAO,EAAuD,SAAS,EAA0C,MAAM,cAAc,CAAA;AAKrI,KAAK,sBAAsB,GAAG;IAC5B,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,qBAAqB,CAAC,EAAE,SAAS,CAAA;CAClC,CAAA;AAED,QAAA,MAAM,oBAAoB;iDAAgD,sBAAsB;;
|
|
1
|
+
{"version":3,"file":"mpx-keyboard-avoiding-view.d.ts","sourceRoot":"","sources":["../mpx-keyboard-avoiding-view.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAiC,MAAM,OAAO,CAAA;AACvE,OAAO,EAAuD,SAAS,EAA0C,MAAM,cAAc,CAAA;AAKrI,KAAK,sBAAsB,GAAG;IAC5B,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,qBAAqB,CAAC,EAAE,SAAS,CAAA;CAClC,CAAA;AAED,QAAA,MAAM,oBAAoB;iDAAgD,sBAAsB;;CAiH/F,CAAA;AAID,eAAe,oBAAoB,CAAA"}
|
|
@@ -38,6 +38,9 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }) => {
|
|
|
38
38
|
};
|
|
39
39
|
const onTouchEnd = ({ nativeEvent }) => {
|
|
40
40
|
if (nativeEvent.origin !== 'input') {
|
|
41
|
+
if (keyboardAvoid?.current?.holdKeyboard) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
41
44
|
Keyboard.isVisible() && Keyboard.dismiss();
|
|
42
45
|
}
|
|
43
46
|
};
|
|
@@ -7,7 +7,7 @@ const _PortalManager = forwardRef((props, ref) => {
|
|
|
7
7
|
setState((prevState) => ({
|
|
8
8
|
portals: [...prevState.portals, { key, children }]
|
|
9
9
|
}));
|
|
10
|
-
}, [
|
|
10
|
+
}, []);
|
|
11
11
|
const update = useCallback((key, children) => {
|
|
12
12
|
setState((prevState) => ({
|
|
13
13
|
portals: prevState.portals.map((item) => {
|
|
@@ -17,7 +17,7 @@ const _PortalManager = forwardRef((props, ref) => {
|
|
|
17
17
|
return item;
|
|
18
18
|
})
|
|
19
19
|
}));
|
|
20
|
-
}, [
|
|
20
|
+
}, []);
|
|
21
21
|
const unmount = useCallback((key) => {
|
|
22
22
|
setState((prevState) => ({
|
|
23
23
|
portals: prevState.portals.filter((item) => item.key !== key)
|
|
@@ -5,6 +5,11 @@ import { GestureHandler } from './utils';
|
|
|
5
5
|
/**
|
|
6
6
|
* ✔ indicator-dots
|
|
7
7
|
* ✔ indicator-color
|
|
8
|
+
* ✔ indicator-width
|
|
9
|
+
* ✔ indicator-height
|
|
10
|
+
* ✔ indicator-radius
|
|
11
|
+
* ✔ indicator-spacing
|
|
12
|
+
* ✔ indicator-margin
|
|
8
13
|
* ✔ indicator-active-color
|
|
9
14
|
* ✔ autoplay
|
|
10
15
|
* ✔ current
|
|
@@ -29,6 +34,11 @@ interface SwiperProps {
|
|
|
29
34
|
scale?: boolean;
|
|
30
35
|
'indicator-dots'?: boolean;
|
|
31
36
|
'indicator-color'?: string;
|
|
37
|
+
'indicator-width'?: number;
|
|
38
|
+
'indicator-height'?: number;
|
|
39
|
+
'indicator-spacing'?: number;
|
|
40
|
+
'indicator-radius'?: number;
|
|
41
|
+
'indicator-margin'?: number;
|
|
32
42
|
'indicator-active-color'?: string;
|
|
33
43
|
vertical?: boolean;
|
|
34
44
|
style: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mpx-swiper.d.ts","sourceRoot":"","sources":["../mpx-swiper.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,oBAAoB,EAAqB,MAAM,cAAc,CAAA;AAI5E,OAAO,KAAK,EAAE,EAAsC,SAAS,EAAwC,MAAM,OAAO,CAAA;AAElH,OAAoB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,EAAoF,cAAc,EAAmC,MAAM,SAAS,CAAA;AAG3J
|
|
1
|
+
{"version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