@aks-dev/easyui 1.0.136 → 1.0.138

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.
@@ -2,7 +2,7 @@
2
2
  * @Author: shiguo
3
3
  * @Date: 2022-05-17 15:22:06
4
4
  * @LastEditors: shiguo
5
- * @LastEditTime: 2022-12-22 11:57:30
5
+ * @LastEditTime: 2022-12-26 17:26:14
6
6
  * @FilePath: /@aks-dev/easyui/lib/AnimationModal/AnimationModal.tsx
7
7
  */
8
8
 
@@ -10,10 +10,11 @@ import * as React from "react";
10
10
  import { View, Animated, Easing, LayoutRectangle, PanResponder, StyleSheet, useWindowDimensions, BackHandler } from 'react-native';
11
11
  import type { AnimationModalProps } from '.';
12
12
  import * as utils from '../../utils/lazy';
13
- type State = {
14
- display: 'flex' | 'none';
15
- }
16
- type StateReducerProps = (state: State, action: Partial<State>) => State
13
+ // type State = {
14
+ // display: 'flex' | 'none';
15
+ // }
16
+ // type StateReducerProps = (state: State, action: Partial<State>) => State
17
+
17
18
 
18
19
 
19
20
  export const AnimationModal: React.ForwardRefExoticComponent<
@@ -28,11 +29,13 @@ export const AnimationModal: React.ForwardRefExoticComponent<
28
29
 
29
30
  const { height } = useWindowDimensions()
30
31
 
31
- const [state, dispatch] = React.useReducer<StateReducerProps>(
32
- (state, action) => ({ ...state, ...action }),
33
- {
34
- display: 'none'
35
- })
32
+ // const [state, dispatch] = React.useReducer<StateReducerProps>(
33
+ // (state, action) => ({ ...state, ...action }),
34
+ // {
35
+ // display: 'none'
36
+ // })
37
+
38
+ const [display, setDisplay] = useCallbackState<'flex' | 'none'>('none')
36
39
 
37
40
  const animatedValue = React.useRef(new Animated.Value(0)).current;
38
41
  const timing = (value: number) => {
@@ -60,31 +63,36 @@ export const AnimationModal: React.ForwardRefExoticComponent<
60
63
  }), [])
61
64
  const targetRef = React.useRef<any>()
62
65
 
66
+
63
67
  const show = async () => {
64
- dispatch({ display: 'flex' })
65
- await utils.sleep(50)
66
- timing(-layoutRef.current?.h1)
68
+ setDisplay('flex', async () => {
69
+ await utils.sleep(50)
70
+ timing(-layoutRef.current?.h1)
71
+ })
67
72
  }
68
73
  const hide = async () => {
69
74
  timing(0)
70
75
  await utils.sleep(300)
71
- dispatch({ display: 'none' })
76
+ setDisplay('none')
72
77
  }
73
78
 
74
79
 
75
80
  React.useEffect(() => {
76
- let addEventListener = BackHandler.addEventListener("hardwareBackPress", ()=>{
77
- return state.display == 'flex'
81
+ let addEventListener = BackHandler.addEventListener("hardwareBackPress", () => {
82
+ return display == 'flex'
78
83
  })
79
84
  return () => {
80
85
  addEventListener.remove()
81
86
  }
82
- }, [state.display])
87
+ }, [display])
88
+
83
89
 
84
90
 
85
91
  return (
86
92
  <View
87
- style={Object.assign({ display: state.display }, styles.container, props.style)}
93
+ style={Object.assign({
94
+ display: display
95
+ }, styles.container, props.style)}
88
96
  {...PanResponder.create({
89
97
  onStartShouldSetPanResponder: (e, gestureState) => {
90
98
  let pageY = e.nativeEvent.pageY
@@ -146,3 +154,22 @@ const styles = StyleSheet.create({
146
154
  // backgroundColor: 'cyan'
147
155
  }
148
156
  })
157
+
158
+
159
+
160
+
161
+ const useCallbackState = <T,>(od: T): [T, (d: T, callback?: Function) => void] => {
162
+ const cbRef = React.useRef<Function>()
163
+ const [data, setData] = React.useState<T>(od)
164
+ React.useEffect(() => {
165
+ cbRef.current && cbRef.current(data)
166
+ }, [data])
167
+
168
+ return [
169
+ data,
170
+ (d: T, callback?: Function) => {
171
+ cbRef.current = callback;
172
+ setData(d)
173
+ }
174
+ ]
175
+ }
@@ -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
 
@@ -31,13 +24,13 @@ export default (props: MenuProps) => {
31
24
 
32
25
  // const containerRef = React.useRef<{ measureInWindow: (callback: MeasureInWindowOnSuccessCallback) => void }>()
33
26
  const containerRef = React.useRef<{ measure: (callback: MeasureOnSuccessCallback) => void }>()
34
- const _container = React.useRef<{
35
- x: number;
36
- y: number;
27
+ const rootView = React.useRef<{
28
+ pageX: number;
29
+ pageY: number;
37
30
  height: number;
38
31
  width: number;
39
- }>({ x: 0, y: 0, width: 0, height: 0 })
40
-
32
+ }>({ pageX: 0, pageY: 0, width: 0, height: 0 })
33
+ const sc = React.useRef<LayoutRectangle>({ x: 0, y: 0, width: 0, height: 0 })
41
34
 
42
35
  // React.useEffect(() => {
43
36
  // ; (async () => {
@@ -60,15 +53,15 @@ export default (props: MenuProps) => {
60
53
  const getRootViewlayoutPromise = () => {
61
54
  return new Promise((resovle, reject) => {
62
55
  containerRef.current?.measure((...args) => {
63
- // console.log('containerRef', args)
64
56
  if (args.length == 6) {
65
- _container.current = {
66
- x: args[4],
67
- y: args[5],
57
+ rootView.current = {
68
58
  width: args[2],
69
59
  height: args[3],
60
+ pageX: args[4],
61
+ pageY: args[5],
70
62
  }
71
63
  }
64
+ // console.log('RootView', rootView.current)
72
65
  resovle(args)
73
66
  })
74
67
  })
@@ -88,19 +81,20 @@ export default (props: MenuProps) => {
88
81
  = () => {
89
82
  let alignVertical: 'bottom' | 'top' = defaultAlignVertical
90
83
  let alignHorizontal: 'left' | 'right' = defaultAlignHorizontal
91
- let width = _container.current.width
92
- let height = _container.current.height
93
- let x = _container.current.x
84
+ let width = rootView.current.width
85
+ let height = rootView.current.height
86
+ let x = rootView.current.pageX
94
87
  // let y = (StatusBar.currentHeight || 0) + _container.current.y + height
95
- let y = _container.current.y + height
88
+ let y = rootView.current.pageY + height
96
89
  if (x > Math.abs(deviceWidth - width - x)) {
97
90
  alignHorizontal = 'right'
98
91
  }
99
92
  if (y > deviceHeight * .5) {
100
93
  alignVertical = 'top'
101
94
  }
102
- const target_width = state.target?.width || 0
103
- 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)
104
98
  return {
105
99
  alignVertical,
106
100
  alignHorizontal,
@@ -131,6 +125,7 @@ export default (props: MenuProps) => {
131
125
  target_height,
132
126
  } = getLayoutInfos()
133
127
 
128
+ // console.log({ getLayoutInfos: getLayoutInfos() })
134
129
  const layout = () => {
135
130
  if (alignHorizontal == 'left') {
136
131
  if (target_width + x > deviceWidth) {
@@ -158,16 +153,20 @@ export default (props: MenuProps) => {
158
153
  }
159
154
  }
160
155
  if (alignVertical == 'bottom') {
161
- y = y + 10
156
+ y = y + PADDING
162
157
  return layout()
163
158
  } else {
164
- // y = (StatusBar.currentHeight || 0) + _container.current.y - target_height - 10
165
- y = _container.current.y - target_height - 10
159
+ y = rootView.current.pageY - target_height - PADDING * 2 - ARROW_HEIGHT
166
160
  return layout()
167
161
  }
168
162
  }
169
163
 
170
164
 
165
+ const PADDING = 10
166
+ const ARROW_HEIGHT = 12
167
+ const CELL_HEIGHT = 36
168
+
169
+
171
170
  const show = async () => {
172
171
  if (props.data == undefined || props.data?.length == 0) return
173
172
  /**重新获取rootview的定位 */
@@ -178,23 +177,21 @@ export default (props: MenuProps) => {
178
177
  <TouchableOpacity
179
178
  activeOpacity={1}
180
179
  style={{
180
+
181
181
  position: 'absolute',
182
182
  minWidth: deviceWidth * 0.36,
183
183
  maxWidth: deviceWidth * 0.8,
184
- minHeight: 36 + 20,
185
- maxHeight: 36 * 5 + 20,
184
+ minHeight: CELL_HEIGHT + PADDING * 2,
185
+ maxHeight: CELL_HEIGHT * 5 + PADDING * 2,
186
186
  borderRadius: 6, backgroundColor: '#000000ee',
187
187
  // overflow: 'hidden' ,
188
- padding: 10,
188
+ padding: PADDING,
189
189
  ...reLayout()
190
190
  }}
191
- // onLayout={e=>{
192
- // console.log('onLayout TouchableOpacity', e.nativeEvent.layout)
193
- // }}
194
191
  >
195
192
 
196
193
  <View style={{
197
- width: 12, height: 12,
194
+ width: ARROW_HEIGHT, height: ARROW_HEIGHT,
198
195
  backgroundColor: '#000000ee', position: 'absolute', zIndex: 1,
199
196
  transform: [{ rotateZ: '45deg' }],
200
197
  ...(() => {
@@ -211,11 +208,11 @@ export default (props: MenuProps) => {
211
208
  }} />
212
209
 
213
210
  <ScrollView onLayout={e => {
214
- // console.log('onLayout', e.nativeEvent.layout)
215
- let target: LayoutRectangle = e.nativeEvent.layout
216
- dispatch({ target })
211
+ // console.log('target onLayout', e.nativeEvent.layout)
212
+ let _sc: LayoutRectangle = e.nativeEvent.layout
213
+ sc.current = _sc
217
214
  }}
218
- style={{}}
215
+ // style={{ backgroundColor: "red" }}
219
216
  >
220
217
  {props.data?.map((i, idx) => {
221
218
  return (
@@ -223,7 +220,7 @@ export default (props: MenuProps) => {
223
220
  activeOpacity={.7}
224
221
  key={`sg-memnu-${idx}`}
225
222
  style={{
226
- height: 36, display: 'flex', flexDirection: 'row', alignItems: 'center'
223
+ height: CELL_HEIGHT, display: 'flex', flexDirection: 'row', alignItems: 'center'
227
224
  // ,backgroundColor:utils.randomcolor()
228
225
  }}
229
226
  onPress={e => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aks-dev/easyui",
3
- "version": "1.0.136",
3
+ "version": "1.0.138",
4
4
  "description": "工具箱",
5
5
  "main": "./src/index.ts",
6
6
  "typings": "./src/index.d.ts",