22 lines
645 B
TypeScript
22 lines
645 B
TypeScript
import { AbstractService, InternalEventBus, ReactNativeToWebEvent } from '@standardnotes/snjs'
|
|
import { BackHandler, NativeEventSubscription } from 'react-native'
|
|
|
|
export class AndroidBackHandlerService extends AbstractService<ReactNativeToWebEvent> {
|
|
private removeListener: NativeEventSubscription
|
|
|
|
constructor() {
|
|
const internalEventBus = new InternalEventBus()
|
|
super(internalEventBus)
|
|
|
|
this.removeListener = BackHandler.addEventListener('hardwareBackPress', () => {
|
|
void this.notifyEvent(ReactNativeToWebEvent.AndroidBackButtonPressed)
|
|
|
|
return true
|
|
})
|
|
}
|
|
|
|
deinit() {
|
|
this.removeListener.remove()
|
|
}
|
|
}
|