esoftplay 0.0.126-e → 0.0.126-f
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/modules/lib/collaps.tsx +38 -29
- package/package.json +1 -1
package/modules/lib/collaps.tsx
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
import { useSafeState } from 'esoftplay';
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import React, {
|
|
6
|
+
import React, { useEffect } from 'react';
|
|
7
7
|
import { Pressable } from 'react-native';
|
|
8
|
-
import Animated, {
|
|
8
|
+
import Animated, { runOnJS, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
export interface LibCollapsArgs {
|
|
@@ -17,42 +17,51 @@ export interface LibCollapsProps {
|
|
|
17
17
|
style?: any
|
|
18
18
|
}
|
|
19
19
|
export default function m(props: LibCollapsProps): any {
|
|
20
|
-
const animHeight = useSharedValue(-1)
|
|
21
|
-
const bodyHeight = useSharedValue(1)
|
|
22
20
|
const [expand, setExpand] = useSafeState(props.show)
|
|
21
|
+
const opacity = useSharedValue(0);
|
|
22
|
+
const translateY = useSharedValue(-10);
|
|
23
23
|
|
|
24
|
-
const
|
|
24
|
+
const animatedStyle = useAnimatedStyle(() => {
|
|
25
25
|
return {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
opacity: opacity.value,
|
|
27
|
+
transform: [{ translateY: translateY.value }],
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (expand) {
|
|
33
|
+
toggleAnimation()
|
|
33
34
|
}
|
|
34
|
-
})
|
|
35
|
+
}, [expand])
|
|
36
|
+
|
|
37
|
+
const toggleAnimation = () => {
|
|
38
|
+
opacity.value = withTiming(opacity.value === 0 ? 1 : 0, { duration: 300 }, (status) => {
|
|
39
|
+
if (opacity.value == 0 && status) {
|
|
40
|
+
runOnJS(setExpand)(false)
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
translateY.value = withTiming(opacity.value !== 0 ? -10 : 0, { duration: 300})
|
|
44
|
+
};
|
|
35
45
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
function toggle() {
|
|
47
|
+
if (!expand) {
|
|
48
|
+
setExpand(true)
|
|
49
|
+
} else {
|
|
50
|
+
toggleAnimation()
|
|
51
|
+
}
|
|
52
|
+
}
|
|
40
53
|
|
|
41
54
|
return (
|
|
42
|
-
<Animated.View
|
|
43
|
-
|
|
55
|
+
<Animated.View>
|
|
56
|
+
<Pressable onPress={toggle} style={{zIndex:11}} >
|
|
44
57
|
{props.header(expand)}
|
|
45
58
|
</Pressable>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}}
|
|
53
|
-
style={[heightStyle]}>
|
|
54
|
-
{props.children}
|
|
55
|
-
</Animated.View>
|
|
59
|
+
{expand &&
|
|
60
|
+
<Animated.View
|
|
61
|
+
style={[{ paddingBottom: expand ? 10 : 0, zIndex:10 }, animatedStyle]}>
|
|
62
|
+
{props.children}
|
|
63
|
+
</Animated.View>
|
|
64
|
+
}
|
|
56
65
|
</Animated.View>
|
|
57
66
|
)
|
|
58
67
|
}
|