@aks-dev/easyui 1.0.135 → 1.0.137

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.
@@ -6,13 +6,6 @@ import { deviceHeight, deviceWidth } from '../../screen/px2dp';
6
6
  import { hidePopoverView, showPopoverView } from '../Hud/Hud';
7
7
 
8
8
  type State = {
9
- target?: LayoutRectangle;
10
- arrow?: Partial<{
11
- left: number | string;
12
- right: number | string;
13
- top: number;
14
- bottom: number;
15
- }>;
16
9
  }
17
10
 
18
11
 
@@ -22,17 +15,22 @@ type Reducer = (prevState: State, action: Partial<State>) => State
22
15
 
23
16
  export default (props: MenuProps) => {
24
17
 
18
+ const {
19
+ defaultAlignHorizontal = 'left',
20
+ defaultAlignVertical = 'bottom'
21
+ } = props
22
+
25
23
  const [state, dispatch] = React.useReducer<Reducer>((prevState, action) => Object.assign({}, prevState, action), {})
26
24
 
27
25
  // const containerRef = React.useRef<{ measureInWindow: (callback: MeasureInWindowOnSuccessCallback) => void }>()
28
26
  const containerRef = React.useRef<{ measure: (callback: MeasureOnSuccessCallback) => void }>()
29
- const _container = React.useRef<{
30
- x: number;
31
- y: number;
27
+ const rootView = React.useRef<{
28
+ pageX: number;
29
+ pageY: number;
32
30
  height: number;
33
31
  width: number;
34
- }>({ x: 0, y: 0, width: 0, height: 0 })
35
-
32
+ }>({ pageX: 0, pageY: 0, width: 0, height: 0 })
33
+ const sc = React.useRef<LayoutRectangle>({ x: 0, y: 0, width: 0, height: 0 })
36
34
 
37
35
  // React.useEffect(() => {
38
36
  // ; (async () => {
@@ -55,15 +53,15 @@ export default (props: MenuProps) => {
55
53
  const getRootViewlayoutPromise = () => {
56
54
  return new Promise((resovle, reject) => {
57
55
  containerRef.current?.measure((...args) => {
58
- // console.log('containerRef', args)
59
56
  if (args.length == 6) {
60
- _container.current = {
61
- x: args[4],
62
- y: args[5],
57
+ rootView.current = {
63
58
  width: args[2],
64
59
  height: args[3],
60
+ pageX: args[4],
61
+ pageY: args[5],
65
62
  }
66
63
  }
64
+ // console.log('RootView', rootView.current)
67
65
  resovle(args)
68
66
  })
69
67
  })
@@ -81,21 +79,22 @@ export default (props: MenuProps) => {
81
79
  target_height: number;
82
80
  }
83
81
  = () => {
84
- let alignVertical: 'bottom' | 'top' = 'bottom'
85
- let alignHorizontal: 'left' | 'right' = 'left'
86
- let width = _container.current.width
87
- let height = _container.current.height
88
- let x = _container.current.x
82
+ let alignVertical: 'bottom' | 'top' = defaultAlignVertical
83
+ let alignHorizontal: 'left' | 'right' = defaultAlignHorizontal
84
+ let width = rootView.current.width
85
+ let height = rootView.current.height
86
+ let x = rootView.current.pageX
89
87
  // let y = (StatusBar.currentHeight || 0) + _container.current.y + height
90
- let y = _container.current.y + height
88
+ let y = rootView.current.pageY + height
91
89
  if (x > Math.abs(deviceWidth - width - x)) {
92
90
  alignHorizontal = 'right'
93
91
  }
94
92
  if (y > deviceHeight * .5) {
95
93
  alignVertical = 'top'
96
94
  }
97
- const target_width = state.target?.width || 0
98
- const target_height = state.target?.height || 0
95
+ /**todo: target_width的获取是延迟的,所以这里又问题 */
96
+ const target_width = sc.current.width
97
+ const target_height = CELL_HEIGHT * (Math.min(props.data?.length || 0, 5) || 0)
99
98
  return {
100
99
  alignVertical,
101
100
  alignHorizontal,
@@ -126,6 +125,7 @@ export default (props: MenuProps) => {
126
125
  target_height,
127
126
  } = getLayoutInfos()
128
127
 
128
+ // console.log({ getLayoutInfos: getLayoutInfos() })
129
129
  const layout = () => {
130
130
  if (alignHorizontal == 'left') {
131
131
  if (target_width + x > deviceWidth) {
@@ -153,41 +153,45 @@ export default (props: MenuProps) => {
153
153
  }
154
154
  }
155
155
  if (alignVertical == 'bottom') {
156
- y = y + 10
156
+ y = y + PADDING
157
157
  return layout()
158
158
  } else {
159
- y = (StatusBar.currentHeight || 0) + _container.current.y - target_height - 10
159
+ y = rootView.current.pageY - target_height - PADDING * 2 - ARROW_HEIGHT
160
160
  return layout()
161
161
  }
162
162
  }
163
163
 
164
164
 
165
+ const PADDING = 10
166
+ const ARROW_HEIGHT = 12
167
+ const CELL_HEIGHT = 36
168
+
169
+
165
170
  const show = async () => {
166
171
  if (props.data == undefined || props.data?.length == 0) return
167
172
  /**重新获取rootview的定位 */
168
173
  await getRootViewlayoutPromise()
174
+ /**重新获取rootview的定位 */
169
175
  showPopoverView({
170
176
  content: (
171
177
  <TouchableOpacity
172
178
  activeOpacity={1}
173
179
  style={{
180
+
174
181
  position: 'absolute',
175
182
  minWidth: deviceWidth * 0.36,
176
183
  maxWidth: deviceWidth * 0.8,
177
- minHeight: 36 + 20,
178
- maxHeight: 36 * 5 + 20,
184
+ minHeight: CELL_HEIGHT + PADDING * 2,
185
+ maxHeight: CELL_HEIGHT * 5 + PADDING * 2,
179
186
  borderRadius: 6, backgroundColor: '#000000ee',
180
187
  // overflow: 'hidden' ,
181
- padding: 10,
188
+ padding: PADDING,
182
189
  ...reLayout()
183
190
  }}
184
- // onLayout={e=>{
185
- // console.log('onLayout TouchableOpacity', e.nativeEvent.layout)
186
- // }}
187
191
  >
188
192
 
189
193
  <View style={{
190
- width: 12, height: 12,
194
+ width: ARROW_HEIGHT, height: ARROW_HEIGHT,
191
195
  backgroundColor: '#000000ee', position: 'absolute', zIndex: 1,
192
196
  transform: [{ rotateZ: '45deg' }],
193
197
  ...(() => {
@@ -204,11 +208,11 @@ export default (props: MenuProps) => {
204
208
  }} />
205
209
 
206
210
  <ScrollView onLayout={e => {
207
- // console.log('onLayout', e.nativeEvent.layout)
208
- let target: LayoutRectangle = e.nativeEvent.layout
209
- dispatch({ target })
211
+ // console.log('target onLayout', e.nativeEvent.layout)
212
+ let _sc: LayoutRectangle = e.nativeEvent.layout
213
+ sc.current = _sc
210
214
  }}
211
- style={{}}
215
+ // style={{ backgroundColor: "red" }}
212
216
  >
213
217
  {props.data?.map((i, idx) => {
214
218
  return (
@@ -216,7 +220,7 @@ export default (props: MenuProps) => {
216
220
  activeOpacity={.7}
217
221
  key={`sg-memnu-${idx}`}
218
222
  style={{
219
- height: 36, display: 'flex', flexDirection: 'row', alignItems: 'center'
223
+ height: CELL_HEIGHT, display: 'flex', flexDirection: 'row', alignItems: 'center'
220
224
  // ,backgroundColor:utils.randomcolor()
221
225
  }}
222
226
  onPress={e => {
@@ -2,12 +2,12 @@
2
2
  * @Author: shiguo
3
3
  * @Date: 2022-07-14 18:09:02
4
4
  * @LastEditors: shiguo
5
- * @LastEditTime: 2022-12-22 22:38:52
5
+ * @LastEditTime: 2022-12-23 12:24:54
6
6
  * @FilePath: /@aks-dev/easyui/lib/MenuView/index.ts
7
7
  */
8
8
 
9
9
  import React from "react";
10
- import { ImageSourcePropType, StyleProp, ViewStyle } from 'react-native';
10
+ import { ImageSourcePropType, StyleProp, ViewStyle, TouchableOpacityProps } from 'react-native';
11
11
 
12
12
 
13
13
 
@@ -18,11 +18,12 @@ export type MenuItem = {
18
18
  }
19
19
 
20
20
  export type MenuProps = {
21
- activeOpacity?: number | undefined;
21
+ defaultAlignVertical?: 'bottom' | 'top';
22
+ defaultAlignHorizontal?: 'left' | 'right';
22
23
  style?: StyleProp<ViewStyle> | undefined;
23
24
  data?: MenuItem[];
24
25
  onItemClick?: (index: number, extra?: any) => void;
25
- } & Readonly<{ children?: React.ReactNode | undefined }>
26
+ } & Readonly<{ children?: React.ReactNode | undefined }> & TouchableOpacityProps
26
27
 
27
28
 
28
29
  export declare const MenuView: React.FC<MenuProps>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aks-dev/easyui",
3
- "version": "1.0.135",
3
+ "version": "1.0.137",
4
4
  "description": "工具箱",
5
5
  "main": "./src/index.ts",
6
6
  "typings": "./src/index.d.ts",