@aks-dev/easyui 1.0.134 → 1.0.136
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.
- package/lib/MenuView/MenuView.tsx +38 -12
- package/lib/MenuView/index.ts +5 -4
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import React from "react";
|
|
|
2
2
|
import { Image, LayoutRectangle, MeasureOnSuccessCallback, ScrollView, StatusBar, Text, TouchableOpacity, View } from 'react-native';
|
|
3
3
|
import type { MenuProps } from '.';
|
|
4
4
|
import { deviceHeight, deviceWidth } from '../../screen/px2dp';
|
|
5
|
-
import * as utils from '../../utils/lazy';
|
|
5
|
+
// import * as utils from '../../utils/lazy';
|
|
6
6
|
import { hidePopoverView, showPopoverView } from '../Hud/Hud';
|
|
7
7
|
|
|
8
8
|
type State = {
|
|
@@ -22,6 +22,11 @@ type Reducer = (prevState: State, action: Partial<State>) => State
|
|
|
22
22
|
|
|
23
23
|
export default (props: MenuProps) => {
|
|
24
24
|
|
|
25
|
+
const {
|
|
26
|
+
defaultAlignHorizontal = 'left',
|
|
27
|
+
defaultAlignVertical = 'bottom'
|
|
28
|
+
} = props
|
|
29
|
+
|
|
25
30
|
const [state, dispatch] = React.useReducer<Reducer>((prevState, action) => Object.assign({}, prevState, action), {})
|
|
26
31
|
|
|
27
32
|
// const containerRef = React.useRef<{ measureInWindow: (callback: MeasureInWindowOnSuccessCallback) => void }>()
|
|
@@ -34,9 +39,26 @@ export default (props: MenuProps) => {
|
|
|
34
39
|
}>({ x: 0, y: 0, width: 0, height: 0 })
|
|
35
40
|
|
|
36
41
|
|
|
37
|
-
React.useEffect(() => {
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
// React.useEffect(() => {
|
|
43
|
+
// ; (async () => {
|
|
44
|
+
// await utils.sleep()
|
|
45
|
+
// containerRef.current?.measure((...args) => {
|
|
46
|
+
// console.log('containerRef', args)
|
|
47
|
+
// if (args.length == 6) {
|
|
48
|
+
// _container.current = {
|
|
49
|
+
// x: args[4],
|
|
50
|
+
// y: args[5],
|
|
51
|
+
// width: args[2],
|
|
52
|
+
// height: args[3],
|
|
53
|
+
// }
|
|
54
|
+
// }
|
|
55
|
+
// })
|
|
56
|
+
// })()
|
|
57
|
+
// })
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
const getRootViewlayoutPromise = () => {
|
|
61
|
+
return new Promise((resovle, reject) => {
|
|
40
62
|
containerRef.current?.measure((...args) => {
|
|
41
63
|
// console.log('containerRef', args)
|
|
42
64
|
if (args.length == 6) {
|
|
@@ -47,9 +69,10 @@ export default (props: MenuProps) => {
|
|
|
47
69
|
height: args[3],
|
|
48
70
|
}
|
|
49
71
|
}
|
|
72
|
+
resovle(args)
|
|
50
73
|
})
|
|
51
|
-
})
|
|
52
|
-
}
|
|
74
|
+
})
|
|
75
|
+
}
|
|
53
76
|
|
|
54
77
|
|
|
55
78
|
const getLayoutInfos: () => {
|
|
@@ -63,13 +86,13 @@ export default (props: MenuProps) => {
|
|
|
63
86
|
target_height: number;
|
|
64
87
|
}
|
|
65
88
|
= () => {
|
|
66
|
-
let alignVertical: 'bottom' | 'top' =
|
|
67
|
-
let alignHorizontal: 'left' | 'right' =
|
|
89
|
+
let alignVertical: 'bottom' | 'top' = defaultAlignVertical
|
|
90
|
+
let alignHorizontal: 'left' | 'right' = defaultAlignHorizontal
|
|
68
91
|
let width = _container.current.width
|
|
69
92
|
let height = _container.current.height
|
|
70
93
|
let x = _container.current.x
|
|
71
94
|
// let y = (StatusBar.currentHeight || 0) + _container.current.y + height
|
|
72
|
-
let y =
|
|
95
|
+
let y = _container.current.y + height
|
|
73
96
|
if (x > Math.abs(deviceWidth - width - x)) {
|
|
74
97
|
alignHorizontal = 'right'
|
|
75
98
|
}
|
|
@@ -138,15 +161,18 @@ export default (props: MenuProps) => {
|
|
|
138
161
|
y = y + 10
|
|
139
162
|
return layout()
|
|
140
163
|
} else {
|
|
141
|
-
y = (StatusBar.currentHeight || 0) + _container.current.y - target_height - 10
|
|
164
|
+
// y = (StatusBar.currentHeight || 0) + _container.current.y - target_height - 10
|
|
165
|
+
y = _container.current.y - target_height - 10
|
|
142
166
|
return layout()
|
|
143
167
|
}
|
|
144
168
|
}
|
|
145
169
|
|
|
146
170
|
|
|
147
|
-
const show = () => {
|
|
148
|
-
// console.log('_container', _container.current, StatusBar.currentHeight)
|
|
171
|
+
const show = async () => {
|
|
149
172
|
if (props.data == undefined || props.data?.length == 0) return
|
|
173
|
+
/**重新获取rootview的定位 */
|
|
174
|
+
await getRootViewlayoutPromise()
|
|
175
|
+
/**重新获取rootview的定位 */
|
|
150
176
|
showPopoverView({
|
|
151
177
|
content: (
|
|
152
178
|
<TouchableOpacity
|
package/lib/MenuView/index.ts
CHANGED
|
@@ -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-
|
|
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
|
-
|
|
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>;
|