@mpxjs/webpack-plugin 2.9.62 → 2.9.64

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 (86) hide show
  1. package/lib/index.js +1 -3
  2. package/lib/platform/style/wx/index.js +67 -53
  3. package/lib/react/processStyles.js +1 -0
  4. package/lib/react/processTemplate.js +2 -3
  5. package/lib/react/style-helper.js +12 -7
  6. package/lib/runtime/components/react/context.ts +9 -7
  7. package/lib/runtime/components/react/dist/context.js +1 -0
  8. package/lib/runtime/components/react/dist/getInnerListeners.js +12 -1
  9. package/lib/runtime/components/react/dist/mpx-button.jsx +52 -74
  10. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +19 -18
  11. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +28 -41
  12. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -14
  13. package/lib/runtime/components/react/dist/mpx-icon.jsx +14 -17
  14. package/lib/runtime/components/react/dist/mpx-image/index.jsx +34 -33
  15. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +3 -1
  16. package/lib/runtime/components/react/dist/mpx-input.jsx +35 -31
  17. package/lib/runtime/components/react/dist/mpx-label.jsx +29 -37
  18. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -18
  19. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +8 -8
  20. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +9 -9
  21. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +7 -4
  22. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +11 -7
  23. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +1 -1
  24. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +18 -18
  25. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +102 -10
  26. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +147 -53
  27. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +19 -18
  28. package/lib/runtime/components/react/dist/mpx-radio.jsx +28 -43
  29. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +8 -4
  30. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +33 -26
  31. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +139 -74
  32. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +14 -6
  33. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +19 -11
  34. package/lib/runtime/components/react/dist/mpx-switch.jsx +17 -14
  35. package/lib/runtime/components/react/dist/mpx-text.jsx +19 -35
  36. package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
  37. package/lib/runtime/components/react/dist/mpx-view.jsx +284 -209
  38. package/lib/runtime/components/react/dist/mpx-web-view.jsx +8 -5
  39. package/lib/runtime/components/react/dist/parser.js +218 -0
  40. package/lib/runtime/components/react/dist/utils.jsx +433 -0
  41. package/lib/runtime/components/react/getInnerListeners.ts +18 -8
  42. package/lib/runtime/components/react/mpx-button.tsx +81 -91
  43. package/lib/runtime/components/react/mpx-checkbox-group.tsx +48 -43
  44. package/lib/runtime/components/react/mpx-checkbox.tsx +52 -63
  45. package/lib/runtime/components/react/mpx-form.tsx +49 -21
  46. package/lib/runtime/components/react/mpx-icon.tsx +30 -27
  47. package/lib/runtime/components/react/mpx-image/index.tsx +52 -46
  48. package/lib/runtime/components/react/mpx-image/svg.tsx +5 -3
  49. package/lib/runtime/components/react/mpx-input.tsx +58 -38
  50. package/lib/runtime/components/react/mpx-label.tsx +54 -59
  51. package/lib/runtime/components/react/mpx-movable-area.tsx +38 -24
  52. package/lib/runtime/components/react/mpx-movable-view.tsx +27 -28
  53. package/lib/runtime/components/react/mpx-navigator.tsx +2 -2
  54. package/lib/runtime/components/react/mpx-picker/date.tsx +2 -3
  55. package/lib/runtime/components/react/mpx-picker/index.tsx +10 -10
  56. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +15 -12
  57. package/lib/runtime/components/react/mpx-picker/region.tsx +21 -18
  58. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -6
  59. package/lib/runtime/components/react/mpx-picker/time.tsx +25 -29
  60. package/lib/runtime/components/react/mpx-picker/type.ts +1 -1
  61. package/lib/runtime/components/react/mpx-picker-view-column.tsx +148 -20
  62. package/lib/runtime/components/react/mpx-picker-view.tsx +179 -63
  63. package/lib/runtime/components/react/mpx-radio-group.tsx +50 -47
  64. package/lib/runtime/components/react/mpx-radio.tsx +56 -72
  65. package/lib/runtime/components/react/mpx-root-portal.tsx +10 -8
  66. package/lib/runtime/components/react/mpx-scroll-view.tsx +133 -103
  67. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +174 -96
  68. package/lib/runtime/components/react/mpx-swiper/index.tsx +18 -9
  69. package/lib/runtime/components/react/mpx-swiper/type.ts +16 -5
  70. package/lib/runtime/components/react/mpx-swiper-item.tsx +46 -13
  71. package/lib/runtime/components/react/mpx-switch.tsx +44 -23
  72. package/lib/runtime/components/react/mpx-text.tsx +37 -45
  73. package/lib/runtime/components/react/mpx-textarea.tsx +1 -1
  74. package/lib/runtime/components/react/mpx-view.tsx +388 -240
  75. package/lib/runtime/components/react/mpx-web-view.tsx +19 -20
  76. package/lib/runtime/components/react/parser.ts +245 -0
  77. package/lib/runtime/components/react/types/common.ts +4 -4
  78. package/lib/runtime/components/react/types/global.d.ts +14 -2
  79. package/lib/runtime/components/react/useNodesRef.ts +1 -2
  80. package/lib/runtime/components/react/utils.tsx +505 -0
  81. package/lib/template-compiler/compiler.js +28 -20
  82. package/lib/template-compiler/gen-node-react.js +1 -3
  83. package/lib/web/processStyles.js +2 -5
  84. package/package.json +6 -4
  85. package/lib/runtime/components/react/dist/utils.js +0 -148
  86. package/lib/runtime/components/react/utils.ts +0 -170
@@ -82,7 +82,7 @@ export const getDataSet = (props: Record<string, any>) => {
82
82
  }
83
83
 
84
84
  export const getCustomEvent = (
85
- type: string = '',
85
+ type = '',
86
86
  oe: any = {},
87
87
  { detail = {}, layoutRef }: { detail?: Record<string, unknown>; layoutRef: LayoutRef },
88
88
  props: Props = {}
@@ -107,7 +107,7 @@ export const getCustomEvent = (
107
107
  const useInnerProps = (
108
108
  props: Props = {},
109
109
  additionalProps: AdditionalProps = {},
110
- removeProps: RemoveProps = [],
110
+ userRemoveProps: RemoveProps = [],
111
111
  rawConfig?: UseInnerPropsConfig
112
112
  ) => {
113
113
  const ref = useRef<InnerRef>({
@@ -130,6 +130,17 @@ const useInnerProps = (
130
130
  const propsRef = useRef<Record<string, any>>({})
131
131
  const eventConfig: { [key: string]: string[] } = {}
132
132
  const config = rawConfig || { layoutRef: { current: {} }, disableTouch: false, disableTap: false }
133
+ const removeProps = [
134
+ 'children',
135
+ 'enable-background',
136
+ 'enable-offset',
137
+ 'enable-var',
138
+ 'external-var-context',
139
+ 'parent-font-size',
140
+ 'parent-width',
141
+ 'parent-height',
142
+ ...userRemoveProps
143
+ ]
133
144
 
134
145
  propsRef.current = { ...props, ...additionalProps }
135
146
 
@@ -143,7 +154,7 @@ const useInnerProps = (
143
154
  return omit(propsRef.current, removeProps)
144
155
  }
145
156
 
146
- function handleEmitEvent(
157
+ function handleEmitEvent (
147
158
  events: string[],
148
159
  type: string,
149
160
  oe: NativeTouchEvent
@@ -171,7 +182,7 @@ const useInnerProps = (
171
182
  }
172
183
  }
173
184
 
174
- function handleTouchstart(e: NativeTouchEvent, type: 'bubble' | 'capture') {
185
+ function handleTouchstart (e: NativeTouchEvent, type: 'bubble' | 'capture') {
175
186
  e.persist()
176
187
  const bubbleTouchEvent = ['catchtouchstart', 'bindtouchstart']
177
188
  const bubblePressEvent = ['catchlongpress', 'bindlongpress']
@@ -196,7 +207,7 @@ const useInnerProps = (
196
207
  }
197
208
  }
198
209
 
199
- function handleTouchmove(e: NativeTouchEvent, type: 'bubble' | 'capture') {
210
+ function handleTouchmove (e: NativeTouchEvent, type: 'bubble' | 'capture') {
200
211
  const bubbleTouchEvent = ['catchtouchmove', 'bindtouchmove']
201
212
  const captureTouchEvent = ['capture-catchtouchmove', 'capture-bindtouchmove']
202
213
  const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
@@ -204,7 +215,7 @@ const useInnerProps = (
204
215
  checkIsNeedPress(e, type)
205
216
  }
206
217
 
207
- function handleTouchend(e: NativeTouchEvent, type: 'bubble' | 'capture') {
218
+ function handleTouchend (e: NativeTouchEvent, type: 'bubble' | 'capture') {
208
219
  // move event may not be triggered
209
220
  checkIsNeedPress(e, type)
210
221
  const bubbleTouchEvent = ['catchtouchend', 'bindtouchend']
@@ -224,7 +235,7 @@ const useInnerProps = (
224
235
  }
225
236
  }
226
237
 
227
- function handleTouchcancel(e: NativeTouchEvent, type: 'bubble' | 'capture') {
238
+ function handleTouchcancel (e: NativeTouchEvent, type: 'bubble' | 'capture') {
228
239
  const bubbleTouchEvent = ['catchtouchcancel', 'bindtouchcancel']
229
240
  const captureTouchEvent = ['capture-catchtouchcancel', 'capture-bindtouchcancel']
230
241
  const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
@@ -284,7 +295,6 @@ const useInnerProps = (
284
295
 
285
296
  const finalEventKeys = [...new Set(transformedEventKeys)]
286
297
 
287
-
288
298
  touchEventList.forEach(item => {
289
299
  if (finalEventKeys.includes(item.eventName)) {
290
300
  events[item.eventName] = item.handler
@@ -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,49 @@ 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 } = useNodesRef(props, ref, { defaultStyle })
301
+
302
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
303
+
304
+ const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle)
305
+
306
+ if (backgroundStyle) {
307
+ warn('Button does not support background image-related styles!')
284
308
  }
285
309
 
286
310
  const handleOpenTypeEvent = (evt: NativeSyntheticEvent<TouchEvent>) => {
@@ -290,7 +314,7 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((props, re
290
314
  if (openType === 'share') {
291
315
  handleEvent && handleEvent({
292
316
  from: 'button',
293
- target: getCustomEvent('tap', evt, { layoutRef }, props).target,
317
+ target: getCustomEvent('tap', evt, { layoutRef }, props).target
294
318
  })
295
319
  }
296
320
 
@@ -339,6 +363,7 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((props, re
339
363
  resetFn && resetFn()
340
364
  }
341
365
  }
366
+
342
367
  const onTap = (evt: NativeSyntheticEvent<TouchEvent>) => {
343
368
  if (disabled) return
344
369
  bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, props))
@@ -346,69 +371,34 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((props, re
346
371
  handleFormTypeFn()
347
372
  }
348
373
 
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
374
  const innerProps = useInnerProps(
379
375
  props,
380
376
  {
381
377
  ref: nodeRef,
378
+ style: { ...innerStyle, ...layoutStyle },
379
+ ...layoutProps,
382
380
  bindtouchstart: onTouchStart,
383
381
  bindtouchend: onTouchEnd,
384
- bindtap: onTap,
385
- ...(enableOffset ? { onLayout } : {}),
382
+ bindtap: onTap
386
383
  },
387
- [
388
- 'enable-offset'
389
- ],
384
+ [],
390
385
  {
391
386
  layoutRef,
392
387
  disableTap: disabled
393
388
  }
394
- );
389
+ )
395
390
 
396
391
  return (
397
- <View
398
- {...innerProps}
399
- style={{
400
- ...defaultViewStyle,
401
- ...innerStyle,
402
- ...(applyHoverEffect && hoverInnerStyle),
403
- } as ViewStyle}>
392
+ <View {...innerProps}>
404
393
  {loading && <Loading alone={!children} />}
405
394
  {
406
395
  wrapChildren(
407
- children,
408
- defaultTextStyle,
396
+ props,
409
397
  {
410
- ...textStyle,
411
- ...(applyHoverEffect && hoverTextStyle),
398
+ hasVarDec,
399
+ varContext: varContextRef.current,
400
+ textStyle,
401
+ textProps
412
402
  }
413
403
  )
414
404
  }
@@ -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,30 @@ 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 } = useNodesRef(props, ref, { defaultStyle })
69
+
70
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
71
+
75
72
  const getSelectionValue = (): string[] => {
76
73
  const arr: string[] = []
77
- for (let key in groupValue) {
74
+ for (const key in groupValue) {
78
75
  if (groupValue[key].checked) {
79
76
  arr.push(key)
80
77
  }
@@ -95,7 +92,7 @@ const CheckboxGroup = forwardRef<
95
92
 
96
93
  if (formValuesMap) {
97
94
  if (!props.name) {
98
- throwReactWarning('[Mpx runtime warn]: If a form component is used, the name attribute is required.')
95
+ warn('If a form component is used, the name attribute is required.')
99
96
  } else {
100
97
  formValuesMap.set(props.name, { getValue, resetValue })
101
98
  }
@@ -124,10 +121,10 @@ const CheckboxGroup = forwardRef<
124
121
  props,
125
122
  {
126
123
  ref: nodeRef,
127
- style: defaultStyle,
128
- ...(enableOffset ? { onLayout } : {})
124
+ style: { ...normalStyle, ...layoutStyle },
125
+ ...layoutProps
129
126
  },
130
- ['enable-offset'],
127
+ [],
131
128
  {
132
129
  layoutRef
133
130
  }
@@ -136,7 +133,15 @@ const CheckboxGroup = forwardRef<
136
133
  return (
137
134
  <View {...innerProps}>
138
135
  <CheckboxGroupContext.Provider value={{ groupValue, notifyChange }}>
139
- {children}
136
+ {
137
+ wrapChildren(
138
+ props,
139
+ {
140
+ hasVarDec,
141
+ varContext: varContextRef.current
142
+ }
143
+ )
144
+ }
140
145
  </CheckboxGroupContext.Provider>
141
146
  </View>
142
147
  )
@@ -144,4 +149,4 @@ const CheckboxGroup = forwardRef<
144
149
 
145
150
  CheckboxGroup.displayName = 'mpx-checkbox-group'
146
151
 
147
- export default CheckboxGroup
152
+ export default CheckboxGroup