@mpxjs/webpack-plugin 2.9.59 → 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 (115) hide show
  1. package/lib/index.js +1 -3
  2. package/lib/platform/style/wx/index.js +344 -270
  3. package/lib/platform/template/wx/component-config/checkbox-group.js +8 -0
  4. package/lib/platform/template/wx/component-config/checkbox.js +8 -0
  5. package/lib/platform/template/wx/component-config/cover-image.js +15 -0
  6. package/lib/platform/template/wx/component-config/cover-view.js +9 -0
  7. package/lib/platform/template/wx/component-config/form.js +13 -1
  8. package/lib/platform/template/wx/component-config/icon.js +8 -0
  9. package/lib/platform/template/wx/component-config/index.js +5 -1
  10. package/lib/platform/template/wx/component-config/label.js +15 -0
  11. package/lib/platform/template/wx/component-config/movable-area.js +18 -1
  12. package/lib/platform/template/wx/component-config/movable-view.js +18 -1
  13. package/lib/platform/template/wx/component-config/navigator.js +8 -0
  14. package/lib/platform/template/wx/component-config/picker-view-column.js +8 -0
  15. package/lib/platform/template/wx/component-config/picker-view.js +18 -2
  16. package/lib/platform/template/wx/component-config/picker.js +14 -1
  17. package/lib/platform/template/wx/component-config/radio-group.js +8 -0
  18. package/lib/platform/template/wx/component-config/radio.js +8 -0
  19. package/lib/platform/template/wx/component-config/root-portal.js +15 -0
  20. package/lib/platform/template/wx/component-config/switch.js +8 -0
  21. package/lib/platform/template/wx/component-config/unsupported.js +1 -3
  22. package/lib/react/processScript.js +2 -0
  23. package/lib/react/processStyles.js +1 -0
  24. package/lib/react/processTemplate.js +2 -3
  25. package/lib/react/style-helper.js +12 -7
  26. package/lib/runtime/components/react/context.ts +40 -0
  27. package/lib/runtime/components/react/dist/context.js +8 -0
  28. package/lib/runtime/components/react/dist/getInnerListeners.js +34 -12
  29. package/lib/runtime/components/react/dist/mpx-button.jsx +88 -88
  30. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +82 -0
  31. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +139 -0
  32. package/lib/runtime/components/react/dist/mpx-form.jsx +61 -0
  33. package/lib/runtime/components/react/dist/mpx-icon.jsx +48 -0
  34. package/lib/runtime/components/react/dist/mpx-image/index.jsx +39 -43
  35. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +3 -2
  36. package/lib/runtime/components/react/dist/mpx-input.jsx +63 -37
  37. package/lib/runtime/components/react/dist/mpx-label.jsx +55 -0
  38. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +41 -0
  39. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +346 -0
  40. package/lib/runtime/components/react/dist/mpx-navigator.jsx +35 -0
  41. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +69 -0
  42. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +138 -0
  43. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +142 -0
  44. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +94 -0
  45. package/lib/runtime/components/react/dist/mpx-picker/regionData.js +6099 -0
  46. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +76 -0
  47. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +244 -0
  48. package/lib/runtime/components/react/dist/mpx-picker/type.js +1 -0
  49. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +107 -0
  50. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +162 -0
  51. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +80 -0
  52. package/lib/runtime/components/react/dist/mpx-radio.jsx +154 -0
  53. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +15 -0
  54. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +93 -70
  55. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +281 -157
  56. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +21 -11
  57. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +19 -11
  58. package/lib/runtime/components/react/dist/mpx-switch.jsx +79 -0
  59. package/lib/runtime/components/react/dist/mpx-text.jsx +21 -49
  60. package/lib/runtime/components/react/dist/mpx-textarea.jsx +2 -2
  61. package/lib/runtime/components/react/dist/mpx-view.jsx +451 -146
  62. package/lib/runtime/components/react/dist/mpx-web-view.jsx +17 -20
  63. package/lib/runtime/components/react/dist/parser.js +218 -0
  64. package/lib/runtime/components/react/dist/types/common.js +1 -0
  65. package/lib/runtime/components/react/dist/useNodesRef.js +3 -8
  66. package/lib/runtime/components/react/dist/utils.jsx +433 -0
  67. package/lib/runtime/components/react/getInnerListeners.ts +43 -21
  68. package/lib/runtime/components/react/mpx-button.tsx +129 -119
  69. package/lib/runtime/components/react/mpx-checkbox-group.tsx +152 -0
  70. package/lib/runtime/components/react/mpx-checkbox.tsx +234 -0
  71. package/lib/runtime/components/react/mpx-form.tsx +117 -0
  72. package/lib/runtime/components/react/mpx-icon.tsx +106 -0
  73. package/lib/runtime/components/react/mpx-image/index.tsx +62 -68
  74. package/lib/runtime/components/react/mpx-image/svg.tsx +7 -5
  75. package/lib/runtime/components/react/mpx-input.tsx +90 -42
  76. package/lib/runtime/components/react/mpx-label.tsx +110 -0
  77. package/lib/runtime/components/react/mpx-movable-area.tsx +81 -0
  78. package/lib/runtime/components/react/mpx-movable-view.tsx +424 -0
  79. package/lib/runtime/components/react/mpx-navigator.tsx +67 -0
  80. package/lib/runtime/components/react/mpx-picker/date.tsx +82 -0
  81. package/lib/runtime/components/react/mpx-picker/index.tsx +155 -0
  82. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +156 -0
  83. package/lib/runtime/components/react/mpx-picker/region.tsx +107 -0
  84. package/lib/runtime/components/react/mpx-picker/regionData.ts +6101 -0
  85. package/lib/runtime/components/react/mpx-picker/selector.tsx +91 -0
  86. package/lib/runtime/components/react/mpx-picker/time.tsx +270 -0
  87. package/lib/runtime/components/react/mpx-picker/type.ts +107 -0
  88. package/lib/runtime/components/react/mpx-picker-view-column.tsx +156 -0
  89. package/lib/runtime/components/react/mpx-picker-view.tsx +220 -0
  90. package/lib/runtime/components/react/mpx-radio-group.tsx +150 -0
  91. package/lib/runtime/components/react/mpx-radio.tsx +230 -0
  92. package/lib/runtime/components/react/mpx-root-portal.tsx +27 -0
  93. package/lib/runtime/components/react/mpx-scroll-view.tsx +184 -130
  94. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +308 -183
  95. package/lib/runtime/components/react/mpx-swiper/index.tsx +27 -19
  96. package/lib/runtime/components/react/mpx-swiper/type.ts +23 -5
  97. package/lib/runtime/components/react/mpx-swiper-item.tsx +49 -14
  98. package/lib/runtime/components/react/mpx-switch.tsx +148 -0
  99. package/lib/runtime/components/react/mpx-text.tsx +53 -77
  100. package/lib/runtime/components/react/mpx-textarea.tsx +3 -3
  101. package/lib/runtime/components/react/mpx-view.tsx +576 -195
  102. package/lib/runtime/components/react/mpx-web-view.tsx +34 -39
  103. package/lib/runtime/components/react/parser.ts +245 -0
  104. package/lib/runtime/components/react/types/common.ts +12 -0
  105. package/lib/runtime/components/react/types/getInnerListeners.ts +2 -1
  106. package/lib/runtime/components/react/types/global.d.ts +17 -1
  107. package/lib/runtime/components/react/useNodesRef.ts +4 -10
  108. package/lib/runtime/components/react/utils.tsx +505 -0
  109. package/lib/runtime/optionProcessor.js +19 -17
  110. package/lib/template-compiler/compiler.js +84 -61
  111. package/lib/template-compiler/gen-node-react.js +7 -9
  112. package/lib/web/processStyles.js +2 -5
  113. package/package.json +8 -3
  114. package/lib/runtime/components/react/dist/utils.js +0 -80
  115. package/lib/runtime/components/react/utils.ts +0 -92
@@ -1,6 +1,6 @@
1
- import { View, ScrollView } from 'react-native'
2
- import React, { forwardRef, useRef } from 'react'
3
- import { default as Carouse } from './carouse'
1
+ import { ScrollView } from 'react-native'
2
+ import { JSX, MutableRefObject, forwardRef, useRef } from 'react'
3
+ import Carouse from './carouse'
4
4
  import { SwiperProps } from './type'
5
5
  import useInnerProps from '../getInnerListeners'
6
6
  import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
@@ -15,13 +15,14 @@ import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
15
15
  * ✔ circular
16
16
  * ✔ vertical
17
17
  * ✘ display-multiple-items
18
- * previous-margin
19
- * next-margin
18
+ * previous-margin
19
+ * next-margin
20
+ * ✔ easing-function ="easeOutCubic"
20
21
  * ✘ snap-to-edge
21
22
  */
22
- const _SwiperWrapper = forwardRef<HandlerRef<ScrollView, SwiperProps>, SwiperProps>((props: SwiperProps, ref): React.JSX.Element => {
23
+ const _SwiperWrapper = forwardRef<HandlerRef<ScrollView, SwiperProps>, SwiperProps>((props: SwiperProps, ref): JSX.Element => {
23
24
  const { children } = props
24
- let innerLayout = useRef({})
25
+ const innerLayout = useRef({})
25
26
  const swiperProp = {
26
27
  circular: props.circular || false,
27
28
  current: props.current || 0,
@@ -29,17 +30,22 @@ const _SwiperWrapper = forwardRef<HandlerRef<ScrollView, SwiperProps>, SwiperPro
29
30
  duration: props.duration || 500,
30
31
  interval: props.interval || 5000,
31
32
  showsPagination: props['indicator-dots'],
32
- dotColor: props['indicator-color'] || "rgba(0, 0, 0, .3)",
33
+ dotColor: props['indicator-color'] || 'rgba(0, 0, 0, .3)',
33
34
  activeDotColor: props['indicator-active-color'] || '#000000',
34
35
  horizontal: props.vertical !== undefined ? !props.vertical : true,
35
- style: props.style,
36
36
  previousMargin: props['previous-margin'] ? parseInt(props['previous-margin']) : 0,
37
37
  nextMargin: props['next-margin'] ? parseInt(props['next-margin']) : 0,
38
- enableOffset: props['enable-offset'] || false,
39
- bindchange: props.bindchange
38
+ enableOffset: props['enable-offset'] || true,
39
+ enableVar: props['enable-var'] || false,
40
+ parentFontSize: props['parent-font-size'],
41
+ parentWidth: props['parent-width'],
42
+ parentHeight: props['parent-height'],
43
+ style: props.style || {},
44
+ externalVarContext: props['external-var-context'],
45
+ bindchange: props.bindchange,
46
+ easingFunction: props['easing-function'] || 'default'
40
47
  }
41
- const { nodeRef } = useNodesRef<ScrollView, SwiperProps>(props, ref, {
42
- })
48
+ const { nodeRef } = useNodesRef<ScrollView, SwiperProps>(props, ref, {})
43
49
  const innerProps = useInnerProps(props, {
44
50
  ref: nodeRef
45
51
  }, [
@@ -47,22 +53,24 @@ const _SwiperWrapper = forwardRef<HandlerRef<ScrollView, SwiperProps>, SwiperPro
47
53
  'indicator-color',
48
54
  'indicator-active-color',
49
55
  'previous-margin',
50
- 'next-margin'
56
+ 'vertical',
57
+ 'previous-margin',
58
+ 'next-margin',
59
+ 'easing-function'
51
60
  ], { layoutRef: innerLayout })
52
61
 
53
- const getInnerLayout = (layout: React.MutableRefObject<{}>) => {
62
+ const getInnerLayout = (layout: MutableRefObject<{}>) => {
54
63
  innerLayout.current = layout.current
55
64
  }
56
65
 
57
66
  return <Carouse
58
67
  getInnerLayout={getInnerLayout}
59
68
  innerProps={innerProps}
60
- {...swiperProp}
61
- {...innerProps}>
69
+ {...innerProps}
70
+ {...swiperProp}>
62
71
  {children}
63
72
  </Carouse>
64
-
65
73
  })
66
- _SwiperWrapper.displayName = 'mpx-swiper';
74
+ _SwiperWrapper.displayName = 'mpx-swiper'
67
75
 
68
76
  export default _SwiperWrapper
@@ -1,5 +1,8 @@
1
1
  import { ReactNode } from 'react'
2
2
  import { NativeSyntheticEvent } from 'react-native'
3
+
4
+ export type EaseType = 'default' | 'linear' | 'easeInCubic' | 'easeOutCubic' | 'easeInOutCubic'
5
+
3
6
  export interface SwiperProps {
4
7
  children?: ReactNode;
5
8
  circular?: boolean;
@@ -11,11 +14,18 @@ export interface SwiperProps {
11
14
  'indicator-color'?: string;
12
15
  'indicator-active-color'?: string;
13
16
  vertical?: boolean;
14
- style?: string;
15
- easingFunction?: string;
17
+ style: {
18
+ [key: string]: any
19
+ };
20
+ 'easing-function'?: EaseType;
16
21
  'previous-margin'?: string;
17
22
  'next-margin'?: string;
18
23
  'enable-offset'?: boolean;
24
+ 'enable-var': boolean;
25
+ 'parent-font-size'?: number;
26
+ 'parent-width'?: number;
27
+ 'parent-height'?: number;
28
+ 'external-var-context'?: Record<string, any>;
19
29
  bindchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void;
20
30
  }
21
31
 
@@ -30,14 +40,21 @@ export interface CarouseProps {
30
40
  dotColor?: string;
31
41
  activeDotColor?: string;
32
42
  horizontal?: boolean;
33
- style?: string;
34
- easingFunction?: string;
43
+ easingFunction?: EaseType;
35
44
  previousMargin?: number;
36
45
  nextMargin?: number;
37
46
  enableOffset?: boolean;
47
+ parentFontSize?: number;
48
+ parentWidth?: number;
49
+ parentHeight?: number;
38
50
  bindchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void;
39
- getInnerLayout: Function,
51
+ getInnerLayout: Function;
40
52
  innerProps: Object;
53
+ style: {
54
+ [key: string]: any
55
+ };
56
+ enableVar: boolean;
57
+ externalVarContext?: Record<string, any>;
41
58
  }
42
59
 
43
60
  export interface CarouseState {
@@ -55,6 +72,7 @@ export interface CarouseState {
55
72
  autoplayEnd: boolean;
56
73
  loopJump: boolean;
57
74
  dir: 'x' | 'y';
75
+ isScrollEnd: boolean
58
76
  }
59
77
 
60
78
  export interface ScrollElementProps {
@@ -1,27 +1,53 @@
1
- import { View } from 'react-native'
2
- import React, { forwardRef, useRef } from 'react'
1
+ import { View, LayoutChangeEvent } from 'react-native'
2
+ import { ReactNode, forwardRef, useRef } from 'react'
3
3
  import useInnerProps from './getInnerListeners'
4
4
  import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
5
+ import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout } from './utils'
5
6
 
6
7
  interface SwiperItemProps {
7
8
  'item-id'?: string;
8
9
  'enable-offset'?: boolean;
9
- children?: React.ReactNode;
10
+ 'enable-var': boolean;
11
+ 'external-var-context'?: Record<string, any>;
12
+ 'parent-font-size'?: number;
13
+ 'parent-width'?: number;
14
+ 'parent-height'?: number;
15
+ children?: ReactNode;
16
+ style?: Object;
10
17
  }
11
18
 
12
19
  const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProps>((props: SwiperItemProps, ref) => {
13
- const { children, 'enable-offset': enableOffset } = props
14
- const layoutRef = useRef({})
20
+ const {
21
+ 'enable-offset': enableOffset,
22
+ 'enable-var': enableVar,
23
+ 'external-var-context': externalVarContext,
24
+ style
25
+ } = props
26
+
27
+ const { textProps } = splitProps(props)
15
28
  const { nodeRef } = useNodesRef(props, ref, {})
16
29
 
17
- const onLayout = () => {
18
- nodeRef.current?.measure((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
19
- layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
20
- })
21
- }
30
+ const {
31
+ normalStyle,
32
+ hasVarDec,
33
+ varContextRef,
34
+ hasSelfPercent,
35
+ setWidth,
36
+ setHeight
37
+ } = useTransformStyle(style, { enableVar, externalVarContext })
38
+ const { textStyle, innerStyle } = splitStyle(normalStyle)
39
+
40
+ const {
41
+ // 存储layout布局信息
42
+ layoutRef,
43
+ layoutProps,
44
+ layoutStyle
45
+ } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef })
22
46
 
23
47
  const innerProps = useInnerProps(props, {
24
- ...(enableOffset ? { onLayout } : {}),
48
+ style: { ...innerStyle, ...layoutStyle },
49
+ ref: nodeRef,
50
+ ...layoutProps
25
51
  }, [
26
52
  'children',
27
53
  'enable-offset'
@@ -29,14 +55,23 @@ const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProp
29
55
 
30
56
  return (
31
57
  <View
32
- ref={nodeRef}
33
58
  data-itemId={props['item-id']}
34
59
  {...innerProps}>
35
- {children}
60
+ {
61
+ wrapChildren(
62
+ props,
63
+ {
64
+ hasVarDec,
65
+ varContext: varContextRef.current,
66
+ textStyle,
67
+ textProps
68
+ }
69
+ )
70
+ }
36
71
  </View>
37
72
  )
38
73
  })
39
74
 
40
- _SwiperItem.displayName = 'mpx-swiper-item';
75
+ _SwiperItem.displayName = 'mpx-swiper-item'
41
76
 
42
77
  export default _SwiperItem
@@ -0,0 +1,148 @@
1
+ /**
2
+ * ✔ checked
3
+ * ✔ type
4
+ * ✔ disabled
5
+ * ✔ color
6
+ */
7
+ import { Switch, SwitchProps, ViewStyle, NativeSyntheticEvent, LayoutChangeEvent } from 'react-native'
8
+ import { useRef, useEffect, forwardRef, JSX, useState, useContext } from 'react'
9
+ import { warn } from '@mpxjs/utils'
10
+ import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
11
+ import useInnerProps, { getCustomEvent } from './getInnerListeners'
12
+
13
+ import CheckBox from './mpx-checkbox'
14
+ import { FormContext, FormFieldValue } from './context'
15
+ import { useTransformStyle, useLayout } from './utils'
16
+
17
+ interface _SwitchProps extends SwitchProps {
18
+ style?: ViewStyle
19
+ name?: string
20
+ checked?: boolean
21
+ type: 'switch' | 'checkbox'
22
+ disabled: boolean
23
+ color: string
24
+ 'enable-var'?: boolean
25
+ 'parent-font-size'?: number
26
+ 'parent-width'?: number
27
+ 'parent-height'?: number
28
+ 'external-var-context'?: Record<string, any>
29
+ bindchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
30
+ catchchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
31
+ }
32
+
33
+ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((props, ref): JSX.Element => {
34
+ const {
35
+ style = {},
36
+ checked = false,
37
+ type = 'switch',
38
+ disabled = false,
39
+ color = '#04BE02',
40
+ 'enable-var': enableVar,
41
+ 'external-var-context': externalVarContext,
42
+ 'parent-font-size': parentFontSize,
43
+ 'parent-width': parentWidth,
44
+ 'parent-height': parentHeight,
45
+
46
+ bindchange,
47
+ catchchange
48
+ } = props
49
+
50
+ const [isChecked, setIsChecked] = useState<boolean>(checked)
51
+
52
+ const changeHandler = bindchange || catchchange
53
+
54
+ let formValuesMap: Map<string, FormFieldValue> | undefined
55
+
56
+ const formContext = useContext(FormContext)
57
+
58
+ if (formContext) {
59
+ formValuesMap = formContext.formValuesMap
60
+ }
61
+
62
+ const {
63
+ normalStyle,
64
+ hasSelfPercent,
65
+ setWidth,
66
+ setHeight
67
+ } = useTransformStyle(style, {
68
+ enableVar,
69
+ externalVarContext,
70
+ parentFontSize,
71
+ parentWidth,
72
+ parentHeight
73
+ })
74
+
75
+ useEffect(() => {
76
+ setIsChecked(checked)
77
+ }, [checked])
78
+
79
+ const { nodeRef } = useNodesRef<Switch, _SwitchProps>(props, ref)
80
+
81
+ const {
82
+ layoutRef,
83
+ layoutStyle,
84
+ layoutProps
85
+ } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
86
+
87
+ const onChange = (evt: NativeSyntheticEvent<TouchEvent> | boolean, { checked }: { checked?: boolean } = {}) => {
88
+ if (type === 'switch') {
89
+ setIsChecked(evt as boolean)
90
+ changeHandler && changeHandler(getCustomEvent('change', {}, { layoutRef, detail: { value: evt } }, props))
91
+ } else {
92
+ setIsChecked(checked as boolean)
93
+ changeHandler && changeHandler(getCustomEvent('change', evt, { layoutRef, detail: { value: checked } }, props))
94
+ }
95
+ }
96
+
97
+ const resetValue = () => {
98
+ setIsChecked(false)
99
+ }
100
+
101
+ const getValue = () => {
102
+ return isChecked
103
+ }
104
+
105
+ if (formValuesMap) {
106
+ if (!props.name) {
107
+ warn('If a form component is used, the name attribute is required.')
108
+ } else {
109
+ formValuesMap.set(props.name, { getValue, resetValue })
110
+ }
111
+ }
112
+
113
+ const innerProps = useInnerProps(props, {
114
+ ref: nodeRef,
115
+ style: { ...normalStyle, ...layoutStyle },
116
+ ...layoutProps,
117
+ ...!disabled ? { [type === 'switch' ? 'onValueChange' : '_onChange']: onChange } : {}
118
+ }, [
119
+ 'checked',
120
+ 'disabled',
121
+ 'type',
122
+ 'color'
123
+ ], {
124
+ layoutRef
125
+ })
126
+
127
+ if (type === 'checkbox') {
128
+ return <CheckBox
129
+ {...innerProps}
130
+ color={color}
131
+ style={normalStyle}
132
+ checked={isChecked}
133
+ />
134
+ }
135
+
136
+ return <Switch
137
+ {...innerProps}
138
+ style={normalStyle}
139
+ value={isChecked}
140
+ trackColor={{ false: '#FFF', true: color }}
141
+ thumbColor={isChecked ? '#FFF' : '#f4f3f4'}
142
+ ios_backgroundColor="#FFF"
143
+ />
144
+ })
145
+
146
+ _Switch.displayName = 'mpx-switch'
147
+
148
+ export default _Switch
@@ -4,101 +4,77 @@
4
4
  * ✘ space
5
5
  * ✘ decode
6
6
  */
7
- import { Text, TextStyle, TextProps, StyleSheet } from 'react-native'
8
- import { useRef, useEffect, forwardRef, ReactNode, ForwardedRef, JSX } from 'react';
7
+ import { Text, TextStyle, TextProps } from 'react-native'
8
+ import { useRef, forwardRef, ReactNode, JSX } from 'react'
9
9
  import useInnerProps from './getInnerListeners'
10
- // @ts-ignore
11
10
  import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
12
- import { PERCENT_REGEX } from './utils'
13
-
11
+ import { useTransformStyle, wrapChildren } from './utils'
14
12
 
15
13
  interface _TextProps extends TextProps {
16
14
  style?: TextStyle
17
15
  children?: ReactNode
18
16
  selectable?: boolean
19
- 'enable-offset'?: boolean
20
17
  'user-select'?: boolean
21
- userSelect?: boolean
22
- ['disable-default-style']?: boolean
23
- }
24
-
25
- const DEFAULT_STYLE = {
26
- fontSize: 16
27
- }
28
-
29
- const transformStyle = (styleObj: TextStyle) => {
30
- let { lineHeight } = styleObj
31
- if (typeof lineHeight === 'string' && PERCENT_REGEX.test(lineHeight)) {
32
- lineHeight = (parseFloat(lineHeight)/100) * (styleObj.fontSize || DEFAULT_STYLE.fontSize)
33
- styleObj.lineHeight = lineHeight
34
- }
18
+ 'enable-var'?: boolean
19
+ 'external-var-context'?: Record<string, any>
20
+ 'parent-font-size'?: number
21
+ 'parent-width'?: number
22
+ 'parent-height'?: number
35
23
  }
36
24
 
37
25
  const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref): JSX.Element => {
38
26
  const {
39
- style = [],
40
- children,
27
+ style = {},
41
28
  selectable,
42
- 'enable-offset': enableOffset,
29
+ 'enable-var': enableVar,
30
+ 'external-var-context': externalVarContext,
43
31
  'user-select': userSelect,
44
- 'disable-default-style': disableDefaultStyle = false,
45
- } = props
46
-
47
- const layoutRef = useRef({})
48
-
49
- const styleObj: TextStyle = StyleSheet.flatten<TextStyle>(style)
32
+ 'parent-font-size': parentFontSize,
33
+ 'parent-width': parentWidth,
34
+ 'parent-height': parentHeight
35
+ } = props
50
36
 
51
- let defaultStyle = {}
37
+ const layoutRef = useRef({})
52
38
 
53
- if (!disableDefaultStyle) {
54
- defaultStyle = DEFAULT_STYLE
55
- transformStyle(styleObj)
56
- }
57
-
58
- const { nodeRef } = useNodesRef<Text, _TextProps>(props, ref, {
59
- defaultStyle
60
- })
61
-
62
- const innerProps = useInnerProps(props, {
63
- ref: nodeRef
64
- }, [
65
- 'style',
66
- 'children',
67
- 'selectable',
68
- 'user-select',
69
- 'useInherit',
70
- 'enable-offset'
71
- ], {
72
- layoutRef
73
- })
74
-
75
- useEffect(() => {
76
- let measureTimeout: ReturnType<typeof setTimeout> | null = null
77
- if (enableOffset) {
78
- measureTimeout = setTimeout(() => {
79
- nodeRef.current?.measure((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
80
- layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
81
- })
82
- })
83
- return () => {
84
- if (measureTimeout) {
85
- clearTimeout(measureTimeout)
86
- measureTimeout = null
39
+ const {
40
+ normalStyle,
41
+ hasVarDec,
42
+ varContextRef
43
+ } = useTransformStyle(style, {
44
+ enableVar,
45
+ externalVarContext,
46
+ parentFontSize,
47
+ parentWidth,
48
+ parentHeight
49
+ })
50
+
51
+ const { nodeRef } = useNodesRef<Text, _TextProps>(props, ref)
52
+
53
+ const innerProps = useInnerProps(props, {
54
+ ref: nodeRef,
55
+ style: normalStyle,
56
+ selectable: !!selectable || !!userSelect
57
+ }, [
58
+ 'user-select'
59
+ ], {
60
+ layoutRef
61
+ })
62
+
63
+ return (
64
+ <Text
65
+ {...innerProps}
66
+ >
67
+ {
68
+ wrapChildren(
69
+ props,
70
+ {
71
+ hasVarDec,
72
+ varContext: varContextRef.current
87
73
  }
88
- }
74
+ )
89
75
  }
90
- }, [])
91
-
92
-
93
- return (
94
- <Text
95
- style={{...defaultStyle, ...styleObj}}
96
- selectable={!!selectable || !!userSelect}
97
- {...innerProps}
98
- >
99
- {children}
100
- </Text>
101
- )
76
+ </Text>
77
+ )
102
78
  })
103
79
 
104
80
  _Text.displayName = 'mpx-text'
@@ -9,7 +9,7 @@
9
9
  * ✘ show-confirm-bar
10
10
  * ✔ bindlinechange: No `heightRpx` info.
11
11
  */
12
- import React, { forwardRef } from 'react'
12
+ import { JSX, forwardRef } from 'react'
13
13
  import { Keyboard, TextInput } from 'react-native'
14
14
  import Input, { InputProps, PrivateInputProps } from './mpx-input'
15
15
  import { omit } from './utils'
@@ -21,13 +21,13 @@ export type TextareProps = Omit<
21
21
  >
22
22
 
23
23
  const Textarea = forwardRef<HandlerRef<TextInput, TextareProps>, TextareProps>(
24
- (props, ref): React.JSX.Element => {
24
+ (props, ref): JSX.Element => {
25
25
  const restProps = omit(props, [
26
26
  'ref',
27
27
  'type',
28
28
  'password',
29
29
  'multiline',
30
- 'confirm-hold',
30
+ 'confirm-hold'
31
31
  ])
32
32
  return (
33
33
  <Input