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.
@@ -3,9 +3,9 @@
3
3
  import { useSafeState } from 'esoftplay';
4
4
 
5
5
 
6
- import React, { useCallback } from 'react';
6
+ import React, { useEffect } from 'react';
7
7
  import { Pressable } from 'react-native';
8
- import Animated, { interpolate, useAnimatedStyle, useSharedValue, withSpring, withTiming } from 'react-native-reanimated';
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 heightStyle = useAnimatedStyle(() => {
24
+ const animatedStyle = useAnimatedStyle(() => {
25
25
  return {
26
- overflow: 'hidden',
27
- height: interpolate(animHeight.value,
28
- [0, 1, 2],
29
- [0, bodyHeight.value, bodyHeight.value * 2]),
30
- opacity: interpolate(animHeight.value,
31
- [-1, 0],
32
- [0, 1])
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
- const toggle = useCallback(() => {
37
- animHeight.value = animHeight.value == 0 ? withSpring(1) : withTiming(0)
38
- setExpand(animHeight.value != 1)
39
- }, [])
46
+ function toggle() {
47
+ if (!expand) {
48
+ setExpand(true)
49
+ } else {
50
+ toggleAnimation()
51
+ }
52
+ }
40
53
 
41
54
  return (
42
- <Animated.View style={{ overflow: 'hidden' }} >
43
- <Pressable onPress={toggle} >
55
+ <Animated.View>
56
+ <Pressable onPress={toggle} style={{zIndex:11}} >
44
57
  {props.header(expand)}
45
58
  </Pressable>
46
- <Animated.View
47
- onLayout={({ nativeEvent: { layout: { height } } }) => {
48
- if (height && animHeight.value == -1) {
49
- bodyHeight.value = height + 5
50
- animHeight.value = props.show ? 1 : 0
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esoftplay",
3
- "version": "0.0.126-e",
3
+ "version": "0.0.126-f",
4
4
  "description": "embedding data from esoftplay framework (web based) into mobile app",
5
5
  "main": "cache/index.js",
6
6
  "types": "../../index.d.ts",