Fork me on GitHub
#cljsrn
<
2018-10-03
>
xfyre17:10:55

I have a question related to ReactNavigation. I want to be able to reference the root navigator globally. In a regular React I can obtain the reference while rendering a component. How to do the same in CLJS/Reagent?

Oliver George21:10:17

These are some notes we made while working through how to bolt react navigation together. https://confluence.condense.com.au/display/IZ/Navigating+between+screens - the relevant bit is the RootStack :ref but perhaps the context is interesting.

Oliver George21:10:59

I do see value in https://github.com/seantempesta/cljs-react-navigation having tried without a wrapper.

Oliver George21:10:03

Or did I read that right. The screen containers get the navigator as a prop. That might be what you are asking.

xfyre14:10:58

I actually figured that out in a different (and more re-frame-ish) way just now

xfyre14:10:24

(defn app-root []
  [:> appnav/central-app-switch {:ref (fn [this] (dispatch [:set-root-navigator this]))}])

xfyre14:10:11

this basically does it - root navigator becomes a part of app-db and then you can reference it in effectful handlers

xfyre14:10:09

(reg-fx
  :navigate
  (fn [[root-navigator route params]]
    (.dispatch root-navigator (navactions/navigate-to route params))))

xfyre14:10:25

(reg-event-fx
  :handle-login-success
  validate-spec
  (fn [{:keys [db]} [_ session-info]]
    (println db)
    {:db (-> db
         (assoc-in [:dcn-session] (-> session-info
                                      (update-in [:userInfo :gender] keyword)
                                      (update-in [:userInfo :siteRoles] (fn [v] (map #(keyword %) v))))))
     :navigate [(:root-navigator db) :Main]}
    ))

xfyre14:10:00

it is embarrassingly simple

xfyre14:10:34

thanks for the link though, it’s very helpful, too!

🙂 4
xfyre17:10:38

Via :component-did-mount?