about summary refs log tree commit diff
path: root/src/lib/routes/back-handler.ts
blob: aae2f2c24e7391983dbde0cc0e2f2831d2e3ac07 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import {isAndroid} from 'platform/detection'
import {BackHandler} from 'react-native'
import {RootStoreModel} from 'state/index'

export function init(store: RootStoreModel) {
  // 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 () => {}
}