@mpxjs/webpack-plugin 2.9.67 → 2.9.69-beta.0
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/index.js +13 -8
- package/lib/platform/json/wx/index.js +21 -8
- package/lib/platform/style/wx/index.js +35 -38
- package/lib/platform/template/wx/component-config/canvas.js +8 -0
- package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
- package/lib/platform/template/wx/component-config/index.js +1 -1
- package/lib/platform/template/wx/component-config/input.js +1 -1
- package/lib/platform/template/wx/component-config/rich-text.js +8 -0
- package/lib/platform/template/wx/component-config/swiper.js +1 -1
- package/lib/platform/template/wx/component-config/textarea.js +1 -1
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/react/processStyles.js +14 -4
- package/lib/react/processTemplate.js +3 -0
- package/lib/resolver/AddModePlugin.js +8 -8
- package/lib/runtime/components/react/context.ts +6 -0
- package/lib/runtime/components/react/dist/context.js +2 -0
- package/lib/runtime/components/react/dist/event.config.js +24 -24
- package/lib/runtime/components/react/dist/getInnerListeners.js +183 -174
- package/lib/runtime/components/react/dist/mpx-button.jsx +77 -49
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
- package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
- package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
- package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
- package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
- package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +160 -88
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
- package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
- package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +606 -0
- package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
- package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
- package/lib/runtime/components/react/dist/mpx-view.jsx +65 -61
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +112 -35
- package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
- package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
- package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
- package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -9
- package/lib/runtime/components/react/dist/utils.jsx +70 -23
- package/lib/runtime/components/react/event.config.ts +25 -26
- package/lib/runtime/components/react/getInnerListeners.ts +237 -199
- package/lib/runtime/components/react/mpx-button.tsx +104 -57
- package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
- package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
- package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
- package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
- package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
- package/lib/runtime/components/react/mpx-canvas/index.tsx +296 -0
- package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
- package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
- package/lib/runtime/components/react/mpx-form.tsx +25 -28
- package/lib/runtime/components/react/mpx-icon.tsx +12 -17
- package/lib/runtime/components/react/mpx-image.tsx +436 -0
- package/lib/runtime/components/react/mpx-input.tsx +77 -57
- package/lib/runtime/components/react/mpx-label.tsx +26 -27
- package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
- package/lib/runtime/components/react/mpx-movable-view.tsx +21 -25
- package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
- package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
- package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +236 -104
- package/lib/runtime/components/react/mpx-picker-view.tsx +132 -122
- package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
- package/lib/runtime/components/react/mpx-radio.tsx +45 -54
- package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
- package/lib/runtime/components/react/mpx-scroll-view.tsx +72 -71
- package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
- package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
- package/lib/runtime/components/react/mpx-switch.tsx +29 -23
- package/lib/runtime/components/react/mpx-text.tsx +14 -18
- package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
- package/lib/runtime/components/react/mpx-view.tsx +92 -76
- package/lib/runtime/components/react/mpx-web-view.tsx +116 -54
- package/lib/runtime/components/react/pickerFaces.ts +104 -0
- package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
- package/lib/runtime/components/react/types/common.ts +2 -0
- package/lib/runtime/components/react/types/global.d.ts +5 -17
- package/lib/runtime/components/react/useAnimationHooks.ts +36 -11
- package/lib/runtime/components/react/utils.tsx +99 -28
- package/lib/runtime/components/web/getInnerListeners.js +6 -6
- package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
- package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
- package/lib/runtime/components/web/mpx-picker.vue +382 -385
- package/lib/runtime/components/web/mpx-web-view.vue +175 -161
- package/lib/runtime/optionProcessor.js +7 -38
- package/lib/runtime/utils.js +2 -0
- package/lib/style-compiler/plugins/scope-id.js +30 -2
- package/lib/template-compiler/bind-this.js +7 -2
- package/lib/template-compiler/compiler.js +79 -47
- package/lib/template-compiler/gen-node-react.js +3 -3
- package/lib/utils/pre-process-json.js +9 -5
- package/package.json +6 -4
- package/LICENSE +0 -433
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
- package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
- package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
- package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
- package/lib/runtime/components/web/event.js +0 -105
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react'
|
|
2
|
+
import { WebView } from 'react-native-webview'
|
|
3
|
+
import Bus from './Bus'
|
|
4
|
+
|
|
5
|
+
export const WEBVIEW_TARGET = '@@WEBVIEW_TARGET'
|
|
6
|
+
|
|
7
|
+
export const constructors: Record<string, any> = {}
|
|
8
|
+
|
|
9
|
+
export const ID = () => Math.random().toString(32).slice(2)
|
|
10
|
+
|
|
11
|
+
const SPECIAL_CONSTRUCTOR: Record<string, { className: string, paramNum: number }> = {
|
|
12
|
+
ImageData: {
|
|
13
|
+
className: 'Uint8ClampedArray',
|
|
14
|
+
paramNum: 0
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface Instance {
|
|
19
|
+
postMessage: (...args: any[]) => void;
|
|
20
|
+
[WEBVIEW_TARGET]?: string;
|
|
21
|
+
[key: string]: any;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface WebviewConstructor {
|
|
25
|
+
new (...args: any[]): Instance;
|
|
26
|
+
constructLocally?: (...args: unknown[]) => Instance;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface WebviewMessage {
|
|
30
|
+
type: 'set' | 'exec' | 'listen' | 'event' | 'construct'
|
|
31
|
+
payload: {
|
|
32
|
+
target?: string | { [key: string]: any }
|
|
33
|
+
key?: string
|
|
34
|
+
value?: any
|
|
35
|
+
method?: string
|
|
36
|
+
args?: any[]
|
|
37
|
+
types?: string[]
|
|
38
|
+
type?: string
|
|
39
|
+
constructor?: string | Function
|
|
40
|
+
id?: string
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface CanvasInstance {
|
|
45
|
+
webview: WebView | null;
|
|
46
|
+
bus: Bus | null;
|
|
47
|
+
context2D: CanvasRenderingContext2D;
|
|
48
|
+
getContext: (contextType: string) => CanvasRenderingContext2D | null;
|
|
49
|
+
createImage: (width?: number, height?: number) => any;
|
|
50
|
+
postMessage: (message: WebviewMessage) => Promise<any>;
|
|
51
|
+
listeners: Array<(payload: any) => void>;
|
|
52
|
+
addMessageListener: (listener: (payload: any) => void) => () => void;
|
|
53
|
+
removeMessageListener: (listener: (payload: any) => void) => void;
|
|
54
|
+
createImageData: (dataArray: number[], width?: number, height?: number) => any;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const registerWebviewTarget = (instance: Instance, targetName: string): void => {
|
|
58
|
+
instance[WEBVIEW_TARGET] = targetName
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const registerWebviewProperties = (instance: Instance, properties: Record<string, any>): void => {
|
|
62
|
+
Object.entries(properties).forEach(([key, initialValue]) => {
|
|
63
|
+
const privateKey = `__${key}__`
|
|
64
|
+
instance[privateKey] = initialValue
|
|
65
|
+
Object.defineProperty(instance, key, {
|
|
66
|
+
configurable: true,
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get () {
|
|
69
|
+
return instance[privateKey]
|
|
70
|
+
},
|
|
71
|
+
set (value) {
|
|
72
|
+
instance.postMessage({
|
|
73
|
+
type: 'set',
|
|
74
|
+
payload: {
|
|
75
|
+
target: instance[WEBVIEW_TARGET],
|
|
76
|
+
key,
|
|
77
|
+
value
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
if (instance.forceUpdate) {
|
|
82
|
+
instance.forceUpdate()
|
|
83
|
+
}
|
|
84
|
+
return (instance[privateKey] = value)
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const registerWebviewMethods = (instance: Instance, methods: string[]): void => {
|
|
91
|
+
methods.forEach(method => {
|
|
92
|
+
instance[method] = (...args: any[]) => {
|
|
93
|
+
return instance.postMessage({
|
|
94
|
+
type: 'exec',
|
|
95
|
+
payload: {
|
|
96
|
+
target: instance[WEBVIEW_TARGET],
|
|
97
|
+
method,
|
|
98
|
+
args
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export const registerWebviewConstructor = (constructor: WebviewConstructor, constructorName: string): void => {
|
|
106
|
+
constructors[constructorName] = constructor
|
|
107
|
+
constructor.constructLocally = function (...args: unknown[]): Instance {
|
|
108
|
+
return new (constructor as any)(...args, true)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
constructor.prototype.onConstruction = function (...args: any[]): void {
|
|
112
|
+
if (SPECIAL_CONSTRUCTOR[constructorName] !== undefined) {
|
|
113
|
+
const { className, paramNum } = SPECIAL_CONSTRUCTOR[constructorName]
|
|
114
|
+
args[paramNum] = { className, classArgs: [args[paramNum]] }
|
|
115
|
+
}
|
|
116
|
+
this[WEBVIEW_TARGET] = ID()
|
|
117
|
+
this.postMessage({
|
|
118
|
+
type: 'construct',
|
|
119
|
+
payload: {
|
|
120
|
+
constructor: constructorName,
|
|
121
|
+
id: this[WEBVIEW_TARGET],
|
|
122
|
+
args
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
constructor.prototype.toJSON = function () {
|
|
127
|
+
return { __ref__: this[WEBVIEW_TARGET] }
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
export const useWebviewBinding = ({
|
|
131
|
+
targetName,
|
|
132
|
+
properties = {},
|
|
133
|
+
methods = []
|
|
134
|
+
}: {
|
|
135
|
+
targetName: string;
|
|
136
|
+
properties?: Record<string, any>;
|
|
137
|
+
methods?: string[]
|
|
138
|
+
}) => {
|
|
139
|
+
const instanceRef = useRef({})
|
|
140
|
+
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
if (instanceRef.current) {
|
|
143
|
+
registerWebviewTarget(instanceRef.current as Instance, targetName)
|
|
144
|
+
registerWebviewProperties(instanceRef.current as Instance, properties)
|
|
145
|
+
registerWebviewMethods(instanceRef.current as Instance, methods)
|
|
146
|
+
}
|
|
147
|
+
}, [])
|
|
148
|
+
|
|
149
|
+
return instanceRef
|
|
150
|
+
}
|
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
ReactNode,
|
|
9
9
|
useContext,
|
|
10
10
|
useMemo,
|
|
11
|
-
useEffect
|
|
11
|
+
useEffect,
|
|
12
|
+
createElement
|
|
12
13
|
} from 'react'
|
|
13
14
|
import {
|
|
14
15
|
View,
|
|
@@ -19,7 +20,7 @@ import { warn } from '@mpxjs/utils'
|
|
|
19
20
|
import { FormContext, FormFieldValue, CheckboxGroupContext, GroupValue } from './context'
|
|
20
21
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
21
22
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
22
|
-
import { useLayout, useTransformStyle, wrapChildren } from './utils'
|
|
23
|
+
import { useLayout, useTransformStyle, wrapChildren, extendObject } from './utils'
|
|
23
24
|
|
|
24
25
|
export interface CheckboxGroupProps {
|
|
25
26
|
name: string
|
|
@@ -64,10 +65,7 @@ const CheckboxGroup = forwardRef<
|
|
|
64
65
|
flexWrap: 'wrap'
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
const styleObj = {
|
|
68
|
-
...defaultStyle,
|
|
69
|
-
...style
|
|
70
|
-
}
|
|
68
|
+
const styleObj = extendObject({}, defaultStyle, style)
|
|
71
69
|
|
|
72
70
|
const {
|
|
73
71
|
hasSelfPercent,
|
|
@@ -80,7 +78,7 @@ const CheckboxGroup = forwardRef<
|
|
|
80
78
|
|
|
81
79
|
const nodeRef = useRef(null)
|
|
82
80
|
|
|
83
|
-
useNodesRef(props, ref, nodeRef, {
|
|
81
|
+
useNodesRef(props, ref, nodeRef, { style: normalStyle })
|
|
84
82
|
|
|
85
83
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
|
|
86
84
|
|
|
@@ -119,12 +117,16 @@ const CheckboxGroup = forwardRef<
|
|
|
119
117
|
|
|
120
118
|
const innerProps = useInnerProps(
|
|
121
119
|
props,
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
120
|
+
extendObject(
|
|
121
|
+
{
|
|
122
|
+
ref: nodeRef,
|
|
123
|
+
style: extendObject({}, normalStyle, layoutStyle)
|
|
124
|
+
},
|
|
125
|
+
layoutProps
|
|
126
|
+
),
|
|
127
|
+
[
|
|
128
|
+
'name'
|
|
129
|
+
],
|
|
128
130
|
{
|
|
129
131
|
layoutRef
|
|
130
132
|
}
|
|
@@ -155,20 +157,21 @@ const CheckboxGroup = forwardRef<
|
|
|
155
157
|
notifyChange
|
|
156
158
|
}
|
|
157
159
|
}, [])
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
160
|
+
|
|
161
|
+
return createElement(
|
|
162
|
+
View,
|
|
163
|
+
innerProps,
|
|
164
|
+
createElement(
|
|
165
|
+
CheckboxGroupContext.Provider,
|
|
166
|
+
{ value: contextValue },
|
|
167
|
+
wrapChildren(
|
|
168
|
+
props,
|
|
161
169
|
{
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
{
|
|
165
|
-
hasVarDec,
|
|
166
|
-
varContext: varContextRef.current
|
|
167
|
-
}
|
|
168
|
-
)
|
|
170
|
+
hasVarDec,
|
|
171
|
+
varContext: varContextRef.current
|
|
169
172
|
}
|
|
170
|
-
|
|
171
|
-
|
|
173
|
+
)
|
|
174
|
+
)
|
|
172
175
|
)
|
|
173
176
|
})
|
|
174
177
|
|
|
@@ -13,7 +13,8 @@ import {
|
|
|
13
13
|
ReactNode,
|
|
14
14
|
useContext,
|
|
15
15
|
Dispatch,
|
|
16
|
-
SetStateAction
|
|
16
|
+
SetStateAction,
|
|
17
|
+
createElement
|
|
17
18
|
} from 'react'
|
|
18
19
|
import {
|
|
19
20
|
View,
|
|
@@ -25,7 +26,7 @@ import { warn } from '@mpxjs/utils'
|
|
|
25
26
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
26
27
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
27
28
|
import Icon from './mpx-icon'
|
|
28
|
-
import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils'
|
|
29
|
+
import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject } from './utils'
|
|
29
30
|
import { CheckboxGroupContext, LabelContext } from './context'
|
|
30
31
|
|
|
31
32
|
interface Selection {
|
|
@@ -46,7 +47,7 @@ export interface CheckboxProps extends Selection {
|
|
|
46
47
|
'parent-height'?: number;
|
|
47
48
|
children?: ReactNode
|
|
48
49
|
bindtap?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
49
|
-
|
|
50
|
+
_onChange?: (evt: NativeSyntheticEvent<TouchEvent> | unknown, { checked }: { checked: boolean }) => void
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
const styles = StyleSheet.create({
|
|
@@ -92,7 +93,7 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
|
|
|
92
93
|
'parent-width': parentWidth,
|
|
93
94
|
'parent-height': parentHeight,
|
|
94
95
|
bindtap,
|
|
95
|
-
|
|
96
|
+
_onChange
|
|
96
97
|
} = props
|
|
97
98
|
|
|
98
99
|
const [isChecked, setIsChecked] = useState<boolean>(!!checked)
|
|
@@ -101,15 +102,13 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
|
|
|
101
102
|
let groupValue: { [key: string]: { checked: boolean; setValue: Dispatch<SetStateAction<boolean>>; } } | undefined
|
|
102
103
|
let notifyChange: (evt: NativeSyntheticEvent<TouchEvent>) => void | undefined
|
|
103
104
|
|
|
104
|
-
const defaultStyle =
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
const defaultStyle = extendObject(
|
|
106
|
+
{},
|
|
107
|
+
styles.wrapper,
|
|
108
|
+
disabled ? styles.wrapperDisabled : null
|
|
109
|
+
)
|
|
108
110
|
|
|
109
|
-
const styleObj = {
|
|
110
|
-
...styles.container,
|
|
111
|
-
...style
|
|
112
|
-
}
|
|
111
|
+
const styleObj = extendObject({}, styles.container, style)
|
|
113
112
|
|
|
114
113
|
const onChange = (evt: NativeSyntheticEvent<TouchEvent>) => {
|
|
115
114
|
if (disabled) return
|
|
@@ -119,20 +118,15 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
|
|
|
119
118
|
groupValue[value].checked = checked
|
|
120
119
|
}
|
|
121
120
|
notifyChange && notifyChange(evt)
|
|
121
|
+
// Called when the switch type attribute is checkbox
|
|
122
|
+
_onChange && _onChange(evt, { checked })
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
const onTap = (evt: NativeSyntheticEvent<TouchEvent>) => {
|
|
125
|
-
if (disabled) return
|
|
126
126
|
bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, props))
|
|
127
127
|
onChange(evt)
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
const catchTap = (evt: NativeSyntheticEvent<TouchEvent>) => {
|
|
131
|
-
if (disabled) return
|
|
132
|
-
catchtap && catchtap(getCustomEvent('tap', evt, { layoutRef }, props))
|
|
133
|
-
onChange(evt)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
130
|
const {
|
|
137
131
|
hasSelfPercent,
|
|
138
132
|
normalStyle,
|
|
@@ -145,13 +139,13 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
|
|
|
145
139
|
const nodeRef = useRef(null)
|
|
146
140
|
|
|
147
141
|
useNodesRef(props, ref, nodeRef, {
|
|
148
|
-
defaultStyle,
|
|
142
|
+
style: extendObject({}, defaultStyle, normalStyle),
|
|
149
143
|
change: onChange
|
|
150
144
|
})
|
|
151
145
|
|
|
152
146
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
|
|
153
147
|
|
|
154
|
-
const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle)
|
|
148
|
+
const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle)
|
|
155
149
|
|
|
156
150
|
if (backgroundStyle) {
|
|
157
151
|
warn('Checkbox does not support background image-related styles!')
|
|
@@ -170,14 +164,21 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
|
|
|
170
164
|
|
|
171
165
|
const innerProps = useInnerProps(
|
|
172
166
|
props,
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
167
|
+
extendObject(
|
|
168
|
+
{
|
|
169
|
+
ref: nodeRef,
|
|
170
|
+
style: extendObject({}, innerStyle, layoutStyle)
|
|
171
|
+
},
|
|
172
|
+
layoutProps,
|
|
173
|
+
{
|
|
174
|
+
bindtap: !disabled && onTap
|
|
175
|
+
}
|
|
176
|
+
),
|
|
177
|
+
[
|
|
178
|
+
'value',
|
|
179
|
+
'disabled',
|
|
180
|
+
'checked'
|
|
181
|
+
],
|
|
181
182
|
{
|
|
182
183
|
layoutRef
|
|
183
184
|
}
|
|
@@ -206,28 +207,26 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
|
|
|
206
207
|
}
|
|
207
208
|
}, [checked])
|
|
208
209
|
|
|
209
|
-
return (
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
210
|
+
return createElement(View, innerProps,
|
|
211
|
+
createElement(
|
|
212
|
+
View,
|
|
213
|
+
{ style: defaultStyle },
|
|
214
|
+
createElement(Icon, {
|
|
215
|
+
type: 'success_no_circle',
|
|
216
|
+
size: 18,
|
|
217
|
+
color: disabled ? '#ADADAD' : color,
|
|
218
|
+
style: isChecked ? styles.iconChecked : styles.icon
|
|
219
|
+
})
|
|
220
|
+
),
|
|
221
|
+
wrapChildren(
|
|
222
|
+
props,
|
|
219
223
|
{
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
varContext: varContextRef.current,
|
|
225
|
-
textStyle,
|
|
226
|
-
textProps
|
|
227
|
-
}
|
|
228
|
-
)
|
|
224
|
+
hasVarDec,
|
|
225
|
+
varContext: varContextRef.current,
|
|
226
|
+
textStyle,
|
|
227
|
+
textProps
|
|
229
228
|
}
|
|
230
|
-
|
|
229
|
+
)
|
|
231
230
|
)
|
|
232
231
|
}
|
|
233
232
|
)
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* ✔ bindreset
|
|
6
6
|
*/
|
|
7
7
|
import { View } from 'react-native'
|
|
8
|
-
import { JSX, useRef, forwardRef, ReactNode, useMemo,
|
|
8
|
+
import { JSX, useRef, forwardRef, ReactNode, useMemo, createElement } from 'react'
|
|
9
9
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
10
10
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
11
11
|
import { FormContext } from './context'
|
|
12
|
-
import { useTransformStyle, splitProps, splitStyle, useLayout, wrapChildren } from './utils'
|
|
12
|
+
import { useTransformStyle, splitProps, splitStyle, useLayout, wrapChildren, extendObject } from './utils'
|
|
13
13
|
interface FormProps {
|
|
14
14
|
style?: Record<string, any>;
|
|
15
15
|
children?: ReactNode;
|
|
@@ -47,21 +47,23 @@ const _Form = forwardRef<HandlerRef<View, FormProps>, FormProps>((fromProps: For
|
|
|
47
47
|
setHeight
|
|
48
48
|
} = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
49
49
|
|
|
50
|
-
const { textStyle, innerStyle } = splitStyle(normalStyle)
|
|
50
|
+
const { textStyle, innerStyle = {} } = splitStyle(normalStyle)
|
|
51
51
|
|
|
52
52
|
const formRef = useRef(null)
|
|
53
|
-
useNodesRef(props, ref, formRef
|
|
53
|
+
useNodesRef(props, ref, formRef, {
|
|
54
|
+
style: normalStyle
|
|
55
|
+
})
|
|
54
56
|
|
|
55
57
|
const propsRef = useRef<FormProps>({})
|
|
56
58
|
propsRef.current = props
|
|
57
59
|
|
|
58
60
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: formRef })
|
|
59
61
|
|
|
60
|
-
const innerProps = useInnerProps(props, {
|
|
61
|
-
style: {
|
|
62
|
-
ref: formRef
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
const innerProps = useInnerProps(props, extendObject({
|
|
63
|
+
style: extendObject({}, innerStyle, layoutStyle),
|
|
64
|
+
ref: formRef
|
|
65
|
+
}, layoutProps)
|
|
66
|
+
, [
|
|
65
67
|
'bindsubmit',
|
|
66
68
|
'bindreset'
|
|
67
69
|
], { layoutRef })
|
|
@@ -100,25 +102,20 @@ const _Form = forwardRef<HandlerRef<View, FormProps>, FormProps>((fromProps: For
|
|
|
100
102
|
reset
|
|
101
103
|
}
|
|
102
104
|
}, [])
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
)
|
|
118
|
-
}
|
|
119
|
-
</FormContext.Provider>
|
|
120
|
-
</View>
|
|
121
|
-
)
|
|
105
|
+
|
|
106
|
+
return createElement(View, innerProps, createElement(
|
|
107
|
+
FormContext.Provider,
|
|
108
|
+
{ value: contextValue },
|
|
109
|
+
wrapChildren(
|
|
110
|
+
props,
|
|
111
|
+
{
|
|
112
|
+
hasVarDec,
|
|
113
|
+
varContext: varContextRef.current,
|
|
114
|
+
textStyle,
|
|
115
|
+
textProps
|
|
116
|
+
}
|
|
117
|
+
)
|
|
118
|
+
))
|
|
122
119
|
})
|
|
123
120
|
|
|
124
121
|
_Form.displayName = 'MpxForm'
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* ✔ size
|
|
4
4
|
* ✔ color
|
|
5
5
|
*/
|
|
6
|
-
import { JSX, forwardRef, useRef } from 'react'
|
|
6
|
+
import { JSX, forwardRef, useRef, createElement } from 'react'
|
|
7
7
|
import { Text, TextStyle, Image } from 'react-native'
|
|
8
8
|
import useInnerProps from './getInnerListeners'
|
|
9
9
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
10
|
-
import { useLayout, useTransformStyle } from './utils'
|
|
10
|
+
import { useLayout, useTransformStyle, extendObject } from './utils'
|
|
11
11
|
|
|
12
12
|
export type IconType =
|
|
13
13
|
| 'success'
|
|
@@ -63,10 +63,7 @@ const Icon = forwardRef<HandlerRef<Text, IconProps>, IconProps>(
|
|
|
63
63
|
|
|
64
64
|
const defaultStyle = { width: ~~size, height: ~~size }
|
|
65
65
|
|
|
66
|
-
const styleObj = {
|
|
67
|
-
...defaultStyle,
|
|
68
|
-
...style
|
|
69
|
-
}
|
|
66
|
+
const styleObj = extendObject({}, defaultStyle, style)
|
|
70
67
|
|
|
71
68
|
const {
|
|
72
69
|
hasSelfPercent,
|
|
@@ -76,29 +73,27 @@ const Icon = forwardRef<HandlerRef<Text, IconProps>, IconProps>(
|
|
|
76
73
|
} = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
77
74
|
|
|
78
75
|
const nodeRef = useRef(null)
|
|
79
|
-
useNodesRef(props, ref, nodeRef, {
|
|
76
|
+
useNodesRef(props, ref, nodeRef, { style: normalStyle })
|
|
80
77
|
|
|
81
78
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
|
|
82
79
|
|
|
83
80
|
const innerProps = useInnerProps(
|
|
84
81
|
props,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
tintColor: color
|
|
82
|
+
extendObject(
|
|
83
|
+
{
|
|
84
|
+
ref: nodeRef,
|
|
85
|
+
source: { uri },
|
|
86
|
+
style: extendObject({}, normalStyle, layoutStyle, { tintColor: color })
|
|
91
87
|
},
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
},
|
|
88
|
+
layoutProps
|
|
89
|
+
),
|
|
95
90
|
[],
|
|
96
91
|
{
|
|
97
92
|
layoutRef
|
|
98
93
|
}
|
|
99
94
|
)
|
|
100
95
|
|
|
101
|
-
return
|
|
96
|
+
return createElement(Image, innerProps)
|
|
102
97
|
}
|
|
103
98
|
)
|
|
104
99
|
|