about summary refs log tree commit diff
path: root/src/lib/routes
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/routes')
-rw-r--r--src/lib/routes/back-handler.ts17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/lib/routes/back-handler.ts b/src/lib/routes/back-handler.ts
index c4067c53e..aae2f2c24 100644
--- a/src/lib/routes/back-handler.ts
+++ b/src/lib/routes/back-handler.ts
@@ -1,8 +1,19 @@
+import {isAndroid} from 'platform/detection'
 import {BackHandler} from 'react-native'
 import {RootStoreModel} from 'state/index'
 
 export function init(store: RootStoreModel) {
-  BackHandler.addEventListener('hardwareBackPress', () => {
-    return store.shell.closeAnyActiveElement()
-  })
+  // only register back handler on android, otherwise it throws an error
+  if (isAndroid) {
+    const backHandler = BackHandler.addEventListener(
+      'hardwareBackPress',
+      () => {
+        return store.shell.closeAnyActiveElement()
+      },
+    )
+    return () => {
+      backHandler.remove()
+    }
+  }
+  return () => {}
 }