cljsrn

https://github.com/drapanjanas/re-natal | https://github.com/drapanjanas/re-natal/wiki/FAQ | https://github.com/condense/mercury-app/wiki | https://github.com/seantempesta/expo-cljs-template/ https://www.npmjs.com/package/create-expo-cljs-app
Oliver George 2020-08-05T01:40:12.105200Z

@benny I'm using react navigation 5. Here's my setup: https://gist.github.com/olivergeorge/981bc5135fa47253cba50fd125495d0b The interop.navigation/*navigator keeps the navigator ref which allows me to do navigation from re-frame fx (not relying on component props).

anson 2020-08-18T16:50:54.118900Z

I think this solution hits a snag when you have nested navigators, and you want the action to be dispatched against a child navigator - usually the parent of the screen where you're dispatching the event to effect the navigation. What I ended up doing recently was using the navigator ref as you're doing here to persist nav state for reloads, but wrapping the event dispatch function to add the navigation prop (from useNavigation) to the event as metadata. Then the effect handler uses that to dispatch the navigation action, rather than the root navigator in the ref.

anson 2020-08-18T16:51:51.119100Z

looks like some earlier messages in this thread were archived already, so apologies if my response is missing some important context 🙂

Oliver George 2020-08-18T23:30:28.119500Z

Hi Anson. I found nested navigators fiddly but doable.

; event handler
(rf/reg-event-fx :home-my-map-press
  []
  {:dispatch  [:setup-route :app.screens/my-map]
   :navigate2 ["TabStack" {:screen "MapStack"}]})

; fx
(rf/reg-fx :navigate2 (fn [[a b]] (navigation/navigate2 a b)))

; helper
(defn navigate2 [a b]  (.navigate @*navigator a (clj->js b)))

Oliver George 2020-08-05T01:42:43.106500Z

As for testing... perhaps others will have good suggestions. Worth teasing out what you want to test then talking about those specific cases.

Oliver George 2020-08-05T01:44:18.107Z

Note the interop.navigation/*initial-state trick... that reloads navigation state so that Figwheel style hot reloading doesn't reset the navigation state.

benny 2020-08-05T04:36:01.107400Z

this is great, thanks @olivergeorge!

benny 2020-08-05T04:42:37.107600Z

I ended up doing just that, teased out the re-frame-related code and shadow just compiles what i use so i just pulled out any native-related stuff