···1313import {Shell} from './view/shell'
1414import * as notifee from 'lib/notifee'
1515import * as analytics from 'lib/analytics'
1616+import * as backHandler from 'lib/routes/back-handler'
1617import * as Toast from './view/com/util/Toast'
1718import {handleLink} from './Navigation'
1819···2829 setRootStore(store)
2930 analytics.init(store)
3031 notifee.init(store)
3232+ backHandler.init(store)
3133 SplashScreen.hideAsync()
3234 Linking.getInitialURL().then((url: string | null) => {
3335 if (url) {
+11
src/lib/routes/back-handler.ts
···11+import {BackHandler} from 'react-native'
22+import {RootStoreModel} from 'state/index'
33+44+export function onBack(cb: () => boolean): () => void {
55+ const subscription = BackHandler.addEventListener('hardwareBackPress', cb)
66+ return () => subscription.remove()
77+}
88+99+export function init(store: RootStoreModel) {
1010+ onBack(() => store.shell.closeAnyActiveElement())
1111+}
+24
src/state/models/ui/shell.ts
···194194 this.minimalShellMode = v
195195 }
196196197197+ /**
198198+ * returns true if something was closed
199199+ * (used by the android hardware back btn)
200200+ */
201201+ closeAnyActiveElement(): boolean {
202202+ if (this.isLightboxActive) {
203203+ this.closeLightbox()
204204+ return true
205205+ }
206206+ if (this.isModalActive) {
207207+ this.closeModal()
208208+ return true
209209+ }
210210+ if (this.isComposerActive) {
211211+ this.closeComposer()
212212+ return true
213213+ }
214214+ if (this.isDrawerOpen) {
215215+ this.closeDrawer()
216216+ return true
217217+ }
218218+ return false
219219+ }
220220+197221 openDrawer() {
198222 this.isDrawerOpen = true
199223 }
+1-2
src/view/com/lightbox/Lightbox.tsx
···11import React from 'react'
22-import {View} from 'react-native'
32import {observer} from 'mobx-react-lite'
43import ImageView from './ImageViewing'
54import {useStores} from 'state/index'
···4847 />
4948 )
5049 } else {
5151- return <View />
5050+ return null
5251 }
5352})