about summary refs log tree commit diff
path: root/src/view/lib/useOnMainScroll.ts
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2022-12-12 16:04:14 -0600
committerPaul Frazee <pfrazee@gmail.com>2022-12-12 16:04:14 -0600
commit1aec0ee156daa5a1d3e4ead70caf667edb75eebb (patch)
treee4931885b9dfea5996cad11e47e59f64109d4761 /src/view/lib/useOnMainScroll.ts
parent470f444eed0d9643612bbdb9533cd64614834c69 (diff)
downloadvoidsky-1aec0ee156daa5a1d3e4ead70caf667edb75eebb.tar.zst
Hide footer on scroll down (minimal shell mode)
Diffstat (limited to 'src/view/lib/useOnMainScroll.ts')
-rw-r--r--src/view/lib/useOnMainScroll.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/view/lib/useOnMainScroll.ts b/src/view/lib/useOnMainScroll.ts
new file mode 100644
index 000000000..ee0081226
--- /dev/null
+++ b/src/view/lib/useOnMainScroll.ts
@@ -0,0 +1,25 @@
+import {useState} from 'react'
+import {NativeSyntheticEvent, NativeScrollEvent} from 'react-native'
+import {RootStoreModel} from '../../state'
+
+export type OnScrollCb = (
+  event: NativeSyntheticEvent<NativeScrollEvent>,
+) => void
+
+export function useOnMainScroll(store: RootStoreModel) {
+  let [lastY, setLastY] = useState(0)
+  let isMinimal = store.shell.minimalShellMode
+  return function onMainScroll(event: NativeSyntheticEvent<NativeScrollEvent>) {
+    const y = event.nativeEvent.contentOffset.y
+    const dy = y - (lastY || 0)
+    setLastY(y)
+
+    if (!isMinimal && y > 10 && dy > 10) {
+      store.shell.setMinimalShellMode(true)
+      isMinimal = true
+    } else if (isMinimal && (y <= 10 || dy < -10)) {
+      store.shell.setMinimalShellMode(false)
+      isMinimal = false
+    }
+  }
+}