This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-11
Channels
- # announcements (6)
- # architecture (14)
- # babashka (26)
- # beginners (22)
- # calva (11)
- # clj-kondo (2)
- # clj-on-windows (1)
- # cljsrn (10)
- # clojure (116)
- # clojure-europe (5)
- # clojure-uk (1)
- # clojurescript (5)
- # cursive (9)
- # datomic (21)
- # depstar (1)
- # events (1)
- # fulcro (2)
- # graalvm (17)
- # graalvm-mobile (28)
- # helix (3)
- # introduce-yourself (2)
- # jobs (2)
- # lsp (4)
- # meander (1)
- # off-topic (4)
- # pathom (5)
- # polylith (6)
- # practicalli (5)
- # reagent (67)
- # reitit (1)
- # releases (2)
- # shadow-cljs (24)
- # tools-deps (23)
@lepistane I haven’t tried this PanResponder but I have used https://docs.swmansion.com/react-native-gesture-handler/
It was some time ago, but I think I spent a bunch of time trying to do PanResponder, but eventually ended up using react-native-gesture-handler which was better.
ok i've given up. I will claim it's impossible to make it work. I will @raspasov’s suggestion using rn-gesture-handler
@raspasov is there any way you could share working example using pan responder?
I am having trouble understanding how to set any handler that has Animated.Event
i am having trouble with even most minimalistic examples like this https://github.com/software-mansion/react-native-gesture-handler/blob/master/examples/Example/src/draggable/index.tsx
alright here is the basic working example that works with X axis. Basically when u start moving the box it follows the finger after you let go it bounces to the center. Why i didn't come up with this earlier i am surprised myself. I was looking at RN examples all of those used Animated.event which does some bindings under the hood which doesn't play well with cljs. So the way i made it work is
(defn draggable-view []
(let [bounce-value (new rn/Animated.Value 0)
on-press #(do (prn "AAA")
(-> bounce-value
(rn/Animated.spring #js {:toValue 125
:friction 1
:useNativeDriver true})
(.start)))
pan-responder (rn/PanResponder.create #js {:onStartShouldSetPanResponder (fn [arg] true)
:onPanResponderMove (fn [e state]
(.setValue ^js bounce-value (goog-obj/get state "dx")))
:onPanResponderRelease (fn [e state]
(-> bounce-value
(rn/Animated.spring #js {:toValue 0
:friction 1
:useNativeDriver true})
(.start)))})]
(fn []
[:> rn/Animated.View (merge (js->clj (.-panHandlers pan-responder))
{:style {:background-color "red"
:height 100
:width 100
:transform [{:translateX bounce-value}]}})])))
i think i already tried something like this before now but i couldn't make it work.
This example was born from https://doc.ebichu.cc/react-native/releases/next/docs/animations.html#tracking-gestures
that comment in following code section made it click.
if anyone has better way of doing this i am all ears.
hopefully someone will find it useful in the future 😄Glad it’s working! As for Animated.event:
(comment
(def event (.-Animated.event rn/ReactNative))
(some-scroll-view
{:onScroll (event
;scroll-y-anim is a React Animated value
(clj->js [{:nativeEvent {:contentOffset {:y scroll-y-anim}}}])
(clj->js {:useNativeDriver true}))}))
Once you have that :onScroll
handler, the scroll-y-anim
Animated.value will be mutably updated as the scroll view moves across the y-axis.Equivalent in JS is something like: https://reactnative.dev/docs/animated#handling-gestures-and-other-events