forked from status-im/status-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnavigation.cljs
More file actions
54 lines (42 loc) · 1.45 KB
/
navigation.cljs
File metadata and controls
54 lines (42 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
(ns status-im.utils.navigation
(:require [status-im.react-native.js-dependencies :as js-dependencies]
[status-im.utils.platform :as platform]
[goog.object :as gobj]))
(def navigation-actions
(.-NavigationActions js-dependencies/react-navigation))
(def navigation-events
(.-NavigationEvents js-dependencies/react-navigation))
(def stack-actions
(.-StackActions js-dependencies/react-navigation))
(def navigator-ref (atom nil))
(defn set-navigator-ref [ref]
(reset! navigator-ref ref))
(defn can-be-called? []
@navigator-ref)
(defn navigate-to [route params]
(when (can-be-called?)
(.dispatch
@navigator-ref
(.navigate
navigation-actions
#js {:routeName (name route)
:params (clj->js params)}))))
(defn- navigate [params]
(when (can-be-called?)
(.navigate navigation-actions (clj->js params))))
(defn navigate-reset [state]
(when (can-be-called?)
(let [state' (update state :actions #(mapv navigate %))]
(.dispatch
@navigator-ref
(.reset
stack-actions
(clj->js state'))))))
(defn navigate-back []
(when (can-be-called?)
(.dispatch
@navigator-ref
(.back navigation-actions))))
(defonce TwoPaneNavigator (gobj/get js-dependencies/react-native-navigation-twopane #js ["createTwoPaneNavigator"]))
(defn twopane-navigator [routeConfigs stackNavigatorConfig]
(TwoPaneNavigator (clj->js routeConfigs) (clj->js stackNavigatorConfig)))