This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-30
Channels
- # announcements (31)
- # aws (17)
- # babashka (26)
- # babashka-sci-dev (8)
- # beginners (16)
- # biff (1)
- # calva (9)
- # cider (5)
- # clj-kondo (3)
- # clj-on-windows (38)
- # cljdoc (2)
- # cljs-dev (9)
- # cljsrn (6)
- # clojure (58)
- # clojure-europe (47)
- # clojure-nl (3)
- # clojure-norway (21)
- # clojure-uk (2)
- # clojurescript (25)
- # conjure (2)
- # data-science (7)
- # datomic (3)
- # emacs (12)
- # events (5)
- # fulcro (5)
- # honeysql (10)
- # introduce-yourself (7)
- # lsp (4)
- # meander (3)
- # nbb (18)
- # off-topic (28)
- # rdf (1)
- # releases (2)
- # sci (5)
- # shadow-cljs (23)
- # sql (5)
- # test-check (3)
Edit: resolved. 🙂 Good evening and happy friday all. Got another dumb question 🙂 I have a Stack Navigator, and wish to do something like the following: https://reactnavigation.org/docs/preventing-going-back/ I've been experimenting at the repl, unsuccessfully:
app.fx> (-> @!navigation-ref (j/get :addListener)) ;; this doesn't seem correct
#object[addListener]
app.fx> (-> @!navigation-ref (j/call :addListener)) ;; well, this at least gets a function
#object[Function]
app.fx> (j/call (-> @!navigation-ref (j/call :addListener))
"beforeRemove" ;; as per docs, arity 2: a type of event,
(fn [_] (print "hello, world"))) ;; and a callback
Execution error (TypeError) at (<cljs repl>:1).
undefined is not an object (evaluating 'f__31485__auto__.call')
:repl/exception!
I'll try inserting it into a screen and see if that has any effect, but I think I'm holding it wrong again.
Any help appreciated!(As expected, adding it in a screen rather than executing at the repl gets identical results)
yes, I am being stupid. It returns a function that can be called to unsubscribe from the event.
Likely all I need is (j/call @!navigation-ref :addListener :beforeRemove (fn [_] (print "hello, world")))
let's see...
ok, seems this is the correct invocation: (.addListener @!navigation-ref "state" #(>evt [:some-fx-example "got state change event"]))
where "state" here is a event type that fires whenever the navigator state changes at all.
for future explorers. (i.e., it's really not complicated, the same as clojure java methods. don't know how i ended up down the rabbithole on that one.)
the use case that I wanted this for probably isn't particularly viable with my use of re-frame, but i learnt something. 👍
some further stuff. am using react navigation just for the convenience of screen display, but don't actually want to care about the routing it does. I guess I am smashing rocks together and making my own navigator & routing. pain point was despite me having a regular routing flow via re-frame events, react navigation had this concept of stacked screens that people could just cycle back to with the back button. after some head-scratching, I modified my navigate fx:
(defn navigate [name]
(.navigate @!navigation-ref name (clj->js {}))
(.reset @!navigation-ref (clj->js {:index 0 :routes [^js (.getCurrentRoute @!navigation-ref)]})))
so there's no routing state directly within the navigator anymore, so nothing to go "back" to.
similarly on android:
(.addEventListener BackHandler "hardwareBackPress" (fn []
(print "back button pressed")
true))
would be where I can persist application state before app minimisation, though returning true completely suppresses the back button action.