about summary refs log tree commit diff
path: root/src/lib/hooks
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2023-10-13 15:24:28 +0100
committerGitHub <noreply@github.com>2023-10-13 15:24:28 +0100
commit2a1edab6d4a8e8b4197b10868153a525f918509c (patch)
treeb73ee178ec662b8209989400e9c9dfa2781fa864 /src/lib/hooks
parent4431cfe2d2971577e9c0a4fa4ed83f0c52fb7540 (diff)
downloadvoidsky-2a1edab6d4a8e8b4197b10868153a525f918509c.tar.zst
Don't re-render bars when showing/hiding them (#1691)
* Don't re-render bars when showing/hiding them

* Fix more cases

* Use autorun instead of reaction to fix first render
Diffstat (limited to 'src/lib/hooks')
-rw-r--r--src/lib/hooks/useMinimalShellMode.tsx35
1 files changed, 19 insertions, 16 deletions
diff --git a/src/lib/hooks/useMinimalShellMode.tsx b/src/lib/hooks/useMinimalShellMode.tsx
index 2a0a4e4d0..68f405dc4 100644
--- a/src/lib/hooks/useMinimalShellMode.tsx
+++ b/src/lib/hooks/useMinimalShellMode.tsx
@@ -1,4 +1,5 @@
 import React from 'react'
+import {autorun} from 'mobx'
 import {useStores} from 'state/index'
 import {Animated} from 'react-native'
 import {useAnimatedValue} from 'lib/hooks/useAnimatedValue'
@@ -12,22 +13,24 @@ export function useMinimalShellMode() {
   }
 
   React.useEffect(() => {
-    if (store.shell.minimalShellMode) {
-      Animated.timing(minimalShellInterp, {
-        toValue: 1,
-        duration: 150,
-        useNativeDriver: true,
-        isInteraction: false,
-      }).start()
-    } else {
-      Animated.timing(minimalShellInterp, {
-        toValue: 0,
-        duration: 150,
-        useNativeDriver: true,
-        isInteraction: false,
-      }).start()
-    }
-  }, [minimalShellInterp, store.shell.minimalShellMode])
+    return autorun(() => {
+      if (store.shell.minimalShellMode) {
+        Animated.timing(minimalShellInterp, {
+          toValue: 1,
+          duration: 150,
+          useNativeDriver: true,
+          isInteraction: false,
+        }).start()
+      } else {
+        Animated.timing(minimalShellInterp, {
+          toValue: 0,
+          duration: 150,
+          useNativeDriver: true,
+          isInteraction: false,
+        }).start()
+      }
+    })
+  }, [minimalShellInterp, store])
 
   return {footerMinimalShellTransform}
 }