esoftplay 0.0.141-t → 0.0.141-u

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.
@@ -1,7 +1,7 @@
1
1
  // withHooks
2
2
  // noPage
3
3
  import useSafeState from 'esoftplay/state';
4
- import React, { useEffect } from 'react';
4
+ import React, { useEffect, useLayoutEffect } from 'react';
5
5
  import { Pressable, ViewStyle } from 'react-native';
6
6
  import Animated, { runOnJS, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
7
7
 
@@ -17,16 +17,22 @@ export interface LibCollapsProps {
17
17
  }
18
18
  export default function m(props: LibCollapsProps): any {
19
19
  const [expand, setExpand] = useSafeState(props.show)
20
- const opacity = useSharedValue(0);
21
20
  const translateY = useSharedValue(-10);
21
+ const isAnimationOff = useSharedValue(0)
22
22
 
23
23
  const animatedStyle = useAnimatedStyle(() => {
24
24
  return {
25
- opacity: opacity.value,
25
+ opacity: 1,
26
26
  transform: [{ translateY: translateY.value }],
27
27
  };
28
28
  });
29
29
 
30
+ useLayoutEffect(() => {
31
+ checkIfAnimationsAreDisabled().then((isDisabled) => {
32
+ isAnimationOff.value = isDisabled ? 1 : 0
33
+ });
34
+ }, [])
35
+
30
36
  useEffect(() => {
31
37
  if (expand) {
32
38
  toggleAnimation()
@@ -34,12 +40,15 @@ export default function m(props: LibCollapsProps): any {
34
40
  }, [expand])
35
41
 
36
42
  const toggleAnimation = () => {
37
- opacity.value = withTiming(opacity.value === 0 ? 1 : 0, { duration: 300 }, (status) => {
38
- if (opacity.value == 0 && status) {
39
- runOnJS(setExpand)(false)
40
- }
41
- });
42
- translateY.value = withTiming(opacity.value !== 0 ? -10 : 0, { duration: 300 })
43
+ if (isAnimationOff.value) {
44
+ translateY.value = translateY.value !== -10 ? -10 : 0
45
+ } else {
46
+ translateY.value = withTiming(translateY.value !== -10 ? -10 : 0, { duration: 300 }, (status) => {
47
+ if (translateY.value == -10 && status) {
48
+ runOnJS(setExpand)(false)
49
+ }
50
+ })
51
+ }
43
52
  };
44
53
 
45
54
  function toggle() {
@@ -66,4 +75,22 @@ export default function m(props: LibCollapsProps): any {
66
75
  }
67
76
  </Animated.View>
68
77
  )
69
- }
78
+ }
79
+
80
+ const checkIfAnimationsAreDisabled = async () => {
81
+ const value = useSharedValue(0);
82
+
83
+ const startTime = Date.now();
84
+
85
+ // Animate the shared value with a short duration
86
+ await new Promise((resolve) => {
87
+ value.value = withTiming(1, { duration: 50 }, () => {
88
+ resolve();
89
+ });
90
+ });
91
+
92
+ const elapsedTime = Date.now() - startTime;
93
+
94
+ // If animations are disabled, the elapsed time will be very short (e.g., < 10ms)
95
+ return elapsedTime < 10;
96
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esoftplay",
3
- "version": "0.0.141-t",
3
+ "version": "0.0.141-u",
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",