Fix back button navigation
This commit is contained in:
parent
7c9e8f6105
commit
f32547aaf8
|
@ -1,9 +1,9 @@
|
||||||
(ns messenger.android.core
|
(ns messenger.android.core
|
||||||
(:require-macros
|
(:require-macros
|
||||||
[natal-shell.components :refer [navigator view text image touchable-highlight list-view
|
[natal-shell.components :refer [navigator view text image touchable-highlight
|
||||||
toolbar-android]]
|
list-view toolbar-android]]
|
||||||
[natal-shell.data-source :refer [data-source clone-with-rows]]
|
[natal-shell.data-source :refer [data-source clone-with-rows]]
|
||||||
[natal-shell.back-android :refer [add-event-listener]]
|
[natal-shell.back-android :refer [add-event-listener remove-event-listener]]
|
||||||
[natal-shell.core :refer [with-error-view]]
|
[natal-shell.core :refer [with-error-view]]
|
||||||
[natal-shell.alert :refer [alert]])
|
[natal-shell.alert :refer [alert]])
|
||||||
(:require [om.next :as om :refer-macros [defui]]
|
(:require [om.next :as om :refer-macros [defui]]
|
||||||
|
@ -21,19 +21,21 @@
|
||||||
|
|
||||||
(def app-registry (.-AppRegistry js/React))
|
(def app-registry (.-AppRegistry js/React))
|
||||||
|
|
||||||
(def initialized-atom (atom false))
|
(def back-button-handler-atom (atom {:nav nil
|
||||||
|
:handler nil}))
|
||||||
|
|
||||||
(defn init-back-button-handler! [nav]
|
(defn init-back-button-handler! [nav]
|
||||||
(if (not @initialized-atom)
|
(let [back-button-handler @back-button-handler-atom]
|
||||||
(swap! initialized-atom
|
(when (not= (:nav back-button-handler) nav)
|
||||||
(fn [initialized]
|
(remove-event-listener "hardwareBackPress" (:handler back-button-handler))
|
||||||
(when (not initialized)
|
(let [new-listener (fn []
|
||||||
(add-event-listener "hardwareBackPress"
|
|
||||||
(fn []
|
|
||||||
(binding [state/*nav-render* false]
|
(binding [state/*nav-render* false]
|
||||||
(when (< 1 (.-length (.getCurrentRoutes nav)))
|
(when (< 1 (.-length (.getCurrentRoutes nav)))
|
||||||
(.pop nav)
|
(.pop nav)
|
||||||
true)))))
|
true)))]
|
||||||
true))))
|
(reset! back-button-handler-atom {:nav nav
|
||||||
|
:handler new-listener})
|
||||||
|
(add-event-listener "hardwareBackPress" new-listener)))))
|
||||||
|
|
||||||
(defui AppRoot
|
(defui AppRoot
|
||||||
static om/IQuery
|
static om/IQuery
|
||||||
|
|
Loading…
Reference in New Issue