diff options
author | Ansh <anshnanda10@gmail.com> | 2023-09-29 10:49:59 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-29 07:49:59 +0400 |
commit | 04fda0f1429d26586d308a619f91d4504bdd3521 (patch) | |
tree | ee215dddc5bfd6385605383a48ca60e3e6f9631f /src/lib/routes | |
parent | 1f60e1a7486013ad84dcc386d226f4225b67c1d3 (diff) | |
download | voidsky-04fda0f1429d26586d308a619f91d4504bdd3521.tar.zst |
Fix 1405 handle android back button in composer (#1446)
* handle android back button in composer * improve backHandler error handling * simplify composer onClose functionality
Diffstat (limited to 'src/lib/routes')
-rw-r--r-- | src/lib/routes/back-handler.ts | 17 |
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 () => {} } |