@mpxjs/webpack-plugin 2.9.64 → 2.9.65
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 +38 -10
- package/lib/platform/style/wx/index.js +52 -17
- package/lib/platform/template/wx/index.js +12 -8
- package/lib/react/style-helper.js +2 -5
- package/lib/runtime/components/react/dist/mpx-button.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +3 -2
- package/lib/runtime/components/react/dist/mpx-form.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-icon.jsx +3 -2
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-input.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-label.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +3 -2
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +4 -2
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +3 -2
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-radio.jsx +3 -2
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +3 -1
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +3 -2
- package/lib/runtime/components/react/dist/mpx-switch.jsx +3 -2
- package/lib/runtime/components/react/dist/mpx-text.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-view.jsx +15 -4
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +3 -2
- package/lib/runtime/components/react/dist/useNodesRef.js +1 -5
- package/lib/runtime/components/react/dist/utils.jsx +48 -36
- package/lib/runtime/components/react/mpx-button.tsx +3 -1
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +3 -1
- package/lib/runtime/components/react/mpx-checkbox.tsx +4 -1
- package/lib/runtime/components/react/mpx-form.tsx +2 -1
- package/lib/runtime/components/react/mpx-icon.tsx +3 -2
- package/lib/runtime/components/react/mpx-image/index.tsx +2 -1
- package/lib/runtime/components/react/mpx-input.tsx +2 -1
- package/lib/runtime/components/react/mpx-label.tsx +2 -1
- package/lib/runtime/components/react/mpx-movable-area.tsx +3 -2
- package/lib/runtime/components/react/mpx-movable-view.tsx +2 -1
- package/lib/runtime/components/react/mpx-picker/date.tsx +2 -1
- package/lib/runtime/components/react/mpx-picker/index.tsx +2 -1
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +2 -1
- package/lib/runtime/components/react/mpx-picker/region.tsx +2 -1
- package/lib/runtime/components/react/mpx-picker/selector.tsx +2 -1
- package/lib/runtime/components/react/mpx-picker/time.tsx +4 -2
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +3 -2
- package/lib/runtime/components/react/mpx-picker-view.tsx +2 -1
- package/lib/runtime/components/react/mpx-radio-group.tsx +2 -1
- package/lib/runtime/components/react/mpx-radio.tsx +3 -2
- package/lib/runtime/components/react/mpx-scroll-view.tsx +3 -1
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +2 -1
- package/lib/runtime/components/react/mpx-swiper/index.tsx +4 -1
- package/lib/runtime/components/react/mpx-swiper-item.tsx +2 -1
- package/lib/runtime/components/react/mpx-switch.tsx +2 -1
- package/lib/runtime/components/react/mpx-text.tsx +2 -1
- package/lib/runtime/components/react/mpx-view.tsx +16 -4
- package/lib/runtime/components/react/mpx-web-view.tsx +3 -2
- package/lib/runtime/components/react/types/global.d.ts +11 -1
- package/lib/runtime/components/react/useNodesRef.ts +1 -6
- package/lib/runtime/components/react/utils.tsx +65 -46
- package/lib/runtime/components/web/mpx-scroll-view.vue +25 -5
- package/lib/style-compiler/index.js +5 -4
- package/lib/template-compiler/compiler.js +105 -141
- package/lib/utils/const.js +2 -1
- package/lib/web/processStyles.js +6 -2
- package/lib/web/processTemplate.js +2 -3
- package/lib/wxml/loader.js +1 -1
- package/package.json +5 -4
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* ✔ checked
|
|
5
5
|
* ✔ color
|
|
6
6
|
*/
|
|
7
|
-
import { useState, forwardRef, useEffect, useContext } from 'react';
|
|
7
|
+
import { useRef, useState, forwardRef, useEffect, useContext } from 'react';
|
|
8
8
|
import { View, StyleSheet } from 'react-native';
|
|
9
9
|
import { warn } from '@mpxjs/utils';
|
|
10
10
|
import { LabelContext, RadioGroupContext } from './context';
|
|
@@ -92,7 +92,8 @@ const Radio = forwardRef((radioProps, ref) => {
|
|
|
92
92
|
if (backgroundStyle) {
|
|
93
93
|
warn('Radio does not support background image-related styles!');
|
|
94
94
|
}
|
|
95
|
-
const
|
|
95
|
+
const nodeRef = useRef(null);
|
|
96
|
+
useNodesRef(props, ref, nodeRef, {
|
|
96
97
|
defaultStyle,
|
|
97
98
|
change: onChange
|
|
98
99
|
});
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
import { ScrollView } from 'react-native-gesture-handler';
|
|
35
35
|
import { RefreshControl } from 'react-native';
|
|
36
36
|
import { useRef, useState, useEffect, forwardRef } from 'react';
|
|
37
|
+
import { useAnimatedRef } from 'react-native-reanimated';
|
|
37
38
|
import { warn } from '@mpxjs/utils';
|
|
38
39
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
39
40
|
import useNodesRef from './useNodesRef';
|
|
@@ -57,7 +58,8 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
57
58
|
const initialTimeout = useRef(null);
|
|
58
59
|
const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
59
60
|
const { textStyle, innerStyle } = splitStyle(normalStyle);
|
|
60
|
-
const
|
|
61
|
+
const scrollViewRef = useAnimatedRef();
|
|
62
|
+
useNodesRef(props, ref, scrollViewRef, {
|
|
61
63
|
scrollOffset: scrollOptions,
|
|
62
64
|
node: {
|
|
63
65
|
scrollEnabled: scrollX || scrollY,
|
|
@@ -69,7 +69,8 @@ const _Carouse = forwardRef((props, ref) => {
|
|
|
69
69
|
const defaultY = (defaultHeight * initOffsetIndex) || 0;
|
|
70
70
|
// 内部存储上一次的offset值
|
|
71
71
|
const autoplayTimerRef = useRef(null);
|
|
72
|
-
const
|
|
72
|
+
const scrollViewRef = useRef(null);
|
|
73
|
+
useNodesRef(props, ref, scrollViewRef, {});
|
|
73
74
|
const {
|
|
74
75
|
// 存储layout布局信息
|
|
75
76
|
layoutRef, layoutProps, layoutStyle } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout: onWrapperLayout });
|
|
@@ -43,7 +43,8 @@ const _SwiperWrapper = forwardRef((props, ref) => {
|
|
|
43
43
|
bindchange: props.bindchange,
|
|
44
44
|
easingFunction: props['easing-function'] || 'default'
|
|
45
45
|
};
|
|
46
|
-
const
|
|
46
|
+
const nodeRef = useRef(null);
|
|
47
|
+
useNodesRef(props, ref, nodeRef, {});
|
|
47
48
|
const innerProps = useInnerProps(props, {
|
|
48
49
|
ref: nodeRef
|
|
49
50
|
}, [
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { View } from 'react-native';
|
|
2
|
-
import { forwardRef } from 'react';
|
|
2
|
+
import { forwardRef, useRef } from 'react';
|
|
3
3
|
import useInnerProps from './getInnerListeners';
|
|
4
4
|
import useNodesRef from './useNodesRef'; // 引入辅助函数
|
|
5
5
|
import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout } from './utils';
|
|
6
6
|
const _SwiperItem = forwardRef((props, ref) => {
|
|
7
7
|
const { 'enable-offset': enableOffset, 'enable-var': enableVar, 'external-var-context': externalVarContext, style } = props;
|
|
8
8
|
const { textProps } = splitProps(props);
|
|
9
|
-
const
|
|
9
|
+
const nodeRef = useRef(null);
|
|
10
|
+
useNodesRef(props, ref, nodeRef, {});
|
|
10
11
|
const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext });
|
|
11
12
|
const { textStyle, innerStyle } = splitStyle(normalStyle);
|
|
12
13
|
const {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* ✔ color
|
|
6
6
|
*/
|
|
7
7
|
import { Switch } from 'react-native';
|
|
8
|
-
import { useEffect, forwardRef, useState, useContext } from 'react';
|
|
8
|
+
import { useRef, useEffect, forwardRef, useState, useContext } from 'react';
|
|
9
9
|
import { warn } from '@mpxjs/utils';
|
|
10
10
|
import useNodesRef from './useNodesRef'; // 引入辅助函数
|
|
11
11
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
@@ -31,7 +31,8 @@ const _Switch = forwardRef((props, ref) => {
|
|
|
31
31
|
useEffect(() => {
|
|
32
32
|
setIsChecked(checked);
|
|
33
33
|
}, [checked]);
|
|
34
|
-
const
|
|
34
|
+
const nodeRef = useRef(null);
|
|
35
|
+
useNodesRef(props, ref, nodeRef);
|
|
35
36
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
|
|
36
37
|
const onChange = (evt, { checked } = {}) => {
|
|
37
38
|
if (type === 'switch') {
|
|
@@ -18,7 +18,8 @@ const _Text = forwardRef((props, ref) => {
|
|
|
18
18
|
parentWidth,
|
|
19
19
|
parentHeight
|
|
20
20
|
});
|
|
21
|
-
const
|
|
21
|
+
const nodeRef = useRef(null);
|
|
22
|
+
useNodesRef(props, ref, nodeRef);
|
|
22
23
|
const innerProps = useInnerProps(props, {
|
|
23
24
|
ref: nodeRef,
|
|
24
25
|
style: normalStyle,
|
|
@@ -39,6 +39,16 @@ const applyHandlers = (handlers, args) => {
|
|
|
39
39
|
handler(...args);
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
|
+
const normalizeStyle = (style = {}) => {
|
|
43
|
+
['backgroundSize', 'backgroundPosition'].forEach(name => {
|
|
44
|
+
if (style[name] && typeof style[name] === 'string') {
|
|
45
|
+
if (style[name].trim()) {
|
|
46
|
+
style[name] = style[name].split(' ');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return style;
|
|
51
|
+
};
|
|
42
52
|
const isPercent = (val) => typeof val === 'string' && PERCENT_REGEX.test(val);
|
|
43
53
|
const isBackgroundSizeKeyword = (val) => typeof val === 'string' && /^cover|contain$/.test(val);
|
|
44
54
|
const isNeedLayout = (preImageInfo) => {
|
|
@@ -405,7 +415,7 @@ function normalizeBackgroundSize(backgroundSize, type) {
|
|
|
405
415
|
return sizeList;
|
|
406
416
|
}
|
|
407
417
|
function preParseImage(imageStyle) {
|
|
408
|
-
const { backgroundImage = '', backgroundSize = ['auto'], backgroundPosition = [0, 0] } = imageStyle || {};
|
|
418
|
+
const { backgroundImage = '', backgroundSize = ['auto'], backgroundPosition = [0, 0] } = normalizeStyle(imageStyle) || {};
|
|
409
419
|
const { type, src, linearInfo } = parseBgImage(backgroundImage);
|
|
410
420
|
return {
|
|
411
421
|
src,
|
|
@@ -487,8 +497,8 @@ function wrapImage(imageStyle) {
|
|
|
487
497
|
};
|
|
488
498
|
setImageSizeWidth(sizeInfo.current.width);
|
|
489
499
|
setImageSizeHeight(sizeInfo.current.height);
|
|
490
|
-
setShow(true);
|
|
491
500
|
}
|
|
501
|
+
setShow(true);
|
|
492
502
|
}
|
|
493
503
|
else if (sizeInfo.current) {
|
|
494
504
|
setLayoutInfoWidth(width);
|
|
@@ -498,7 +508,7 @@ function wrapImage(imageStyle) {
|
|
|
498
508
|
setShow(true);
|
|
499
509
|
}
|
|
500
510
|
};
|
|
501
|
-
return <View key='backgroundImage' {...needLayout ? { onLayout } : null} style={{ ...StyleSheet.absoluteFillObject,
|
|
511
|
+
return <View key='backgroundImage' {...needLayout ? { onLayout } : null} style={{ ...StyleSheet.absoluteFillObject, overflow: 'hidden' }}>
|
|
502
512
|
{show && type === 'linear' && <LinearGradient useAngle={true} {...imageStyleToProps(preImageInfo, sizeInfo.current, layoutInfo.current)}/>}
|
|
503
513
|
{show && type === 'image' && <Image {...imageStyleToProps(preImageInfo, sizeInfo.current, layoutInfo.current)}/>}
|
|
504
514
|
</View>;
|
|
@@ -547,7 +557,8 @@ const _View = forwardRef((viewProps, ref) => {
|
|
|
547
557
|
if (enableBackgroundRef.current !== enableBackground) {
|
|
548
558
|
throw new Error('[Mpx runtime error]: background use should be stable in the component lifecycle, or you can set [enable-background] with true.');
|
|
549
559
|
}
|
|
550
|
-
const
|
|
560
|
+
const nodeRef = useRef(null);
|
|
561
|
+
useNodesRef(props, ref, nodeRef, {
|
|
551
562
|
defaultStyle
|
|
552
563
|
});
|
|
553
564
|
const dataRef = useRef({});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { forwardRef, useEffect } from 'react';
|
|
1
|
+
import { forwardRef, useEffect, useRef } from 'react';
|
|
2
2
|
import { noop, warn } from '@mpxjs/utils';
|
|
3
3
|
import { Portal } from '@ant-design/react-native';
|
|
4
4
|
import { getCustomEvent } from './getInnerListeners';
|
|
@@ -17,7 +17,8 @@ const _WebView = forwardRef((props, ref) => {
|
|
|
17
17
|
top: 0,
|
|
18
18
|
bottom: 0
|
|
19
19
|
};
|
|
20
|
-
const
|
|
20
|
+
const webViewRef = useRef(null);
|
|
21
|
+
useNodesRef(props, ref, webViewRef, {
|
|
21
22
|
defaultStyle: defaultWebViewStyle
|
|
22
23
|
});
|
|
23
24
|
const _messageList = [];
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { useRef, useImperativeHandle } from 'react';
|
|
2
|
-
export default function useNodesRef(props, ref, instance = {}) {
|
|
3
|
-
const nodeRef = useRef(null);
|
|
2
|
+
export default function useNodesRef(props, ref, nodeRef, instance = {}) {
|
|
4
3
|
const _props = useRef(null);
|
|
5
4
|
_props.current = props;
|
|
6
5
|
useImperativeHandle(ref, () => {
|
|
@@ -14,7 +13,4 @@ export default function useNodesRef(props, ref, instance = {}) {
|
|
|
14
13
|
}
|
|
15
14
|
};
|
|
16
15
|
});
|
|
17
|
-
return {
|
|
18
|
-
nodeRef
|
|
19
|
-
};
|
|
20
16
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useEffect, useRef, isValidElement, useContext, useState, Children, cloneElement } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { isObject, hasOwn, diffAndCloneA, error, warn } from '@mpxjs/utils';
|
|
2
|
+
import { isObject, hasOwn, diffAndCloneA, error, warn, getFocusedNavigation } from '@mpxjs/utils';
|
|
4
3
|
import { VarContext } from './context';
|
|
5
4
|
import { ExpressionParser, parseFunc, ReplaceSource } from './parser';
|
|
5
|
+
import { initialWindowMetrics } from 'react-native-safe-area-context';
|
|
6
6
|
export const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/;
|
|
7
7
|
export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/;
|
|
8
8
|
export const URL_REGEX = /^\s*url\(["']?(.*?)["']?\)\s*$/;
|
|
@@ -12,18 +12,24 @@ export const DEFAULT_FONT_SIZE = 16;
|
|
|
12
12
|
export const DEFAULT_UNLAY_STYLE = {
|
|
13
13
|
opacity: 0
|
|
14
14
|
};
|
|
15
|
-
export function rpx(value) {
|
|
16
|
-
const { width } = Dimensions.get('screen');
|
|
17
|
-
// rn 单位 dp = 1(css)px = 1 物理像素 * pixelRatio(像素比)
|
|
18
|
-
// px = rpx * (750 / 屏幕宽度)
|
|
19
|
-
return value * width / 750;
|
|
20
|
-
}
|
|
21
|
-
const rpxRegExp = /^\s*(-?\d+(\.\d+)?)rpx\s*$/;
|
|
22
|
-
const pxRegExp = /^\s*(-?\d+(\.\d+)?)(px)?\s*$/;
|
|
23
|
-
const hairlineRegExp = /^\s*hairlineWidth\s*$/;
|
|
24
15
|
const varDecRegExp = /^--.*/;
|
|
25
16
|
const varUseRegExp = /var\(/;
|
|
26
17
|
const calcUseRegExp = /calc\(/;
|
|
18
|
+
const envUseRegExp = /env\(/;
|
|
19
|
+
const safeAreaInsetMap = {
|
|
20
|
+
'safe-area-inset-top': 'top',
|
|
21
|
+
'safe-area-inset-right': 'right',
|
|
22
|
+
'safe-area-inset-bottom': 'bottom',
|
|
23
|
+
'safe-area-inset-left': 'left'
|
|
24
|
+
};
|
|
25
|
+
function getSafeAreaInset(name) {
|
|
26
|
+
const navigation = getFocusedNavigation();
|
|
27
|
+
const insets = {
|
|
28
|
+
...initialWindowMetrics?.insets,
|
|
29
|
+
...navigation?.insets
|
|
30
|
+
};
|
|
31
|
+
return insets[safeAreaInsetMap[name]];
|
|
32
|
+
}
|
|
27
33
|
export function omit(obj, fields) {
|
|
28
34
|
const shallowCopy = Object.assign({}, obj);
|
|
29
35
|
for (let i = 0; i < fields.length; i += 1) {
|
|
@@ -131,20 +137,6 @@ const parentHeightPercentRule = {
|
|
|
131
137
|
top: true,
|
|
132
138
|
bottom: true
|
|
133
139
|
};
|
|
134
|
-
// todo calc时处理角度和时间等单位
|
|
135
|
-
function formatValue(value) {
|
|
136
|
-
let matched;
|
|
137
|
-
if ((matched = pxRegExp.exec(value))) {
|
|
138
|
-
return +matched[1];
|
|
139
|
-
}
|
|
140
|
-
else if ((matched = rpxRegExp.exec(value))) {
|
|
141
|
-
return rpx(+matched[1]);
|
|
142
|
-
}
|
|
143
|
-
else if (hairlineRegExp.test(value)) {
|
|
144
|
-
return StyleSheet.hairlineWidth;
|
|
145
|
-
}
|
|
146
|
-
return value;
|
|
147
|
-
}
|
|
148
140
|
function resolvePercent(value, key, percentConfig) {
|
|
149
141
|
if (!(typeof value === 'string' && PERCENT_REGEX.test(value)))
|
|
150
142
|
return value;
|
|
@@ -196,11 +188,11 @@ function resolveVar(input, varContext) {
|
|
|
196
188
|
varValue = '' + resolveVar(varValue, varContext);
|
|
197
189
|
}
|
|
198
190
|
else {
|
|
199
|
-
varValue = '' +
|
|
191
|
+
varValue = '' + global.__formatValue(varValue);
|
|
200
192
|
}
|
|
201
193
|
replaced.replace(start, end - 1, varValue);
|
|
202
194
|
});
|
|
203
|
-
return
|
|
195
|
+
return global.__formatValue(replaced.source());
|
|
204
196
|
}
|
|
205
197
|
function transformVar(styleObj, varKeyPaths, varContext) {
|
|
206
198
|
varKeyPaths.forEach((varKeyPath) => {
|
|
@@ -209,6 +201,21 @@ function transformVar(styleObj, varKeyPaths, varContext) {
|
|
|
209
201
|
});
|
|
210
202
|
});
|
|
211
203
|
}
|
|
204
|
+
function transformEnv(styleObj, envKeyPaths) {
|
|
205
|
+
envKeyPaths.forEach((envKeyPath) => {
|
|
206
|
+
setStyle(styleObj, envKeyPath, ({ target, key, value }) => {
|
|
207
|
+
const parsed = parseFunc(value, 'env');
|
|
208
|
+
const replaced = new ReplaceSource(value);
|
|
209
|
+
parsed.forEach(({ start, end, args }) => {
|
|
210
|
+
const name = args[0];
|
|
211
|
+
const fallback = args[1] || '';
|
|
212
|
+
const value = '' + (getSafeAreaInset(name) ?? global.__formatValue(fallback));
|
|
213
|
+
replaced.replace(start, end - 1, value);
|
|
214
|
+
});
|
|
215
|
+
target[key] = global.__formatValue(replaced.source());
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
}
|
|
212
219
|
function transformCalc(styleObj, calcKeyPaths, formatter) {
|
|
213
220
|
calcKeyPaths.forEach((calcKeyPath) => {
|
|
214
221
|
setStyle(styleObj, calcKeyPath, ({ target, key, value }) => {
|
|
@@ -226,7 +233,7 @@ function transformCalc(styleObj, calcKeyPaths, formatter) {
|
|
|
226
233
|
error(`calc(${exp}) parse error.`, undefined, e);
|
|
227
234
|
}
|
|
228
235
|
});
|
|
229
|
-
target[key] =
|
|
236
|
+
target[key] = global.__formatValue(replaced.source());
|
|
230
237
|
});
|
|
231
238
|
});
|
|
232
239
|
}
|
|
@@ -239,6 +246,7 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
|
|
|
239
246
|
const varKeyPaths = [];
|
|
240
247
|
const percentKeyPaths = [];
|
|
241
248
|
const calcKeyPaths = [];
|
|
249
|
+
const envKeyPaths = [];
|
|
242
250
|
const [width, setWidth] = useState(0);
|
|
243
251
|
const [height, setHeight] = useState(0);
|
|
244
252
|
function varVisitor({ key, value, keyPath }) {
|
|
@@ -277,6 +285,11 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
|
|
|
277
285
|
}
|
|
278
286
|
transformVar(normalStyle, varKeyPaths, varContextRef.current);
|
|
279
287
|
}
|
|
288
|
+
function envVisitor({ value, keyPath }) {
|
|
289
|
+
if (envUseRegExp.test(value)) {
|
|
290
|
+
envKeyPaths.push(keyPath.slice());
|
|
291
|
+
}
|
|
292
|
+
}
|
|
280
293
|
function calcVisitor({ value, keyPath }) {
|
|
281
294
|
if (calcUseRegExp.test(value)) {
|
|
282
295
|
calcKeyPaths.push(keyPath.slice());
|
|
@@ -287,12 +300,12 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
|
|
|
287
300
|
hasSelfPercent = true;
|
|
288
301
|
percentKeyPaths.push(keyPath.slice());
|
|
289
302
|
}
|
|
290
|
-
else if (key === 'fontSize' || key === 'lineHeight') {
|
|
303
|
+
else if ((key === 'fontSize' || key === 'lineHeight') && PERCENT_REGEX.test(value)) {
|
|
291
304
|
percentKeyPaths.push(keyPath.slice());
|
|
292
305
|
}
|
|
293
306
|
}
|
|
294
|
-
// traverse calc & percent
|
|
295
|
-
traverseStyle(normalStyle, [percentVisitor, calcVisitor]);
|
|
307
|
+
// traverse env & calc & percent
|
|
308
|
+
traverseStyle(normalStyle, [envVisitor, percentVisitor, calcVisitor]);
|
|
296
309
|
const percentConfig = {
|
|
297
310
|
width,
|
|
298
311
|
height,
|
|
@@ -301,6 +314,8 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
|
|
|
301
314
|
parentHeight,
|
|
302
315
|
parentFontSize
|
|
303
316
|
};
|
|
317
|
+
// apply env
|
|
318
|
+
transformEnv(normalStyle, envKeyPaths);
|
|
304
319
|
// apply percent
|
|
305
320
|
transformPercent(normalStyle, percentKeyPaths, percentConfig);
|
|
306
321
|
// apply calc
|
|
@@ -310,7 +325,7 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
|
|
|
310
325
|
return typeof resolved === 'number' ? resolved : 0;
|
|
311
326
|
}
|
|
312
327
|
else {
|
|
313
|
-
const formatted =
|
|
328
|
+
const formatted = global.__formatValue(value);
|
|
314
329
|
if (typeof formatted === 'number') {
|
|
315
330
|
return formatted;
|
|
316
331
|
}
|
|
@@ -358,12 +373,9 @@ export function traverseStyle(styleObj, visitors) {
|
|
|
358
373
|
}
|
|
359
374
|
traverse(styleObj);
|
|
360
375
|
}
|
|
361
|
-
export function setStyle(styleObj, keyPath, setter
|
|
376
|
+
export function setStyle(styleObj, keyPath, setter) {
|
|
362
377
|
let target = styleObj;
|
|
363
|
-
const firstKey = keyPath[0];
|
|
364
378
|
const lastKey = keyPath[keyPath.length - 1];
|
|
365
|
-
if (needClone)
|
|
366
|
-
target[firstKey] = diffAndCloneA(target[firstKey]).clone;
|
|
367
379
|
for (let i = 0; i < keyPath.length - 1; i++) {
|
|
368
380
|
target = target[keyPath[i]];
|
|
369
381
|
if (!target)
|
|
@@ -297,7 +297,9 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
297
297
|
setHeight
|
|
298
298
|
} = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
299
299
|
|
|
300
|
-
const
|
|
300
|
+
const nodeRef = useRef(null)
|
|
301
|
+
|
|
302
|
+
useNodesRef(props, ref, nodeRef, { defaultStyle })
|
|
301
303
|
|
|
302
304
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
|
|
303
305
|
|
|
@@ -65,7 +65,9 @@ const CheckboxGroup = forwardRef<
|
|
|
65
65
|
setHeight
|
|
66
66
|
} = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
67
67
|
|
|
68
|
-
const
|
|
68
|
+
const nodeRef = useRef(null)
|
|
69
|
+
|
|
70
|
+
useNodesRef(props, ref, nodeRef, { defaultStyle })
|
|
69
71
|
|
|
70
72
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
|
|
71
73
|
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import {
|
|
8
8
|
JSX,
|
|
9
9
|
useState,
|
|
10
|
+
useRef,
|
|
10
11
|
forwardRef,
|
|
11
12
|
useEffect,
|
|
12
13
|
ReactNode,
|
|
@@ -141,7 +142,9 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
|
|
|
141
142
|
setHeight
|
|
142
143
|
} = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
143
144
|
|
|
144
|
-
const
|
|
145
|
+
const nodeRef = useRef(null)
|
|
146
|
+
|
|
147
|
+
useNodesRef(props, ref, nodeRef, {
|
|
145
148
|
defaultStyle,
|
|
146
149
|
change: onChange
|
|
147
150
|
})
|
|
@@ -51,7 +51,8 @@ const _Form = forwardRef<HandlerRef<View, FormProps>, FormProps>((fromProps: For
|
|
|
51
51
|
|
|
52
52
|
const { textStyle, innerStyle } = splitStyle(normalStyle)
|
|
53
53
|
|
|
54
|
-
const
|
|
54
|
+
const formRef = useRef(null)
|
|
55
|
+
useNodesRef(props, ref, formRef)
|
|
55
56
|
|
|
56
57
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: formRef })
|
|
57
58
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* ✔ size
|
|
4
4
|
* ✔ color
|
|
5
5
|
*/
|
|
6
|
-
import { JSX, forwardRef } from 'react'
|
|
6
|
+
import { JSX, forwardRef, useRef } from 'react'
|
|
7
7
|
import { Text, TextStyle, Image } from 'react-native'
|
|
8
8
|
import useInnerProps from './getInnerListeners'
|
|
9
9
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
@@ -75,7 +75,8 @@ const Icon = forwardRef<HandlerRef<Text, IconProps>, IconProps>(
|
|
|
75
75
|
setHeight
|
|
76
76
|
} = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
77
77
|
|
|
78
|
-
const
|
|
78
|
+
const nodeRef = useRef(null)
|
|
79
|
+
useNodesRef(props, ref, nodeRef, { defaultStyle })
|
|
79
80
|
|
|
80
81
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
|
|
81
82
|
|
|
@@ -135,7 +135,8 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
135
135
|
overflow: 'hidden'
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
const
|
|
138
|
+
const nodeRef = useRef(null)
|
|
139
|
+
useNodesRef(props, ref, nodeRef, {
|
|
139
140
|
defaultStyle
|
|
140
141
|
})
|
|
141
142
|
|
|
@@ -192,7 +192,8 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
192
192
|
setHeight
|
|
193
193
|
} = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
194
194
|
|
|
195
|
-
const
|
|
195
|
+
const nodeRef = useRef(null)
|
|
196
|
+
useNodesRef(props, ref, nodeRef)
|
|
196
197
|
|
|
197
198
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
|
|
198
199
|
|
|
@@ -54,7 +54,8 @@ const Label = forwardRef<HandlerRef<View, LabelProps>, LabelProps>(
|
|
|
54
54
|
setHeight
|
|
55
55
|
} = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
56
56
|
|
|
57
|
-
const
|
|
57
|
+
const nodeRef = useRef(null)
|
|
58
|
+
useNodesRef(props, ref, nodeRef, { defaultStyle })
|
|
58
59
|
|
|
59
60
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
|
|
60
61
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { View, LayoutChangeEvent } from 'react-native'
|
|
6
|
-
import { JSX, useState, useEffect, forwardRef, ReactNode } from 'react'
|
|
6
|
+
import { JSX, useState, useEffect, forwardRef, ReactNode, useRef } from 'react'
|
|
7
7
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
8
8
|
import useInnerProps from './getInnerListeners'
|
|
9
9
|
import { MovableAreaContext } from './context'
|
|
@@ -41,7 +41,8 @@ const _MovableArea = forwardRef<HandlerRef<View, MovableAreaProps>, MovableAreaP
|
|
|
41
41
|
setHeight
|
|
42
42
|
} = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
43
43
|
|
|
44
|
-
const
|
|
44
|
+
const movableViewRef = useRef(null)
|
|
45
|
+
useNodesRef(props, ref, movableViewRef)
|
|
45
46
|
|
|
46
47
|
const onLayout = (e: LayoutChangeEvent) => {
|
|
47
48
|
const { width = 10, height = 10 } = e.nativeEvent.layout
|
|
@@ -84,7 +84,8 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
84
84
|
y: Number(y)
|
|
85
85
|
})
|
|
86
86
|
|
|
87
|
-
const
|
|
87
|
+
const nodeRef = useRef<View>(null)
|
|
88
|
+
useNodesRef(props, ref, nodeRef, {
|
|
88
89
|
defaultStyle: styles.container
|
|
89
90
|
})
|
|
90
91
|
|
|
@@ -31,7 +31,8 @@ const _DatePicker = forwardRef<HandlerRef<View, DateProps>, DateProps>((props: D
|
|
|
31
31
|
const [datevalue, setDateValue] = useState(value)
|
|
32
32
|
// 存储layout布局信息
|
|
33
33
|
const layoutRef = useRef({})
|
|
34
|
-
const
|
|
34
|
+
const viewRef = useRef<View>(null)
|
|
35
|
+
useNodesRef<View, DateProps>(props, ref, viewRef, {
|
|
35
36
|
})
|
|
36
37
|
|
|
37
38
|
useEffect(() => {
|
|
@@ -34,7 +34,8 @@ import { FormContext, FormFieldValue } from '../context'
|
|
|
34
34
|
const _Picker = forwardRef<HandlerRef<View, PickerProps>, PickerProps>((props: PickerProps, ref): React.JSX.Element => {
|
|
35
35
|
const { mode = 'selector', value, bindcancel, bindchange, children, bindcolumnchange } = props
|
|
36
36
|
const innerLayout = useRef({})
|
|
37
|
-
const
|
|
37
|
+
const nodeRef = useRef(null)
|
|
38
|
+
useNodesRef<View, PickerProps>(props, ref, nodeRef, {
|
|
38
39
|
})
|
|
39
40
|
const innerProps = useInnerProps(props, {
|
|
40
41
|
ref: nodeRef
|
|
@@ -89,7 +89,8 @@ const _MultiSelectorPicker = forwardRef<HandlerRef<View, MultiSelectorProps>, Mu
|
|
|
89
89
|
const [data, setData] = useState(formatRange || [])
|
|
90
90
|
// 存储layout布局信息
|
|
91
91
|
const layoutRef = useRef({})
|
|
92
|
-
const
|
|
92
|
+
const viewRef = useRef<View>(null)
|
|
93
|
+
useNodesRef<View, MultiSelectorProps>(props, ref, viewRef, {
|
|
93
94
|
})
|
|
94
95
|
|
|
95
96
|
useEffect(() => {
|
|
@@ -44,7 +44,8 @@ const _RegionPicker = forwardRef<HandlerRef<View, RegionProps>, RegionProps>((pr
|
|
|
44
44
|
const [regionvalue, setRegionValue] = useState(value)
|
|
45
45
|
// 存储layout布局信息
|
|
46
46
|
const layoutRef = useRef({})
|
|
47
|
-
const
|
|
47
|
+
const viewRef = useRef<View>(null)
|
|
48
|
+
useNodesRef<View, RegionProps>(props, ref, viewRef, {
|
|
48
49
|
})
|
|
49
50
|
|
|
50
51
|
const onChange = (value: string[]): void => {
|
|
@@ -31,7 +31,8 @@ const _SelectorPicker = forwardRef<HandlerRef<View, SelectorProps>, SelectorProp
|
|
|
31
31
|
const [data, setData] = useState(formatRange || [])
|
|
32
32
|
// 存储layout布局信息
|
|
33
33
|
const layoutRef = useRef({})
|
|
34
|
-
const
|
|
34
|
+
const viewRef = useRef<View>(null)
|
|
35
|
+
useNodesRef<View, SelectorProps>(props, ref, viewRef, {
|
|
35
36
|
})
|
|
36
37
|
|
|
37
38
|
useEffect(() => {
|
|
@@ -134,10 +134,12 @@ const _TimePicker = forwardRef<HandlerRef<View, TimeProps>, TimeProps>((props: T
|
|
|
134
134
|
const [timevalue, setTimeValue] = useState(defaultValue)
|
|
135
135
|
// 存储layout布局信息
|
|
136
136
|
const layoutRef = useRef({})
|
|
137
|
-
const
|
|
137
|
+
const viewRef = useRef<View>(null)
|
|
138
|
+
useNodesRef<View, TimeProps>(props, ref, viewRef, {})
|
|
138
139
|
// 存储modal的布局信息
|
|
139
140
|
const modalLayoutRef = useRef({})
|
|
140
|
-
const
|
|
141
|
+
const modalRef = useRef<View>(null)
|
|
142
|
+
useNodesRef<View, TimeProps>(props, ref, modalRef, {})
|
|
141
143
|
const [visible, setVisible] = useState(false)
|
|
142
144
|
const columnData = generateColumns()
|
|
143
145
|
const [data, setData] = useState(columnData)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
import { View, Animated, SafeAreaView, NativeScrollEvent, NativeSyntheticEvent, LayoutChangeEvent, ScrollView } from 'react-native'
|
|
3
|
-
import React, { forwardRef, useState, useEffect, ReactElement, ReactNode } from 'react'
|
|
3
|
+
import React, { forwardRef, useRef, useState, useEffect, ReactElement, ReactNode } from 'react'
|
|
4
4
|
import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout } from './utils'
|
|
5
5
|
import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
|
|
6
6
|
interface ColumnProps {
|
|
@@ -38,7 +38,8 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
38
38
|
const { textProps } = splitProps(props)
|
|
39
39
|
// const { innerStyle } = splitStyle(normalStyle)
|
|
40
40
|
// scrollView的ref
|
|
41
|
-
const
|
|
41
|
+
const scrollViewRef = useRef<ScrollView>(null)
|
|
42
|
+
useNodesRef(props, ref, scrollViewRef, {})
|
|
42
43
|
// 每个元素的高度
|
|
43
44
|
let [itemH, setItemH] = useState(0)
|
|
44
45
|
|
|
@@ -66,7 +66,8 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
|
|
|
66
66
|
// 微信设置到pick-view上上设置的normalStyle如border等需要转换成RN的style然后进行透传
|
|
67
67
|
const indicatorStyle = parseInlineStyle(props['indicator-style'])
|
|
68
68
|
const { height: indicatorH, width: indicatorW } = indicatorStyle
|
|
69
|
-
const
|
|
69
|
+
const nodeRef = useRef(null)
|
|
70
|
+
useNodesRef<View, PickerViewProps>(props, ref, nodeRef, {})
|
|
70
71
|
// picker-view 设置的color等textStyle,在小程序上的表现是可以继承到最内层的text样式, 但是RN内部column是slot无法设置, 需要业务自己在column内的元素上设置
|
|
71
72
|
const {
|
|
72
73
|
normalStyle,
|
|
@@ -65,7 +65,8 @@ const radioGroup = forwardRef<
|
|
|
65
65
|
setHeight
|
|
66
66
|
} = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
67
67
|
|
|
68
|
-
const
|
|
68
|
+
const nodeRef = useRef(null)
|
|
69
|
+
useNodesRef(props, ref, nodeRef, { defaultStyle })
|
|
69
70
|
|
|
70
71
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
|
|
71
72
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* ✔ checked
|
|
5
5
|
* ✔ color
|
|
6
6
|
*/
|
|
7
|
-
import { JSX, useState, forwardRef, useEffect, ReactNode, useContext, Dispatch, SetStateAction } from 'react'
|
|
7
|
+
import { JSX, useRef, useState, forwardRef, useEffect, ReactNode, useContext, Dispatch, SetStateAction } from 'react'
|
|
8
8
|
import { View, StyleSheet, ViewStyle, NativeSyntheticEvent } from 'react-native'
|
|
9
9
|
import { warn } from '@mpxjs/utils'
|
|
10
10
|
import { LabelContext, RadioGroupContext } from './context'
|
|
@@ -141,7 +141,8 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
|
|
|
141
141
|
warn('Radio does not support background image-related styles!')
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
const
|
|
144
|
+
const nodeRef = useRef(null)
|
|
145
|
+
useNodesRef(props, ref, nodeRef, {
|
|
145
146
|
defaultStyle,
|
|
146
147
|
change: onChange
|
|
147
148
|
})
|