@mpxjs/webpack-plugin 2.9.62 → 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.
Files changed (95) hide show
  1. package/lib/config.js +38 -10
  2. package/lib/index.js +1 -3
  3. package/lib/platform/style/wx/index.js +115 -66
  4. package/lib/platform/template/wx/index.js +12 -8
  5. package/lib/react/processStyles.js +1 -0
  6. package/lib/react/processTemplate.js +2 -3
  7. package/lib/react/style-helper.js +9 -7
  8. package/lib/runtime/components/react/context.ts +9 -7
  9. package/lib/runtime/components/react/dist/context.js +1 -0
  10. package/lib/runtime/components/react/dist/getInnerListeners.js +12 -1
  11. package/lib/runtime/components/react/dist/mpx-button.jsx +53 -74
  12. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +20 -18
  13. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +30 -42
  14. package/lib/runtime/components/react/dist/mpx-form.jsx +18 -15
  15. package/lib/runtime/components/react/dist/mpx-icon.jsx +15 -17
  16. package/lib/runtime/components/react/dist/mpx-image/index.jsx +36 -34
  17. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +3 -1
  18. package/lib/runtime/components/react/dist/mpx-input.jsx +36 -31
  19. package/lib/runtime/components/react/dist/mpx-label.jsx +30 -37
  20. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +15 -19
  21. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +10 -9
  22. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +2 -1
  23. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +11 -10
  24. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +9 -5
  25. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +13 -8
  26. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +3 -2
  27. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +22 -20
  28. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +103 -10
  29. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +149 -54
  30. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +20 -18
  31. package/lib/runtime/components/react/dist/mpx-radio.jsx +29 -43
  32. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +8 -4
  33. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +36 -27
  34. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +141 -75
  35. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +16 -7
  36. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +20 -11
  37. package/lib/runtime/components/react/dist/mpx-switch.jsx +18 -14
  38. package/lib/runtime/components/react/dist/mpx-text.jsx +20 -35
  39. package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
  40. package/lib/runtime/components/react/dist/mpx-view.jsx +296 -210
  41. package/lib/runtime/components/react/dist/mpx-web-view.jsx +11 -7
  42. package/lib/runtime/components/react/dist/parser.js +218 -0
  43. package/lib/runtime/components/react/dist/useNodesRef.js +1 -5
  44. package/lib/runtime/components/react/dist/utils.jsx +445 -0
  45. package/lib/runtime/components/react/getInnerListeners.ts +18 -8
  46. package/lib/runtime/components/react/mpx-button.tsx +83 -91
  47. package/lib/runtime/components/react/mpx-checkbox-group.tsx +50 -43
  48. package/lib/runtime/components/react/mpx-checkbox.tsx +56 -64
  49. package/lib/runtime/components/react/mpx-form.tsx +51 -22
  50. package/lib/runtime/components/react/mpx-icon.tsx +31 -27
  51. package/lib/runtime/components/react/mpx-image/index.tsx +54 -47
  52. package/lib/runtime/components/react/mpx-image/svg.tsx +5 -3
  53. package/lib/runtime/components/react/mpx-input.tsx +59 -38
  54. package/lib/runtime/components/react/mpx-label.tsx +55 -59
  55. package/lib/runtime/components/react/mpx-movable-area.tsx +40 -25
  56. package/lib/runtime/components/react/mpx-movable-view.tsx +29 -29
  57. package/lib/runtime/components/react/mpx-navigator.tsx +2 -2
  58. package/lib/runtime/components/react/mpx-picker/date.tsx +4 -4
  59. package/lib/runtime/components/react/mpx-picker/index.tsx +12 -11
  60. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +17 -13
  61. package/lib/runtime/components/react/mpx-picker/region.tsx +23 -19
  62. package/lib/runtime/components/react/mpx-picker/selector.tsx +7 -7
  63. package/lib/runtime/components/react/mpx-picker/time.tsx +29 -31
  64. package/lib/runtime/components/react/mpx-picker/type.ts +1 -1
  65. package/lib/runtime/components/react/mpx-picker-view-column.tsx +149 -20
  66. package/lib/runtime/components/react/mpx-picker-view.tsx +180 -63
  67. package/lib/runtime/components/react/mpx-radio-group.tsx +51 -47
  68. package/lib/runtime/components/react/mpx-radio.tsx +57 -72
  69. package/lib/runtime/components/react/mpx-root-portal.tsx +10 -8
  70. package/lib/runtime/components/react/mpx-scroll-view.tsx +136 -104
  71. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +175 -96
  72. package/lib/runtime/components/react/mpx-swiper/index.tsx +21 -9
  73. package/lib/runtime/components/react/mpx-swiper/type.ts +16 -5
  74. package/lib/runtime/components/react/mpx-swiper-item.tsx +48 -14
  75. package/lib/runtime/components/react/mpx-switch.tsx +46 -24
  76. package/lib/runtime/components/react/mpx-text.tsx +38 -45
  77. package/lib/runtime/components/react/mpx-textarea.tsx +1 -1
  78. package/lib/runtime/components/react/mpx-view.tsx +401 -241
  79. package/lib/runtime/components/react/mpx-web-view.tsx +22 -22
  80. package/lib/runtime/components/react/parser.ts +245 -0
  81. package/lib/runtime/components/react/types/common.ts +4 -4
  82. package/lib/runtime/components/react/types/global.d.ts +24 -2
  83. package/lib/runtime/components/react/useNodesRef.ts +1 -7
  84. package/lib/runtime/components/react/utils.tsx +524 -0
  85. package/lib/runtime/components/web/mpx-scroll-view.vue +25 -5
  86. package/lib/style-compiler/index.js +5 -4
  87. package/lib/template-compiler/compiler.js +133 -161
  88. package/lib/template-compiler/gen-node-react.js +1 -3
  89. package/lib/utils/const.js +2 -1
  90. package/lib/web/processStyles.js +2 -1
  91. package/lib/web/processTemplate.js +2 -3
  92. package/lib/wxml/loader.js +1 -1
  93. package/package.json +7 -4
  94. package/lib/runtime/components/react/dist/utils.js +0 -148
  95. package/lib/runtime/components/react/utils.ts +0 -170
@@ -35,22 +35,20 @@
35
35
  * ✔ bindtap
36
36
  */
37
37
  import { useEffect, useRef, useState, ReactNode, forwardRef, useContext, JSX } from 'react'
38
-
39
38
  import {
40
39
  View,
41
- Text,
42
40
  StyleSheet,
43
41
  ViewStyle,
44
42
  TextStyle,
45
43
  Animated,
46
44
  Easing,
47
- NativeSyntheticEvent,
45
+ NativeSyntheticEvent
48
46
  } from 'react-native'
49
- import { splitStyle, isText, every, splitProps, throwReactWarning, transformTextStyle } from './utils'
47
+ import { warn } from '@mpxjs/utils'
48
+ import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils'
50
49
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
51
50
  import useNodesRef, { HandlerRef } from './useNodesRef'
52
51
  import { FormContext } from './context'
53
- import { isEmptyObject } from '@mpxjs/utils'
54
52
 
55
53
  export type Type = 'default' | 'primary' | 'warn'
56
54
 
@@ -76,6 +74,11 @@ export interface ButtonProps {
76
74
  'open-type'?: OpenType
77
75
  'form-type'?: 'submit' | 'reset'
78
76
  'enable-offset'?: boolean,
77
+ 'enable-var'?: boolean
78
+ 'external-var-context'?: Record<string, any>
79
+ 'parent-font-size'?: number
80
+ 'parent-width'?: number
81
+ 'parent-height'?: number
79
82
  style?: ViewStyle & TextStyle & Record<string, any>
80
83
  children: ReactNode
81
84
  bindgetuserinfo?: (userInfo: any) => void
@@ -90,12 +93,12 @@ const LOADING_IMAGE_URI =
90
93
  const TypeColorMap: Record<Type, TypeColor> = {
91
94
  default: ['#F8F8F8', '#DEDEDE', '35,35,35', '#F7F7F7'],
92
95
  primary: ['#1AAD19', '#179B16', '26,173,25', '#9ED99D'],
93
- warn: ['#E64340', '#CE3C39', '230,67,64', '#EC8B89'],
96
+ warn: ['#E64340', '#CE3C39', '230,67,64', '#EC8B89']
94
97
  }
95
98
 
96
99
  const OpenTypeEventsMap = new Map<OpenType, OpenTypeEvent>([
97
100
  ['share', 'onShareAppMessage'],
98
- ['getUserInfo', 'onUserInfo'],
101
+ ['getUserInfo', 'onUserInfo']
99
102
  ])
100
103
 
101
104
  const styles = StyleSheet.create({
@@ -110,38 +113,35 @@ const styles = StyleSheet.create({
110
113
  marginHorizontal: 'auto' // 按钮默认居中
111
114
  },
112
115
  buttonMini: {
113
- height: 30,
116
+ height: 30
114
117
  },
115
118
  text: {
116
119
  fontSize: 18,
117
- color: '#000000',
120
+ color: '#000000'
118
121
  },
119
122
  textMini: {
120
- fontSize: 13,
123
+ fontSize: 13
121
124
  },
122
125
  loading: {
123
126
  width: 20,
124
- height: 20,
125
- },
127
+ height: 20
128
+ }
126
129
  })
127
130
 
128
131
  const getOpenTypeEvent = (openType: OpenType) => {
129
- // @ts-ignore
130
- if (!global?.__mpx?.config?.rnConfig) {
131
- throwReactWarning('[Mpx runtime warn]: Environment not supported')
132
+ if (!global.__mpx?.config?.rnConfig) {
133
+ warn('Environment not supported')
132
134
  return
133
135
  }
134
-
135
136
  const eventName = OpenTypeEventsMap.get(openType)
136
137
  if (!eventName) {
137
- throwReactWarning(`[Mpx runtime warn]: open-type not support ${openType}`)
138
+ warn(`open-type not support ${openType}`)
138
139
  return
139
140
  }
140
141
 
141
- // @ts-ignore
142
- const event = global.__mpx.config.rnConfig?.openTypeHandler?.[eventName]
142
+ const event = global.__mpx.config.rnConfig.openTypeHandler?.[eventName]
143
143
  if (!event) {
144
- throwReactWarning(`[Mpx runtime warn]: Unregistered ${eventName} event`)
144
+ warn(`Unregistered ${eventName} event`)
145
145
  return
146
146
  }
147
147
 
@@ -153,7 +153,7 @@ const Loading = ({ alone = false }: { alone: boolean }): JSX.Element => {
153
153
 
154
154
  const rotate = image.interpolate({
155
155
  inputRange: [0, 1],
156
- outputRange: ['0deg', '360deg'],
156
+ outputRange: ['0deg', '360deg']
157
157
  })
158
158
 
159
159
  useEffect(() => {
@@ -163,7 +163,7 @@ const Loading = ({ alone = false }: { alone: boolean }): JSX.Element => {
163
163
  duration: 1000,
164
164
  easing: Easing.linear,
165
165
  useNativeDriver: true,
166
- isInteraction: false,
166
+ isInteraction: false
167
167
  })
168
168
  )
169
169
 
@@ -172,19 +172,20 @@ const Loading = ({ alone = false }: { alone: boolean }): JSX.Element => {
172
172
  return () => {
173
173
  animation.stop()
174
174
  }
175
- // eslint-disable-next-line react-hooks/exhaustive-deps
176
175
  }, [])
177
176
 
178
177
  const loadingStyle = {
179
178
  ...styles.loading,
180
179
  transform: [{ rotate }],
181
- marginRight: alone ? 0 : 5,
180
+ marginRight: alone ? 0 : 5
182
181
  }
183
182
 
184
183
  return <Animated.Image testID="loading" style={loadingStyle} source={{ uri: LOADING_IMAGE_URI }} />
185
184
  }
186
185
 
187
- const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((props, ref): JSX.Element => {
186
+ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonProps, ref): JSX.Element => {
187
+ const { textProps, innerProps: props = {} } = splitProps(buttonProps)
188
+
188
189
  const {
189
190
  size = 'default',
190
191
  type = 'default',
@@ -196,21 +197,24 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((props, re
196
197
  'hover-start-time': hoverStartTime = 20,
197
198
  'hover-stay-time': hoverStayTime = 70,
198
199
  'open-type': openType,
199
- 'enable-offset': enableOffset,
200
200
  'form-type': formType,
201
+ 'enable-var': enableVar,
202
+ 'external-var-context': externalVarContext,
203
+ 'parent-font-size': parentFontSize,
204
+ 'parent-width': parentWidth,
205
+ 'parent-height': parentHeight,
201
206
  style = {},
202
207
  children,
203
208
  bindgetuserinfo,
204
209
  bindtap,
205
210
  bindtouchstart,
206
- bindtouchend,
211
+ bindtouchend
207
212
  } = props
208
213
 
209
-
210
214
  const formContext = useContext(FormContext)
211
215
 
212
- let submitFn: () => void | undefined;
213
- let resetFn: () => void | undefined;
216
+ let submitFn: () => void | undefined
217
+ let resetFn: () => void | undefined
214
218
 
215
219
  if (formContext) {
216
220
  submitFn = formContext.submit
@@ -222,25 +226,15 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((props, re
222
226
  hoverStayTimer: ReturnType<typeof setTimeout> | undefined
223
227
  }>({
224
228
  hoverStartTimer: undefined,
225
- hoverStayTimer: undefined,
229
+ hoverStayTimer: undefined
226
230
  })
227
231
 
228
- const layoutRef = useRef({})
229
-
230
232
  const [isHover, setIsHover] = useState(false)
231
233
 
232
234
  const isMiniSize = size === 'mini'
233
235
 
234
236
  const applyHoverEffect = isHover && hoverClass !== 'none'
235
237
 
236
- const { textStyle, imageStyle, innerStyle } = splitStyle(style)
237
-
238
- const { textStyle: hoverTextStyle, imageStyle: hoverImageStyle, innerStyle: hoverInnerStyle } = splitStyle(hoverStyle)
239
-
240
- if (imageStyle || hoverImageStyle) {
241
- throwReactWarning('[Mpx runtime warn]: Button does not support background image-related styles!')
242
- }
243
-
244
238
  const [color, hoverColor, plainColor, disabledColor] = TypeColorMap[type]
245
239
 
246
240
  const normalBackgroundColor = disabled ? disabledColor : applyHoverEffect || loading ? hoverColor : color
@@ -268,19 +262,51 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((props, re
268
262
  borderWidth: 1,
269
263
  borderStyle: 'solid',
270
264
  borderColor: plain ? plainBorderColor : normalBorderColor,
271
- backgroundColor: plain ? 'transparent' : normalBackgroundColor,
265
+ backgroundColor: plain ? 'transparent' : normalBackgroundColor
272
266
  }
273
267
 
274
268
  const defaultViewStyle = {
275
269
  ...styles.button,
276
270
  ...(isMiniSize && styles.buttonMini),
277
- ...viewStyle,
271
+ ...viewStyle
278
272
  }
279
273
 
280
274
  const defaultTextStyle = {
281
275
  ...styles.text,
282
276
  ...(isMiniSize && styles.textMini),
283
- color: plain ? plainTextColor : normalTextColor,
277
+ color: plain ? plainTextColor : normalTextColor
278
+ }
279
+
280
+ const defaultStyle = {
281
+ ...defaultViewStyle,
282
+ ...defaultTextStyle
283
+ }
284
+
285
+ const styleObj = {
286
+ ...defaultStyle,
287
+ ...style,
288
+ ...(applyHoverEffect && hoverStyle)
289
+ }
290
+
291
+ const {
292
+ hasSelfPercent,
293
+ normalStyle,
294
+ hasVarDec,
295
+ varContextRef,
296
+ setWidth,
297
+ setHeight
298
+ } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
299
+
300
+ const nodeRef = useRef(null)
301
+
302
+ useNodesRef(props, ref, nodeRef, { defaultStyle })
303
+
304
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
305
+
306
+ const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle)
307
+
308
+ if (backgroundStyle) {
309
+ warn('Button does not support background image-related styles!')
284
310
  }
285
311
 
286
312
  const handleOpenTypeEvent = (evt: NativeSyntheticEvent<TouchEvent>) => {
@@ -290,7 +316,7 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((props, re
290
316
  if (openType === 'share') {
291
317
  handleEvent && handleEvent({
292
318
  from: 'button',
293
- target: getCustomEvent('tap', evt, { layoutRef }, props).target,
319
+ target: getCustomEvent('tap', evt, { layoutRef }, props).target
294
320
  })
295
321
  }
296
322
 
@@ -339,6 +365,7 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((props, re
339
365
  resetFn && resetFn()
340
366
  }
341
367
  }
368
+
342
369
  const onTap = (evt: NativeSyntheticEvent<TouchEvent>) => {
343
370
  if (disabled) return
344
371
  bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, props))
@@ -346,69 +373,34 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((props, re
346
373
  handleFormTypeFn()
347
374
  }
348
375
 
349
- function wrapChildren(children: ReactNode, defaultTextStyle: Record<string, any>, textStyle: Record<string, any>) {
350
- if (!children) return children
351
- const hasTextStyle = !isEmptyObject(textStyle)
352
- const { textProps } = splitProps(props)
353
-
354
- if (every(children, (child) => isText(child))) {
355
- transformTextStyle(textStyle as TextStyle)
356
- children = <Text key='buttonTextWrap' style={{ ...defaultTextStyle, ...textStyle }} {...(textProps || {})}>{children}</Text>
357
- } else {
358
- if (hasTextStyle) throwReactWarning('[Mpx runtime warn]: Text style will be ignored unless every child of the Button is Text node!')
359
- }
360
-
361
- return children
362
- }
363
-
364
- const { nodeRef } = useNodesRef(props, ref, {
365
- defaultStyle: {
366
- ...defaultViewStyle,
367
- ...defaultTextStyle,
368
- ...textStyle
369
- }
370
- })
371
-
372
- const onLayout = () => {
373
- nodeRef.current?.measure((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
374
- layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
375
- })
376
- }
377
-
378
376
  const innerProps = useInnerProps(
379
377
  props,
380
378
  {
381
379
  ref: nodeRef,
380
+ style: { ...innerStyle, ...layoutStyle },
381
+ ...layoutProps,
382
382
  bindtouchstart: onTouchStart,
383
383
  bindtouchend: onTouchEnd,
384
- bindtap: onTap,
385
- ...(enableOffset ? { onLayout } : {}),
384
+ bindtap: onTap
386
385
  },
387
- [
388
- 'enable-offset'
389
- ],
386
+ [],
390
387
  {
391
388
  layoutRef,
392
389
  disableTap: disabled
393
390
  }
394
- );
391
+ )
395
392
 
396
393
  return (
397
- <View
398
- {...innerProps}
399
- style={{
400
- ...defaultViewStyle,
401
- ...innerStyle,
402
- ...(applyHoverEffect && hoverInnerStyle),
403
- } as ViewStyle}>
394
+ <View {...innerProps}>
404
395
  {loading && <Loading alone={!children} />}
405
396
  {
406
397
  wrapChildren(
407
- children,
408
- defaultTextStyle,
398
+ props,
409
399
  {
410
- ...textStyle,
411
- ...(applyHoverEffect && hoverTextStyle),
400
+ hasVarDec,
401
+ varContext: varContextRef.current,
402
+ textStyle,
403
+ textProps
412
404
  }
413
405
  )
414
406
  }
@@ -1,27 +1,23 @@
1
1
  /**
2
2
  * ✔ bindchange
3
3
  */
4
- import {
5
- JSX,
6
- useRef,
7
- forwardRef,
8
- ReactNode,
9
- useContext
10
- } from 'react'
11
- import {
12
- View,
13
- NativeSyntheticEvent,
14
- ViewStyle
15
- } from 'react-native'
4
+ import { JSX, useRef, forwardRef, ReactNode, useContext } from 'react'
5
+ import { View, NativeSyntheticEvent, ViewStyle } from 'react-native'
6
+ import { warn } from '@mpxjs/utils'
16
7
  import { FormContext, FormFieldValue, CheckboxGroupContext, GroupValue } from './context'
17
8
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
18
9
  import useNodesRef, { HandlerRef } from './useNodesRef'
19
- import { throwReactWarning } from './utils'
10
+ import { useLayout, useTransformStyle, wrapChildren } from './utils'
20
11
 
21
12
  export interface CheckboxGroupProps {
22
13
  name: string
23
14
  style?: ViewStyle & Record<string, any>
24
15
  'enable-offset'?: boolean
16
+ 'enable-var'?: boolean
17
+ 'external-var-context'?: Record<string, any>
18
+ 'parent-font-size'?: number
19
+ 'parent-width'?: number
20
+ 'parent-height'?: number
25
21
  children: ReactNode
26
22
  bindchange?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
27
23
  }
@@ -32,15 +28,17 @@ const CheckboxGroup = forwardRef<
32
28
  >((props, ref): JSX.Element => {
33
29
  const {
34
30
  style = {},
35
- 'enable-offset': enableOffset,
36
- children,
31
+ 'enable-var': enableVar,
32
+ 'external-var-context': externalVarContext,
33
+ 'parent-font-size': parentFontSize,
34
+ 'parent-width': parentWidth,
35
+ 'parent-height': parentHeight,
37
36
  bindchange
38
37
  } = props
39
38
 
40
- const layoutRef = useRef({})
41
39
  const formContext = useContext(FormContext)
42
40
 
43
- let formValuesMap: Map<string, FormFieldValue> | undefined;
41
+ let formValuesMap: Map<string, FormFieldValue> | undefined
44
42
 
45
43
  if (formContext) {
46
44
  formValuesMap = formContext.formValuesMap
@@ -50,31 +48,32 @@ const CheckboxGroup = forwardRef<
50
48
 
51
49
  const defaultStyle = {
52
50
  flexDirection: 'row',
53
- flexWrap: 'wrap',
54
- ...style
51
+ flexWrap: 'wrap'
55
52
  }
56
- const { nodeRef } = useNodesRef(props, ref, {
57
- defaultStyle
58
- })
59
-
60
- const onLayout = () => {
61
- nodeRef.current?.measure(
62
- (
63
- x: number,
64
- y: number,
65
- width: number,
66
- height: number,
67
- offsetLeft: number,
68
- offsetTop: number
69
- ) => {
70
- layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
71
- }
72
- )
53
+
54
+ const styleObj = {
55
+ ...defaultStyle,
56
+ ...style
73
57
  }
74
58
 
59
+ const {
60
+ hasSelfPercent,
61
+ normalStyle,
62
+ hasVarDec,
63
+ varContextRef,
64
+ setWidth,
65
+ setHeight
66
+ } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
67
+
68
+ const nodeRef = useRef(null)
69
+
70
+ useNodesRef(props, ref, nodeRef, { defaultStyle })
71
+
72
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
73
+
75
74
  const getSelectionValue = (): string[] => {
76
75
  const arr: string[] = []
77
- for (let key in groupValue) {
76
+ for (const key in groupValue) {
78
77
  if (groupValue[key].checked) {
79
78
  arr.push(key)
80
79
  }
@@ -95,7 +94,7 @@ const CheckboxGroup = forwardRef<
95
94
 
96
95
  if (formValuesMap) {
97
96
  if (!props.name) {
98
- throwReactWarning('[Mpx runtime warn]: If a form component is used, the name attribute is required.')
97
+ warn('If a form component is used, the name attribute is required.')
99
98
  } else {
100
99
  formValuesMap.set(props.name, { getValue, resetValue })
101
100
  }
@@ -124,10 +123,10 @@ const CheckboxGroup = forwardRef<
124
123
  props,
125
124
  {
126
125
  ref: nodeRef,
127
- style: defaultStyle,
128
- ...(enableOffset ? { onLayout } : {})
126
+ style: { ...normalStyle, ...layoutStyle },
127
+ ...layoutProps
129
128
  },
130
- ['enable-offset'],
129
+ [],
131
130
  {
132
131
  layoutRef
133
132
  }
@@ -136,7 +135,15 @@ const CheckboxGroup = forwardRef<
136
135
  return (
137
136
  <View {...innerProps}>
138
137
  <CheckboxGroupContext.Provider value={{ groupValue, notifyChange }}>
139
- {children}
138
+ {
139
+ wrapChildren(
140
+ props,
141
+ {
142
+ hasVarDec,
143
+ varContext: varContextRef.current
144
+ }
145
+ )
146
+ }
140
147
  </CheckboxGroupContext.Provider>
141
148
  </View>
142
149
  )
@@ -144,4 +151,4 @@ const CheckboxGroup = forwardRef<
144
151
 
145
152
  CheckboxGroup.displayName = 'mpx-checkbox-group'
146
153
 
147
- export default CheckboxGroup
154
+ export default CheckboxGroup