@mpxjs/webpack-plugin 2.9.66 → 2.9.67
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/RecordGlobalComponentsDependency.js +11 -12
- package/lib/dependencies/RecordRuntimeInfoDependency.js +1 -1
- package/lib/index.js +23 -7
- package/lib/json-compiler/index.js +2 -11
- package/lib/loader.js +24 -45
- package/lib/native-loader.js +49 -64
- package/lib/platform/json/wx/index.js +3 -10
- package/lib/platform/style/wx/index.js +15 -10
- package/lib/react/index.js +4 -3
- package/lib/react/processJSON.js +5 -13
- package/lib/react/processMainScript.js +7 -3
- package/lib/react/processScript.js +3 -4
- package/lib/react/processTemplate.js +2 -2
- package/lib/resolver/AddModePlugin.js +17 -4
- package/lib/runtime/components/react/dist/mpx-button.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +30 -17
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-form.jsx +33 -24
- package/lib/runtime/components/react/dist/mpx-icon.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-input.jsx +44 -38
- package/lib/runtime/components/react/dist/mpx-label.jsx +10 -7
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +10 -17
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +378 -294
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +30 -17
- package/lib/runtime/components/react/dist/mpx-radio.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +49 -29
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-switch.jsx +8 -1
- package/lib/runtime/components/react/dist/mpx-text.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-view.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
- package/lib/runtime/components/react/dist/useAnimationHooks.js +96 -8
- package/lib/runtime/components/react/dist/utils.jsx +12 -3
- package/lib/runtime/components/react/getInnerListeners.ts +1 -0
- package/lib/runtime/components/react/mpx-button.tsx +1 -1
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +52 -29
- package/lib/runtime/components/react/mpx-checkbox.tsx +1 -1
- package/lib/runtime/components/react/mpx-form.tsx +42 -34
- package/lib/runtime/components/react/mpx-icon.tsx +1 -1
- package/lib/runtime/components/react/mpx-image/index.tsx +2 -3
- package/lib/runtime/components/react/mpx-input.tsx +68 -66
- package/lib/runtime/components/react/mpx-label.tsx +11 -8
- package/lib/runtime/components/react/mpx-movable-area.tsx +11 -19
- package/lib/runtime/components/react/mpx-movable-view.tsx +456 -334
- package/lib/runtime/components/react/mpx-navigator.tsx +1 -1
- package/lib/runtime/components/react/mpx-radio-group.tsx +55 -29
- package/lib/runtime/components/react/mpx-radio.tsx +1 -1
- package/lib/runtime/components/react/mpx-root-portal.tsx +1 -1
- package/lib/runtime/components/react/mpx-scroll-view.tsx +81 -36
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +2 -2
- package/lib/runtime/components/react/mpx-swiper/index.tsx +2 -1
- package/lib/runtime/components/react/mpx-swiper-item.tsx +1 -1
- package/lib/runtime/components/react/mpx-switch.tsx +10 -2
- package/lib/runtime/components/react/mpx-text.tsx +1 -1
- package/lib/runtime/components/react/mpx-textarea.tsx +1 -1
- package/lib/runtime/components/react/mpx-view.tsx +1 -1
- package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
- package/lib/runtime/components/react/useAnimationHooks.ts +97 -13
- package/lib/runtime/components/react/useNodesRef.ts +1 -0
- package/lib/runtime/components/react/utils.tsx +18 -3
- package/lib/runtime/optionProcessorReact.js +0 -15
- package/lib/runtime/swanHelper.wxs +1 -1
- package/lib/style-compiler/index.js +1 -1
- package/lib/style-compiler/plugins/scope-id.js +1 -0
- package/lib/template-compiler/compiler.js +46 -16
- package/lib/template-compiler/index.js +4 -4
- package/lib/utils/pre-process-json.js +113 -0
- package/lib/web/index.js +5 -4
- package/lib/web/processJSON.js +5 -13
- package/lib/web/processTemplate.js +2 -2
- package/package.json +4 -4
|
@@ -8,7 +8,7 @@ const {
|
|
|
8
8
|
module.exports = function ({
|
|
9
9
|
loaderContext
|
|
10
10
|
}, callback) {
|
|
11
|
-
const { i18n,
|
|
11
|
+
const { i18n, rnConfig } = loaderContext.getMpx()
|
|
12
12
|
|
|
13
13
|
let output = 'import { AppRegistry } from \'react-native\'\n'
|
|
14
14
|
|
|
@@ -16,8 +16,12 @@ module.exports = function ({
|
|
|
16
16
|
output += buildI18n({ loaderContext })
|
|
17
17
|
}
|
|
18
18
|
// 此处可添加前置于App执行的语句
|
|
19
|
-
output += `var
|
|
20
|
-
|
|
19
|
+
output += `var app = require(${stringifyRequest(loaderContext, addQuery(loaderContext.resource, { isApp: true }))}).default\n`
|
|
20
|
+
if (rnConfig.projectName) {
|
|
21
|
+
output += `AppRegistry.registerComponent(${JSON.stringify(rnConfig.projectName)}, () => app)\n`
|
|
22
|
+
} else {
|
|
23
|
+
output += 'export default app\n'
|
|
24
|
+
}
|
|
21
25
|
|
|
22
26
|
callback(null, {
|
|
23
27
|
output
|
|
@@ -24,16 +24,15 @@ module.exports = function (script, {
|
|
|
24
24
|
if (ctorType === 'app') {
|
|
25
25
|
output += `
|
|
26
26
|
import { getComponent } from ${stringifyRequest(loaderContext, optionProcessorPath)}
|
|
27
|
-
import { NavigationContainer,
|
|
28
|
-
import {
|
|
27
|
+
import { NavigationContainer, StackActions } from '@react-navigation/native'
|
|
28
|
+
import { createStackNavigator } from '@react-navigation/stack'
|
|
29
29
|
import { Provider } from '@ant-design/react-native'
|
|
30
30
|
import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
31
31
|
import { GestureHandlerRootView } from 'react-native-gesture-handler'
|
|
32
32
|
|
|
33
33
|
global.__navigationHelper = {
|
|
34
34
|
NavigationContainer: NavigationContainer,
|
|
35
|
-
|
|
36
|
-
createNativeStackNavigator: createNativeStackNavigator,
|
|
35
|
+
createStackNavigator: createStackNavigator,
|
|
37
36
|
StackActions: StackActions,
|
|
38
37
|
GestureHandlerRootView: GestureHandlerRootView,
|
|
39
38
|
Provider: Provider,
|
|
@@ -14,7 +14,7 @@ module.exports = function (template, {
|
|
|
14
14
|
srcMode,
|
|
15
15
|
moduleId,
|
|
16
16
|
ctorType,
|
|
17
|
-
|
|
17
|
+
usingComponentsInfo,
|
|
18
18
|
componentGenerics
|
|
19
19
|
}, callback) {
|
|
20
20
|
const mpx = loaderContext.getMpx()
|
|
@@ -64,7 +64,7 @@ module.exports = function (template, {
|
|
|
64
64
|
const { root, meta } = templateCompiler.parse(template.content, {
|
|
65
65
|
warn,
|
|
66
66
|
error,
|
|
67
|
-
|
|
67
|
+
usingComponentsInfo, // processTemplate中无其他地方使用,直接透传 string 类型
|
|
68
68
|
hasComment,
|
|
69
69
|
isNative,
|
|
70
70
|
ctorType,
|
|
@@ -6,16 +6,17 @@ const addInfix = require('../utils/add-infix')
|
|
|
6
6
|
const { JSON_JS_EXT } = require('../utils/const')
|
|
7
7
|
|
|
8
8
|
module.exports = class AddModePlugin {
|
|
9
|
-
constructor (source, mode, fileConditionRules, target) {
|
|
9
|
+
constructor (source, mode, fileConditionRules, target, defaultMode) {
|
|
10
10
|
this.source = source
|
|
11
11
|
this.target = target
|
|
12
12
|
this.mode = mode
|
|
13
13
|
this.fileConditionRules = fileConditionRules
|
|
14
|
+
this.defaultMode = defaultMode
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
apply (resolver) {
|
|
17
18
|
const target = resolver.ensureHook(this.target)
|
|
18
|
-
const mode = this
|
|
19
|
+
const { defaultMode, mode } = this
|
|
19
20
|
resolver.getHook(this.source).tapAsync('AddModePlugin', (request, resolveContext, callback) => {
|
|
20
21
|
if (request.mode || request.env) {
|
|
21
22
|
return callback()
|
|
@@ -33,12 +34,24 @@ module.exports = class AddModePlugin {
|
|
|
33
34
|
// 当前资源没有后缀名或者路径不符合fileConditionRules规则时,直接返回
|
|
34
35
|
if (!extname || !matchCondition(resourcePath, this.fileConditionRules)) return callback()
|
|
35
36
|
const queryObj = parseQuery(request.query || '?')
|
|
37
|
+
const queryInfix = queryObj.infix
|
|
36
38
|
queryObj.mode = mode
|
|
37
|
-
queryObj.infix = `${
|
|
39
|
+
queryObj.infix = `${queryInfix || ''}.${mode}`
|
|
38
40
|
obj.query = stringifyQuery(queryObj)
|
|
39
41
|
obj.path = addInfix(resourcePath, mode, extname)
|
|
40
42
|
obj.relativePath = request.relativePath && addInfix(request.relativePath, mode, extname)
|
|
41
|
-
resolver.doResolve(target, Object.assign({}, request, obj), 'add mode: ' + mode, resolveContext,
|
|
43
|
+
resolver.doResolve(target, Object.assign({}, request, obj), 'add mode: ' + mode, resolveContext, (err, result) => {
|
|
44
|
+
if (this.defaultMode && !result) {
|
|
45
|
+
queryObj.infix = `${queryInfix || ''}.${defaultMode}`
|
|
46
|
+
obj.query = stringifyQuery(queryObj)
|
|
47
|
+
obj.path = addInfix(resourcePath, defaultMode, extname)
|
|
48
|
+
resolver.doResolve(target, Object.assign({}, request, obj), 'add mode: ' + this.defaultMode, resolveContext, (err, result) => {
|
|
49
|
+
callback(err, result)
|
|
50
|
+
})
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
callback(err, result)
|
|
54
|
+
})
|
|
42
55
|
})
|
|
43
56
|
}
|
|
44
57
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ✔ bindchange
|
|
3
3
|
*/
|
|
4
|
-
import { useRef, forwardRef, useContext } from 'react';
|
|
4
|
+
import { useRef, forwardRef, useContext, useMemo, useEffect } from 'react';
|
|
5
5
|
import { View } from 'react-native';
|
|
6
6
|
import { warn } from '@mpxjs/utils';
|
|
7
7
|
import { FormContext, CheckboxGroupContext } from './context';
|
|
@@ -9,7 +9,9 @@ import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
|
9
9
|
import useNodesRef from './useNodesRef';
|
|
10
10
|
import { useLayout, useTransformStyle, wrapChildren } from './utils';
|
|
11
11
|
const CheckboxGroup = forwardRef((props, ref) => {
|
|
12
|
-
const
|
|
12
|
+
const propsRef = useRef({});
|
|
13
|
+
propsRef.current = props;
|
|
14
|
+
const { style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
|
|
13
15
|
const formContext = useContext(FormContext);
|
|
14
16
|
let formValuesMap;
|
|
15
17
|
if (formContext) {
|
|
@@ -28,7 +30,7 @@ const CheckboxGroup = forwardRef((props, ref) => {
|
|
|
28
30
|
const nodeRef = useRef(null);
|
|
29
31
|
useNodesRef(props, ref, nodeRef, { defaultStyle });
|
|
30
32
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
|
|
31
|
-
const
|
|
33
|
+
const getValue = () => {
|
|
32
34
|
const arr = [];
|
|
33
35
|
for (const key in groupValue) {
|
|
34
36
|
if (groupValue[key].checked) {
|
|
@@ -37,9 +39,6 @@ const CheckboxGroup = forwardRef((props, ref) => {
|
|
|
37
39
|
}
|
|
38
40
|
return arr;
|
|
39
41
|
};
|
|
40
|
-
const getValue = () => {
|
|
41
|
-
return getSelectionValue();
|
|
42
|
-
};
|
|
43
42
|
const resetValue = () => {
|
|
44
43
|
Object.keys(groupValue).forEach((key) => {
|
|
45
44
|
groupValue[key].checked = false;
|
|
@@ -54,15 +53,13 @@ const CheckboxGroup = forwardRef((props, ref) => {
|
|
|
54
53
|
formValuesMap.set(props.name, { getValue, resetValue });
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}, props));
|
|
65
|
-
};
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
return () => {
|
|
58
|
+
if (formValuesMap && props.name) {
|
|
59
|
+
formValuesMap.delete(props.name);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}, []);
|
|
66
63
|
const innerProps = useInnerProps(props, {
|
|
67
64
|
ref: nodeRef,
|
|
68
65
|
style: { ...normalStyle, ...layoutStyle },
|
|
@@ -70,8 +67,24 @@ const CheckboxGroup = forwardRef((props, ref) => {
|
|
|
70
67
|
}, [], {
|
|
71
68
|
layoutRef
|
|
72
69
|
});
|
|
70
|
+
const contextValue = useMemo(() => {
|
|
71
|
+
const notifyChange = (evt) => {
|
|
72
|
+
const { bindchange } = propsRef.current;
|
|
73
|
+
bindchange &&
|
|
74
|
+
bindchange(getCustomEvent('tap', evt, {
|
|
75
|
+
layoutRef,
|
|
76
|
+
detail: {
|
|
77
|
+
value: getValue()
|
|
78
|
+
}
|
|
79
|
+
}, propsRef.current));
|
|
80
|
+
};
|
|
81
|
+
return {
|
|
82
|
+
groupValue,
|
|
83
|
+
notifyChange
|
|
84
|
+
};
|
|
85
|
+
}, []);
|
|
73
86
|
return (<View {...innerProps}>
|
|
74
|
-
<CheckboxGroupContext.Provider value={
|
|
87
|
+
<CheckboxGroupContext.Provider value={contextValue}>
|
|
75
88
|
{wrapChildren(props, {
|
|
76
89
|
hasVarDec,
|
|
77
90
|
varContext: varContextRef.current
|
|
@@ -79,5 +92,5 @@ const CheckboxGroup = forwardRef((props, ref) => {
|
|
|
79
92
|
</CheckboxGroupContext.Provider>
|
|
80
93
|
</View>);
|
|
81
94
|
});
|
|
82
|
-
CheckboxGroup.displayName = '
|
|
95
|
+
CheckboxGroup.displayName = 'MpxCheckboxGroup';
|
|
83
96
|
export default CheckboxGroup;
|
|
@@ -5,40 +5,21 @@
|
|
|
5
5
|
* ✔ bindreset
|
|
6
6
|
*/
|
|
7
7
|
import { View } from 'react-native';
|
|
8
|
-
import { useRef, forwardRef } from 'react';
|
|
8
|
+
import { useRef, forwardRef, useMemo } from 'react';
|
|
9
9
|
import useNodesRef from './useNodesRef';
|
|
10
10
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
11
11
|
import { FormContext } from './context';
|
|
12
12
|
import { useTransformStyle, splitProps, splitStyle, useLayout, wrapChildren } from './utils';
|
|
13
13
|
const _Form = forwardRef((fromProps, ref) => {
|
|
14
14
|
const { textProps, innerProps: props = {} } = splitProps(fromProps);
|
|
15
|
-
const formValuesMap = useRef(new Map()).current;
|
|
16
15
|
const { style, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
|
|
17
16
|
const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
18
17
|
const { textStyle, innerStyle } = splitStyle(normalStyle);
|
|
19
18
|
const formRef = useRef(null);
|
|
20
19
|
useNodesRef(props, ref, formRef);
|
|
20
|
+
const propsRef = useRef({});
|
|
21
|
+
propsRef.current = props;
|
|
21
22
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: formRef });
|
|
22
|
-
const submit = () => {
|
|
23
|
-
const { bindsubmit } = props;
|
|
24
|
-
const formValue = {};
|
|
25
|
-
for (const name of formValuesMap.keys()) {
|
|
26
|
-
if (formValuesMap.get(name).getValue) {
|
|
27
|
-
formValue[name] = formValuesMap.get(name).getValue();
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
bindsubmit && bindsubmit(getCustomEvent('submit', {}, {
|
|
31
|
-
detail: {
|
|
32
|
-
value: formValue
|
|
33
|
-
},
|
|
34
|
-
layoutRef
|
|
35
|
-
}, props));
|
|
36
|
-
};
|
|
37
|
-
const reset = () => {
|
|
38
|
-
const { bindreset } = props;
|
|
39
|
-
bindreset && bindreset();
|
|
40
|
-
formValuesMap.forEach(item => item.resetValue());
|
|
41
|
-
};
|
|
42
23
|
const innerProps = useInnerProps(props, {
|
|
43
24
|
style: { ...innerStyle, ...layoutStyle },
|
|
44
25
|
ref: formRef,
|
|
@@ -47,8 +28,36 @@ const _Form = forwardRef((fromProps, ref) => {
|
|
|
47
28
|
'bindsubmit',
|
|
48
29
|
'bindreset'
|
|
49
30
|
], { layoutRef });
|
|
31
|
+
const contextValue = useMemo(() => {
|
|
32
|
+
const formValuesMap = new Map();
|
|
33
|
+
const submit = () => {
|
|
34
|
+
const { bindsubmit } = propsRef.current;
|
|
35
|
+
const formValue = {};
|
|
36
|
+
for (const name of formValuesMap.keys()) {
|
|
37
|
+
if (formValuesMap.get(name).getValue) {
|
|
38
|
+
formValue[name] = formValuesMap.get(name).getValue();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
bindsubmit && bindsubmit(getCustomEvent('submit', {}, {
|
|
42
|
+
detail: {
|
|
43
|
+
value: formValue
|
|
44
|
+
},
|
|
45
|
+
layoutRef
|
|
46
|
+
}, propsRef.current));
|
|
47
|
+
};
|
|
48
|
+
const reset = () => {
|
|
49
|
+
const { bindreset } = propsRef.current;
|
|
50
|
+
bindreset && bindreset();
|
|
51
|
+
formValuesMap.forEach(item => item.resetValue());
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
formValuesMap,
|
|
55
|
+
submit,
|
|
56
|
+
reset
|
|
57
|
+
};
|
|
58
|
+
}, []);
|
|
50
59
|
return (<View {...innerProps}>
|
|
51
|
-
<FormContext.Provider value={
|
|
60
|
+
<FormContext.Provider value={contextValue}>
|
|
52
61
|
{wrapChildren(props, {
|
|
53
62
|
hasVarDec,
|
|
54
63
|
varContext: varContextRef.current,
|
|
@@ -58,5 +67,5 @@ const _Form = forwardRef((fromProps, ref) => {
|
|
|
58
67
|
</FormContext.Provider>
|
|
59
68
|
</View>);
|
|
60
69
|
});
|
|
61
|
-
_Form.displayName = '
|
|
70
|
+
_Form.displayName = 'MpxForm';
|
|
62
71
|
export default _Form;
|
|
@@ -121,27 +121,24 @@ const Input = forwardRef((props, ref) => {
|
|
|
121
121
|
}
|
|
122
122
|
};
|
|
123
123
|
const onInputFocus = (evt) => {
|
|
124
|
-
bindfocus
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}, props));
|
|
124
|
+
bindfocus(getCustomEvent('focus', evt, {
|
|
125
|
+
detail: {
|
|
126
|
+
value: tmpValue.current || ''
|
|
127
|
+
},
|
|
128
|
+
layoutRef
|
|
129
|
+
}, props));
|
|
131
130
|
};
|
|
132
131
|
const onInputBlur = (evt) => {
|
|
133
|
-
bindblur
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}, props));
|
|
132
|
+
bindblur(getCustomEvent('blur', evt, {
|
|
133
|
+
detail: {
|
|
134
|
+
value: tmpValue.current || '',
|
|
135
|
+
cursor: cursorIndex.current
|
|
136
|
+
},
|
|
137
|
+
layoutRef
|
|
138
|
+
}, props));
|
|
141
139
|
};
|
|
142
140
|
const onKeyPress = (evt) => {
|
|
143
|
-
|
|
144
|
-
evt.nativeEvent.key === 'Enter' &&
|
|
141
|
+
evt.nativeEvent.key === 'Enter' &&
|
|
145
142
|
bindconfirm(getCustomEvent('confirm', evt, {
|
|
146
143
|
detail: {
|
|
147
144
|
value: tmpValue.current || ''
|
|
@@ -150,14 +147,21 @@ const Input = forwardRef((props, ref) => {
|
|
|
150
147
|
}, props));
|
|
151
148
|
};
|
|
152
149
|
const onSubmitEditing = (evt) => {
|
|
153
|
-
bindconfirm
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
150
|
+
bindconfirm(getCustomEvent('confirm', evt, {
|
|
151
|
+
detail: {
|
|
152
|
+
value: tmpValue.current || ''
|
|
153
|
+
},
|
|
154
|
+
layoutRef
|
|
155
|
+
}, props));
|
|
156
|
+
};
|
|
157
|
+
const onSelectionChange = (evt) => {
|
|
158
|
+
bindselectionchange(getCustomEvent('selectionchange', evt, {
|
|
159
|
+
detail: {
|
|
160
|
+
selectionStart: evt.nativeEvent.selection.start,
|
|
161
|
+
selectionEnd: evt.nativeEvent.selection.end
|
|
162
|
+
},
|
|
163
|
+
layoutRef
|
|
164
|
+
}, props));
|
|
161
165
|
};
|
|
162
166
|
const onContentSizeChange = (evt) => {
|
|
163
167
|
const { width, height } = evt.nativeEvent.contentSize;
|
|
@@ -178,16 +182,6 @@ const Input = forwardRef((props, ref) => {
|
|
|
178
182
|
setContentHeight(height);
|
|
179
183
|
}
|
|
180
184
|
};
|
|
181
|
-
const onSelectionChange = (evt) => {
|
|
182
|
-
bindselectionchange &&
|
|
183
|
-
bindselectionchange(getCustomEvent('selectionchange', evt, {
|
|
184
|
-
detail: {
|
|
185
|
-
selectionStart: evt.nativeEvent.selection.start,
|
|
186
|
-
selectionEnd: evt.nativeEvent.selection.end
|
|
187
|
-
},
|
|
188
|
-
layoutRef
|
|
189
|
-
}, props));
|
|
190
|
-
};
|
|
191
185
|
const resetValue = () => {
|
|
192
186
|
setInputValue('');
|
|
193
187
|
};
|
|
@@ -202,6 +196,13 @@ const Input = forwardRef((props, ref) => {
|
|
|
202
196
|
formValuesMap.set(props.name, { getValue, resetValue });
|
|
203
197
|
}
|
|
204
198
|
}
|
|
199
|
+
useEffect(() => {
|
|
200
|
+
return () => {
|
|
201
|
+
if (formValuesMap && props.name) {
|
|
202
|
+
formValuesMap.delete(props.name);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}, []);
|
|
205
206
|
useUpdateEffect(() => {
|
|
206
207
|
if (!nodeRef?.current) {
|
|
207
208
|
return;
|
|
@@ -220,11 +221,16 @@ const Input = forwardRef((props, ref) => {
|
|
|
220
221
|
height: Math.max(composeStyle?.minHeight || 35, contentHeight)
|
|
221
222
|
}
|
|
222
223
|
},
|
|
223
|
-
...layoutProps
|
|
224
|
+
...layoutProps,
|
|
225
|
+
onFocus: bindfocus && onInputFocus,
|
|
226
|
+
onBlur: bindblur && onInputBlur,
|
|
227
|
+
onKeyPress: bindconfirm && onKeyPress,
|
|
228
|
+
onSubmitEditing: bindconfirm && multiline && onSubmitEditing,
|
|
229
|
+
onSelectionChange: bindselectionchange && onSelectionChange
|
|
224
230
|
}, [], {
|
|
225
231
|
layoutRef
|
|
226
232
|
});
|
|
227
|
-
return (<TextInput {...innerProps} keyboardType={keyboardType} secureTextEntry={!!password} defaultValue={defaultValue} value={inputValue} maxLength={maxlength === -1 ? undefined : maxlength} editable={!disabled} autoFocus={!!autoFocus || !!focus} returnKeyType={confirmType} selection={selection} selectionColor={cursorColor} blurOnSubmit={!multiline && !confirmHold} underlineColorAndroid="rgba(0,0,0,0)" textAlignVertical={textAlignVertical} placeholderTextColor={placeholderTextColor} multiline={!!multiline} onTextInput={onTextInput} onChange={onChange}
|
|
233
|
+
return (<TextInput {...innerProps} keyboardType={keyboardType} secureTextEntry={!!password} defaultValue={defaultValue} value={inputValue} maxLength={maxlength === -1 ? undefined : maxlength} editable={!disabled} autoFocus={!!autoFocus || !!focus} returnKeyType={confirmType} selection={selection} selectionColor={cursorColor} blurOnSubmit={!multiline && !confirmHold} underlineColorAndroid="rgba(0,0,0,0)" textAlignVertical={textAlignVertical} placeholderTextColor={placeholderTextColor} multiline={!!multiline} onTextInput={onTextInput} onChange={onChange} onContentSizeChange={onContentSizeChange}/>);
|
|
228
234
|
});
|
|
229
|
-
Input.displayName = '
|
|
235
|
+
Input.displayName = 'MpxInput';
|
|
230
236
|
export default Input;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ✘ for
|
|
3
3
|
*/
|
|
4
|
-
import { useRef, forwardRef } from 'react';
|
|
4
|
+
import { useRef, forwardRef, useCallback } from 'react';
|
|
5
5
|
import { View } from 'react-native';
|
|
6
6
|
import { noop, warn } from '@mpxjs/utils';
|
|
7
7
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
@@ -10,7 +10,9 @@ import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } fr
|
|
|
10
10
|
import { LabelContext } from './context';
|
|
11
11
|
const Label = forwardRef((labelProps, ref) => {
|
|
12
12
|
const { textProps, innerProps: props = {} } = splitProps(labelProps);
|
|
13
|
-
const
|
|
13
|
+
const propsRef = useRef({});
|
|
14
|
+
const { style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
|
|
15
|
+
propsRef.current = props;
|
|
14
16
|
const defaultStyle = {
|
|
15
17
|
flexDirection: 'row'
|
|
16
18
|
};
|
|
@@ -29,10 +31,11 @@ const Label = forwardRef((labelProps, ref) => {
|
|
|
29
31
|
const contextRef = useRef({
|
|
30
32
|
triggerChange: noop
|
|
31
33
|
});
|
|
32
|
-
const onTap = (evt) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
const onTap = useCallback((evt) => {
|
|
35
|
+
const { bindtap } = propsRef.current;
|
|
36
|
+
bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, { props: propsRef.current }));
|
|
37
|
+
contextRef.current.triggerChange(evt);
|
|
38
|
+
}, []);
|
|
36
39
|
const innerProps = useInnerProps(props, {
|
|
37
40
|
ref: nodeRef,
|
|
38
41
|
style: { ...innerStyle, ...layoutStyle },
|
|
@@ -52,5 +55,5 @@ const Label = forwardRef((labelProps, ref) => {
|
|
|
52
55
|
</LabelContext.Provider>
|
|
53
56
|
</View>;
|
|
54
57
|
});
|
|
55
|
-
Label.displayName = '
|
|
58
|
+
Label.displayName = 'MpxLabel';
|
|
56
59
|
export default Label;
|
|
@@ -2,34 +2,27 @@
|
|
|
2
2
|
* ✘ scale-area
|
|
3
3
|
*/
|
|
4
4
|
import { View } from 'react-native';
|
|
5
|
-
import {
|
|
5
|
+
import { forwardRef, useRef, useMemo } from 'react';
|
|
6
6
|
import useNodesRef from './useNodesRef';
|
|
7
7
|
import useInnerProps from './getInnerListeners';
|
|
8
8
|
import { MovableAreaContext } from './context';
|
|
9
9
|
import { useTransformStyle, wrapChildren, useLayout } from './utils';
|
|
10
10
|
const _MovableArea = forwardRef((props, ref) => {
|
|
11
|
-
const { style = {},
|
|
12
|
-
const [areaWidth, setAreaWidth] = useState(0);
|
|
13
|
-
const [areaHeight, setAreaHeight] = useState(0);
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
setAreaWidth(width);
|
|
16
|
-
setAreaHeight(height);
|
|
17
|
-
}, [width, height]);
|
|
11
|
+
const { style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
|
|
18
12
|
const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
19
13
|
const movableViewRef = useRef(null);
|
|
20
14
|
useNodesRef(props, ref, movableViewRef);
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: movableViewRef, onLayout });
|
|
15
|
+
const contextValue = useMemo(() => ({
|
|
16
|
+
height: normalStyle.height || 10,
|
|
17
|
+
width: normalStyle.width || 10
|
|
18
|
+
}), [normalStyle.width, normalStyle.height]);
|
|
19
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: movableViewRef });
|
|
27
20
|
const innerProps = useInnerProps(props, {
|
|
28
|
-
style: { height:
|
|
21
|
+
style: { height: contextValue.height, width: contextValue.width, overflow: 'hidden', ...normalStyle, ...layoutStyle },
|
|
29
22
|
ref: movableViewRef,
|
|
30
23
|
...layoutProps
|
|
31
24
|
}, [], { layoutRef });
|
|
32
|
-
return (<MovableAreaContext.Provider value={
|
|
25
|
+
return (<MovableAreaContext.Provider value={contextValue}>
|
|
33
26
|
<View {...innerProps}>
|
|
34
27
|
{wrapChildren(props, {
|
|
35
28
|
hasVarDec,
|
|
@@ -38,5 +31,5 @@ const _MovableArea = forwardRef((props, ref) => {
|
|
|
38
31
|
</View>
|
|
39
32
|
</MovableAreaContext.Provider>);
|
|
40
33
|
});
|
|
41
|
-
_MovableArea.displayName = '
|
|
34
|
+
_MovableArea.displayName = 'MpxMovableArea';
|
|
42
35
|
export default _MovableArea;
|