@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
@@ -8,11 +8,11 @@
8
8
  * ✔ delta
9
9
  */
10
10
  import { View } from 'react-native'
11
- import { useCallback, forwardRef, JSX } from 'react';
11
+ import { useCallback, forwardRef, JSX } from 'react'
12
12
  import useInnerProps from './getInnerListeners'
13
13
  import { redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy'
14
14
 
15
- import MpxView, { _ViewProps } from './mpx-view'
15
+ import MpxView, { _ViewProps } from './mpx-view'
16
16
 
17
17
  interface _NavigatorProps extends _ViewProps {
18
18
  ['open-type']: 'navigate' | 'redirect' | 'switchTab' | 'reLaunch' | 'navigateBack'
@@ -4,7 +4,7 @@ import React, { forwardRef, useState, useRef, useEffect } from 'react'
4
4
  import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
5
5
  import { DateProps, LayoutType } from './type'
6
6
 
7
- function formatTimeStr(time = ''): Date {
7
+ function formatTimeStr (time = ''): Date {
8
8
  let [year, month, day]: any = time.split('-')
9
9
  year = ~~year || 2000
10
10
  month = ~~month || 1
@@ -26,13 +26,13 @@ function dateToString (date: Date, fields: 'day' | 'month' | 'year' = 'day'): st
26
26
  return ret
27
27
  }
28
28
 
29
-
30
- const _DatePicker = forwardRef<HandlerRef<View, DateProps>, DateProps>((props: DateProps, ref): React.JSX.Element => {
29
+ const _DatePicker = forwardRef<HandlerRef<View, DateProps>, DateProps>((props: DateProps, ref): React.JSX.Element => {
31
30
  const { children, start = '1970-01-01', end = '2999-01-01', value, bindchange, bindcancel, disabled, fields } = props
32
31
  const [datevalue, setDateValue] = useState(value)
33
32
  // 存储layout布局信息
34
33
  const layoutRef = useRef({})
35
- const { nodeRef: viewRef } = useNodesRef<View, DateProps>(props, ref, {
34
+ const viewRef = useRef<View>(null)
35
+ useNodesRef<View, DateProps>(props, ref, viewRef, {
36
36
  })
37
37
 
38
38
  useEffect(() => {
@@ -1,6 +1,7 @@
1
1
  import { View } from 'react-native'
2
2
  import { PickerValue } from '@ant-design/react-native'
3
3
  import React, { forwardRef, useRef, useContext, useState } from 'react'
4
+ import { warn } from '@mpxjs/utils'
4
5
  import useInnerProps, { getCustomEvent } from '../getInnerListeners'
5
6
  import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
6
7
  import Selector from './selector'
@@ -10,7 +11,6 @@ import MultiSelector from './multiSelector'
10
11
  import RegionSelector from './region'
11
12
  import { PickerProps, EventType, ValueType } from './type'
12
13
  import { FormContext, FormFieldValue } from '../context'
13
- import { throwReactWarning } from '../utils'
14
14
 
15
15
  /**
16
16
  * ✔ mode
@@ -33,8 +33,9 @@ import { throwReactWarning } from '../utils'
33
33
 
34
34
  const _Picker = forwardRef<HandlerRef<View, PickerProps>, PickerProps>((props: PickerProps, ref): React.JSX.Element => {
35
35
  const { mode = 'selector', value, bindcancel, bindchange, children, bindcolumnchange } = props
36
- let innerLayout = useRef({})
37
- const { nodeRef } = useNodesRef<View, PickerProps>(props, ref, {
36
+ const innerLayout = useRef({})
37
+ const nodeRef = useRef(null)
38
+ useNodesRef<View, PickerProps>(props, ref, nodeRef, {
38
39
  })
39
40
  const innerProps = useInnerProps(props, {
40
41
  ref: nodeRef
@@ -69,7 +70,7 @@ const _Picker = forwardRef<HandlerRef<View, PickerProps>, PickerProps>((props: P
69
70
  }
70
71
  if (formValuesMap) {
71
72
  if (!props.name) {
72
- throwReactWarning('[Mpx runtime warn]: If a form component is used, the name attribute is required.')
73
+ warn('If a form component is used, the name attribute is required.')
73
74
  } else {
74
75
  formValuesMap.set(props.name, { getValue, resetValue })
75
76
  }
@@ -103,29 +104,29 @@ const _Picker = forwardRef<HandlerRef<View, PickerProps>, PickerProps>((props: P
103
104
  const selectorProps = {
104
105
  ...commonProps,
105
106
  value: pickerValue as PickerValue,
106
- range: props['range'],
107
+ range: props.range,
107
108
  'range-key': props['range-key']
108
109
  }
109
110
 
110
111
  const multiProps = {
111
112
  ...commonProps,
112
113
  value: pickerValue as Array<number>,
113
- range: props['range'],
114
+ range: props.range,
114
115
  'range-key': props['range-key']
115
116
  }
116
117
 
117
118
  const timeProps = {
118
119
  ...commonProps,
119
120
  value: pickerValue as string,
120
- start: props['start'],
121
- end: props['end']
121
+ start: props.start,
122
+ end: props.end
122
123
  }
123
124
 
124
125
  const dateProps = {
125
126
  ...commonProps,
126
127
  value: pickerValue as string,
127
- start: props['start'],
128
- end: props['end'],
128
+ start: props.start,
129
+ end: props.end,
129
130
  fileds: props.fields || 'day'
130
131
  }
131
132
 
@@ -150,6 +151,6 @@ const _Picker = forwardRef<HandlerRef<View, PickerProps>, PickerProps>((props: P
150
151
  }
151
152
  })
152
153
 
153
- _Picker.displayName = 'mpx-picker';
154
+ _Picker.displayName = 'mpx-picker'
154
155
 
155
156
  export default _Picker
@@ -4,7 +4,7 @@ import React, { forwardRef, useState, useRef, useEffect } from 'react'
4
4
  import { MultiSelectorProps, LayoutType } from './type'
5
5
  import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
6
6
 
7
- function convertToObj(item?: any, rangeKey = ''): any {
7
+ function convertToObj (item?: any, rangeKey = ''): any {
8
8
  if (typeof item === 'object') {
9
9
  return { value: item[rangeKey], label: item[rangeKey] }
10
10
  } else {
@@ -13,13 +13,13 @@ function convertToObj(item?: any, rangeKey = ''): any {
13
13
  }
14
14
 
15
15
  // eslint-disable-next-line default-param-last
16
- function formatRangeFun(range: any[][] = [], rangeKey?: string): any[] {
16
+ function formatRangeFun (range: any[][] = [], rangeKey?: string): any[] {
17
17
  const result = (range[0] || []).map(item => {
18
18
  return convertToObj(item, rangeKey)
19
19
  })
20
20
  let tmp = result
21
21
  for (let i = 1; i < range.length; i++) {
22
- let child = Array.isArray(range[i]) ? range[i] : []
22
+ const child = Array.isArray(range[i]) ? range[i] : []
23
23
  const nextColData = child.map(item => {
24
24
  return convertToObj(item, rangeKey)
25
25
  })
@@ -31,7 +31,7 @@ function formatRangeFun(range: any[][] = [], rangeKey?: string): any[] {
31
31
  return result
32
32
  }
33
33
 
34
- function getIndexByValues(range: any[] = [], value: any[] = []): number[] {
34
+ function getIndexByValues (range: any[] = [], value: any[] = []): number[] {
35
35
  let tmp = range
36
36
  return value.map(v => {
37
37
  for (let i = 0; i < tmp.length; i++) {
@@ -44,16 +44,16 @@ function getIndexByValues(range: any[] = [], value: any[] = []): number[] {
44
44
  })
45
45
  }
46
46
  // [1,1,2] 寻找出[]
47
- function getInnerValueByIndex(range: any[] = [], value: any[] = []): string[] {
47
+ function getInnerValueByIndex (range: any[] = [], value: any[] = []): string[] {
48
48
  let tmp = range
49
49
  return value.map(v => {
50
- let current = tmp[v].value
50
+ const current = tmp[v].value
51
51
  tmp = tmp[v].children
52
52
  return current
53
53
  })
54
54
  }
55
55
  // column = 1 value = ['无脊柱动物', '扁性动物', '吸血虫'] 根据column 和value 获取到当前列变动选择的值所在当前列的索引
56
- function getColumnIndexByValue(range: any[] = [], column: number, value: any[] = []): number {
56
+ function getColumnIndexByValue (range: any[] = [], column: number, value: any[] = []): number {
57
57
  let curRange = range
58
58
  let changeIndex = 0
59
59
  let tmpRange: any[] = []
@@ -63,30 +63,34 @@ function getColumnIndexByValue(range: any[] = [], column: number, value: any[] =
63
63
  if (ritem.value === item) {
64
64
  changeIndex = rindex
65
65
  }
66
+ return ritem
66
67
  })
67
68
  } else {
68
- curRange.map((citem, cindex) => {
69
+ curRange.map((citem, cindex) => {
69
70
  if (citem.value === item) {
70
71
  tmpRange = citem.children
71
72
  }
72
- })
73
- curRange = tmpRange
73
+ return citem
74
+ })
75
+ curRange = tmpRange
74
76
  }
77
+ return item
75
78
  })
76
79
  return changeIndex
77
80
  }
78
81
 
79
82
  const _MultiSelectorPicker = forwardRef<HandlerRef<View, MultiSelectorProps>, MultiSelectorProps>((props: MultiSelectorProps, ref): React.JSX.Element => {
80
83
  const { range, value, disabled, bindchange, bindcancel, children, bindcolumnchange } = props
81
- let formatRange = formatRangeFun(range, props['range-key'])
82
- let initValue = getInnerValueByIndex(formatRange, value)
84
+ const formatRange = formatRangeFun(range, props['range-key'])
85
+ const initValue = getInnerValueByIndex(formatRange, value)
83
86
  // 选中的索引值
84
87
  const [selected, setSelected] = useState(initValue)
85
88
  // range数据源
86
89
  const [data, setData] = useState(formatRange || [])
87
90
  // 存储layout布局信息
88
91
  const layoutRef = useRef({})
89
- const { nodeRef: viewRef } = useNodesRef<View, MultiSelectorProps>(props, ref, {
92
+ const viewRef = useRef<View>(null)
93
+ useNodesRef<View, MultiSelectorProps>(props, ref, viewRef, {
90
94
  })
91
95
 
92
96
  useEffect(() => {
@@ -1,15 +1,17 @@
1
1
  import { View, TouchableWithoutFeedback } from 'react-native'
2
- import { Picker } from '@ant-design/react-native'
2
+ import { Picker, PickerColumnItem } from '@ant-design/react-native'
3
3
  import { regionData } from './regionData'
4
4
  import React, { forwardRef, useState, useRef } from 'react'
5
5
  import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
6
- import { RegionProps, RegionObj, PickerData, LayoutType } from './type'
6
+ import { RegionProps, RegionObj, LayoutType } from './type'
7
7
 
8
- function formateRegionData(clObj: RegionObj[] = [], customItem?: string, depth = 2): PickerData[] {
8
+ function formateRegionData (clObj: RegionObj[] = [], customItem?: string, depth = 2): PickerColumnItem[] {
9
9
  const l = depth
10
- const obj: PickerData[] = []
10
+ // 'PickerData[]' is not assignable to type 'PickerColumn | PickerColumn[]'.
11
+ // const obj: PickerColumnItem[] = []
12
+ const obj: PickerColumnItem[] = []
11
13
  if (customItem) {
12
- const objClone: PickerData = {
14
+ const objClone: PickerColumnItem = {
13
15
  value: customItem,
14
16
  label: customItem,
15
17
  children: []
@@ -18,14 +20,14 @@ function formateRegionData(clObj: RegionObj[] = [], customItem?: string, depth =
18
20
  let loop = panding
19
21
  while (depth-- > 0) {
20
22
  loop.children = [{ ...objClone }]
21
- loop = loop.children[0] as PickerData
23
+ loop = loop.children[0] as PickerColumnItem
22
24
  }
23
- obj.push(panding)
25
+ obj.push(panding as PickerColumnItem)
24
26
  }
25
27
  for (let i = 0; i < clObj.length; i++) {
26
- const region: PickerData = {
28
+ const region: PickerColumnItem = {
27
29
  value: clObj[i].value,
28
- label: clObj[i].value,
30
+ label: clObj[i].value
29
31
  }
30
32
  if (clObj[i].children) {
31
33
  region.children = formateRegionData(clObj[i].children, customItem, l - 1)
@@ -35,16 +37,15 @@ function formateRegionData(clObj: RegionObj[] = [], customItem?: string, depth =
35
37
  return obj
36
38
  }
37
39
 
38
-
39
-
40
40
  const _RegionPicker = forwardRef<HandlerRef<View, RegionProps>, RegionProps>((props: RegionProps, ref): React.JSX.Element => {
41
41
  const { children, value, bindchange, bindcancel, disabled } = props
42
- let formatRegionData = formateRegionData(regionData, props['custom-item'])
42
+ const formatRegionData = formateRegionData(regionData, props['custom-item'])
43
43
 
44
44
  const [regionvalue, setRegionValue] = useState(value)
45
45
  // 存储layout布局信息
46
46
  const layoutRef = useRef({})
47
- const { nodeRef: viewRef } = useNodesRef<View, RegionProps>(props, ref, {
47
+ const viewRef = useRef<View>(null)
48
+ useNodesRef<View, RegionProps>(props, ref, viewRef, {
48
49
  })
49
50
 
50
51
  const onChange = (value: string[]): void => {
@@ -60,6 +61,7 @@ const _RegionPicker = forwardRef<HandlerRef<View, RegionProps>, RegionProps>((pr
60
61
  return code
61
62
  }
62
63
  }
64
+ return item
63
65
  }).filter(code => !!code)
64
66
  const detail: Record<string, any> = { value, code }
65
67
  if (postcode[2]) detail.postcode = postcode[2]
@@ -75,13 +77,17 @@ const _RegionPicker = forwardRef<HandlerRef<View, RegionProps>, RegionProps>((pr
75
77
  props.getInnerLayout && props.getInnerLayout(layoutRef)
76
78
  })
77
79
  }
78
-
80
+
81
+ const onDismiss = (): void => {
82
+ bindcancel && bindcancel()
83
+ }
84
+
79
85
  const regionProps = {
80
86
  data: formatRegionData,
81
87
  value: regionvalue,
82
88
  onChange,
83
89
  disabled,
84
- onDismiss: bindcancel && bindcancel
90
+ onDismiss
85
91
  }
86
92
 
87
93
  const touchProps = {
@@ -90,15 +96,13 @@ const _RegionPicker = forwardRef<HandlerRef<View, RegionProps>, RegionProps>((pr
90
96
  }
91
97
 
92
98
  return (
93
- // @ts-ignore
94
99
  <Picker {...regionProps}>
95
100
  <TouchableWithoutFeedback>
96
101
  <View {...touchProps}>{children}</View>
97
102
  </TouchableWithoutFeedback>
98
103
  </Picker>
99
104
  )
100
-
101
105
  })
102
106
 
103
- _RegionPicker.displayName === 'mpx-picker-region'
104
- export default _RegionPicker
107
+ _RegionPicker.displayName = 'mpx-picker-region'
108
+ export default _RegionPicker
@@ -9,7 +9,7 @@ import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
9
9
 
10
10
  type RangeItemType = Obj | number | string
11
11
 
12
- const formatRangeFun = (range: Array<RangeItemType>, rangeKey = ''): any => {
12
+ const formatRangeFun = (range: Array<RangeItemType>, rangeKey = ''): any => {
13
13
  let newRange: Object[] = []
14
14
  newRange = (range || []).map((item: RangeItemType, index) => {
15
15
  if (typeof item === 'object') {
@@ -24,14 +24,15 @@ const formatRangeFun = (range: Array<RangeItemType>, rangeKey = ''): any => {
24
24
  const _SelectorPicker = forwardRef<HandlerRef<View, SelectorProps>, SelectorProps>((props: SelectorProps, ref): React.JSX.Element => {
25
25
  const { range, children, value, disabled, bindchange, bindcancel } = props
26
26
  // 格式化数据为Array<*>
27
- let formatRange: PickerColumn = formatRangeFun(range, props['range-key'])
27
+ const formatRange: PickerColumn = formatRangeFun(range, props['range-key'])
28
28
  // 选中的索引值
29
29
  const [selected, setSelected] = useState<PickerValue>(value || 0)
30
30
  // range数据源
31
31
  const [data, setData] = useState(formatRange || [])
32
32
  // 存储layout布局信息
33
33
  const layoutRef = useRef({})
34
- const { nodeRef: viewRef } = useNodesRef<View, SelectorProps>(props, ref, {
34
+ const viewRef = useRef<View>(null)
35
+ useNodesRef<View, SelectorProps>(props, ref, viewRef, {
35
36
  })
36
37
 
37
38
  useEffect(() => {
@@ -44,7 +45,7 @@ const _SelectorPicker = forwardRef<HandlerRef<View, SelectorProps>, SelectorProp
44
45
  })
45
46
  }, [range, value])
46
47
  const defaultValue = [value]
47
-
48
+
48
49
  const onChange = (value: PickerValue[]) => {
49
50
  bindchange && bindchange({
50
51
  detail: {
@@ -60,7 +61,6 @@ const _SelectorPicker = forwardRef<HandlerRef<View, SelectorProps>, SelectorProp
60
61
  })
61
62
  }
62
63
 
63
-
64
64
  const antPickerProps = {
65
65
  data,
66
66
  value: [selected],
@@ -69,7 +69,7 @@ const _SelectorPicker = forwardRef<HandlerRef<View, SelectorProps>, SelectorProp
69
69
  itemHeight: 40,
70
70
  onChange,
71
71
  onDismiss: bindcancel && bindcancel
72
- } as any
72
+ } as any
73
73
 
74
74
  const touchProps = {
75
75
  onLayout: onElementLayout,
@@ -87,6 +87,6 @@ const _SelectorPicker = forwardRef<HandlerRef<View, SelectorProps>, SelectorProp
87
87
  )
88
88
  })
89
89
 
90
- _SelectorPicker.displayName = 'mpx-picker-selector';
90
+ _SelectorPicker.displayName = 'mpx-picker-selector'
91
91
 
92
92
  export default _SelectorPicker
@@ -8,48 +8,47 @@ import { TimeProps } from './type'
8
8
  // const { height: dHeight, width: dWidth } = Dimensions.get('window');
9
9
  // modal属性: {"height": 298.33331298828125, "offsetLeft": 0, "offsetTop": 513.6666870117188, "width": 375, "x": 0, "y": 513.6666870117188}
10
10
  // const { height: sHeight, width: sWidth } = Dimensions.get('screen');
11
- // 设备屏幕的大小。 screen
12
-
11
+ // 设备屏幕的大小。 screen
13
12
  const styles: { [key: string]: Object } = {
14
13
  showModal: {
15
- backgroundColor: "black",
14
+ backgroundColor: 'black',
16
15
  opacity: 0.5,
17
- position: "absolute",
18
- width: "100%"
16
+ position: 'absolute',
17
+ width: '100%'
19
18
  },
20
19
  hideModal: {
21
20
  opacity: 1,
22
21
  height: 0
23
22
  },
24
23
  modal: {
25
- backgroundColor: "black",
24
+ backgroundColor: 'black',
26
25
  opacity: 0.5
27
26
  },
28
27
  centeredView: {
29
28
  position: 'absolute',
30
29
  bottom: 0,
31
- width: "100%",
30
+ width: '100%',
32
31
  overflow: 'scroll'
33
32
  },
34
33
  btnLine: {
35
- width: "100%",
34
+ width: '100%',
36
35
  flex: 1,
37
- flexDirection: "row",
38
- justifyContent: "space-between",
36
+ flexDirection: 'row',
37
+ justifyContent: 'space-between',
39
38
  borderColor: 20,
40
39
  borderBottomWidth: 1,
41
- backgroundColor: "white",
40
+ backgroundColor: 'white',
42
41
  paddingLeft: 40,
43
42
  paddingRight: 40
44
43
  },
45
44
  cancel: {
46
45
  height: 50,
47
- display: "flex",
46
+ display: 'flex',
48
47
  justifyContent: 'center'
49
48
  },
50
49
  ok: {
51
50
  height: 50,
52
- display: "flex",
51
+ display: 'flex',
53
52
  justifyContent: 'center'
54
53
  },
55
54
  btntext: {
@@ -58,12 +57,12 @@ const styles: { [key: string]: Object } = {
58
57
  }
59
58
  }
60
59
 
61
- function formatStrToInt(timestr: string) {
62
- let [start, end] = timestr.split(':')
60
+ function formatStrToInt (timestr: string) {
61
+ const [start, end] = timestr.split(':')
63
62
  return [parseInt(start), parseInt(end)]
64
63
  }
65
64
  // [9, 59] to 09:59
66
- function formatStr(arr: any[]) {
65
+ function formatStr (arr: any[]) {
67
66
  let [hour, minute] = arr
68
67
  if (hour < 10) {
69
68
  hour = '0' + hour
@@ -74,10 +73,10 @@ function formatStr(arr: any[]) {
74
73
  return hour + ':' + minute
75
74
  }
76
75
 
77
- function generateMinute() {
78
- let arrMinute: any[] = []
76
+ function generateMinute () {
77
+ const arrMinute: any[] = []
79
78
  for (let i = 0; i <= 59; i++) {
80
- let obj = {
79
+ const obj = {
81
80
  label: toSingleStr(i),
82
81
  value: i,
83
82
  children: []
@@ -86,10 +85,10 @@ function generateMinute() {
86
85
  }
87
86
  return arrMinute
88
87
  }
89
- function generateColumns(): any[] {
90
- let pickData: any[] = []
88
+ function generateColumns (): any[] {
89
+ const pickData: any[] = []
91
90
  for (let i = 0; i <= 23; i++) {
92
- let obj = {
91
+ const obj = {
93
92
  label: toSingleStr(i),
94
93
  value: i,
95
94
  children: generateMinute()
@@ -100,18 +99,18 @@ function generateColumns(): any[] {
100
99
  return pickData
101
100
  }
102
101
 
103
- function toSingleStr(str: number) {
102
+ function toSingleStr (str: number) {
104
103
  return str < 10 ? '0' + str : str
105
104
  }
106
105
 
107
- function toStr(time: string): string {
106
+ function toStr (time: string): string {
108
107
  const [hour, minute]: any = formatStrToInt(time)
109
108
  const newHour = toSingleStr(hour)
110
109
  const newMinute = toSingleStr(minute)
111
110
  return '' + newHour + newMinute
112
111
  }
113
112
 
114
- function checkSelectedIsValid(strStart: string, strEnd: string, selected: number[]): Boolean {
113
+ function checkSelectedIsValid (strStart: string, strEnd: string, selected: number[]): boolean {
115
114
  const strSel = '' + toSingleStr(selected[0]) + toSingleStr(selected[1])
116
115
  if (strSel < strStart || strSel > strEnd) return false
117
116
  return true
@@ -135,10 +134,12 @@ const _TimePicker = forwardRef<HandlerRef<View, TimeProps>, TimeProps>((props: T
135
134
  const [timevalue, setTimeValue] = useState(defaultValue)
136
135
  // 存储layout布局信息
137
136
  const layoutRef = useRef({})
138
- const { nodeRef: viewRef } = useNodesRef<View, TimeProps>(props, ref, {})
137
+ const viewRef = useRef<View>(null)
138
+ useNodesRef<View, TimeProps>(props, ref, viewRef, {})
139
139
  // 存储modal的布局信息
140
140
  const modalLayoutRef = useRef({})
141
- const { nodeRef: modalRef } = useNodesRef<View, TimeProps>(props, ref, {})
141
+ const modalRef = useRef<View>(null)
142
+ useNodesRef<View, TimeProps>(props, ref, modalRef, {})
142
143
  const [visible, setVisible] = useState(false)
143
144
  const columnData = generateColumns()
144
145
  const [data, setData] = useState(columnData)
@@ -196,7 +197,6 @@ const _TimePicker = forwardRef<HandlerRef<View, TimeProps>, TimeProps>((props: T
196
197
  }
197
198
  }
198
199
 
199
-
200
200
  const onElementLayout = () => {
201
201
  viewRef.current?.measure((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
202
202
  layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
@@ -211,7 +211,6 @@ const _TimePicker = forwardRef<HandlerRef<View, TimeProps>, TimeProps>((props: T
211
211
  })
212
212
  }
213
213
 
214
-
215
214
  const renderModalChildren = () => {
216
215
  const pickerProps = {
217
216
  data,
@@ -250,7 +249,7 @@ const _TimePicker = forwardRef<HandlerRef<View, TimeProps>, TimeProps>((props: T
250
249
  </TouchableWithoutFeedback>
251
250
  </View>
252
251
  }
253
- const strStyle = visible ? styles['showModal'] : styles['hideModal']
252
+ const strStyle = visible ? styles.showModal : styles.hideModal
254
253
  const mheight = Math.floor(offsetTop)
255
254
 
256
255
  // Animated.View
@@ -271,4 +270,3 @@ const _TimePicker = forwardRef<HandlerRef<View, TimeProps>, TimeProps>((props: T
271
270
  _TimePicker.displayName = 'mpx-picker-time'
272
271
 
273
272
  export default _TimePicker
274
-
@@ -34,7 +34,7 @@ export type MultiSelectorProps = {
34
34
  getInnerLayout: Function
35
35
  }
36
36
 
37
- export type TimeProps = {
37
+ export type TimeProps = {
38
38
  mode: string,
39
39
  // 表示选择了 range 中的第几个(下标从 0 开始)
40
40
  value: string,