This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-12
Channels
- # announcements (1)
- # aws (1)
- # babashka (63)
- # beginners (108)
- # calva (12)
- # cider (6)
- # cljdoc (2)
- # cljsrn (33)
- # clojure (150)
- # clojure-europe (28)
- # clojure-nl (13)
- # clojure-spain (1)
- # clojure-spec (8)
- # clojure-uk (25)
- # clojurescript (16)
- # conjure (7)
- # cursive (7)
- # datomic (15)
- # duct (2)
- # eastwood (2)
- # figwheel (1)
- # figwheel-main (1)
- # fulcro (6)
- # graalvm (1)
- # graalvm-mobile (1)
- # helix (6)
- # honeysql (23)
- # integrant (6)
- # introduce-yourself (4)
- # jobs (10)
- # lsp (132)
- # malli (4)
- # meander (1)
- # membrane (1)
- # off-topic (223)
- # pathom (23)
- # pedestal (3)
- # re-frame (18)
- # reagent (13)
- # releases (1)
- # remote-jobs (2)
- # shadow-cljs (68)
- # tools-deps (217)
- # vim (19)
- # xtdb (79)
I've tried this but it doesn't work.
`(def event rn/Animated.event)
(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 (event
(clj->js [{:nativeEvent {:contentOffset {:x bounce-value}}}])
(clj->js {:useNativeDriver true}))
#_(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}]}})])))
and it gives me
TypeError: config.onPanResponderMove is not a function. (In 'config.onPanResponderMove(event, gestureState)', 'config.onPanResponderMove' is an instance of AnimatedEvent)
am i doing something wrong? @raspasovSo we’re in the same spot 🙂 Let me see what could be the problem here… Again, I would say PanResponder is kinda irrelevant if you get reanimated
going. But I’m curious what’s the reason for this error.
makes sense but some of the examples in react native gesture handler do use animated.event https://snack.expo.io/@adamgrzybowski/react-native-gesture-handler-demo and i failed to recreate them as well that's why i went back and figure out animated.event and move from there. Since i failed i got workaround working and that's what i shared
Ok first thing:
:onPanResponderMove (fn [evt gesture-state]
(timbre/info "Move!!!")
(timbre/spy (js->clj gesture-state)))
This works.Animated.event is weird… It’s basically a helper: https://reactnative.dev/docs/animated#event
“Takes an array of mappings and extracts values from each arg accordingly, then calls `setValue` on the mapped outputs. e.g.”
yep oki so at least we have conclusion to just use setvalue manually as described https://clojurians.slack.com/archives/C0E1SN0NM/p1626040969278900
(fn [evt gesture-state]
(let [dx (.-dx gesture-state)
dy (.-dy gesture-state)]
(timbre/spy [dx dy])
(.setValue (.-x pan-current) dx)
(.setValue (.-y pan-current) dy)))
Yes! I now recall having some weird issues with this as well years ago. No idea why it “works” with :onScroll …
^^ I have had those kinds of events working for a very long time via :onScroll with the weird helper… Very strange. Perhaps something about that nil
first parameter in onResponderMove
throws it off but I could be wrong.
i've tried using not having first argument nil and using that native event without luck 🙂
Yeah there’s something whack about it… I wonder if this will even work from JavaScript.
Old issues here from 2017 https://github.com/facebook/react-native/issues/13377
Yeahhhh… “This is a current limitation of native Animated.event. It doesn’t work with PanResponder because it is implemented in JavaScript.”
And I think they never fixed it for PanResponder, because you can use things like “reanimated”… but the “Animated.event magic trick helper” should work for Animated.ScrollView
and other components …
wait if that's the case then their examples wouldn't work either (pan responder with animated.event )https://reactnative.dev/docs/panresponder#example
i am sorry to bother you again. How did u exactly make react native gesture handler work?
(defn draggable-view-gesture []
(let [x (new rn/Animated.Value 0)]
(fn []
[:> rn/View {:flex 1
:justify-content :center}
[:> gesture/PanGestureHandler {:maxPointers 1
:onGestureEvent #(prn "AAA")}
[:> rn/Animated.View {:style {:background-color "blue"
:height 100
:width 100
:transform [{:translateX x}]}}]]])))
onGestureEvent never fires.
installation process was
npm install --save react-native-gesture-handler
first require is
["react-native-gesture-handler" :as gesture]
cli version 2.0.1
rn version 0.64i tried with different versions version of rn and gesture-handler
"react-native-gesture-handler": "^1.6.1",
"react-native-reanimated": "^1.8.0",
"react-native": "0.62.2",
This project has react navigation working (which uses gesture-handler) and still onGestureEvent didn't trigger
and
"react-native": "0.64.2",
"react-native-gesture-handler": "^1.10.3",
"react-native-reanimated": "^2.2.0"
same behavior.
I am testing only android emulator.turns out this is quite important https://docs.swmansion.com/react-native-gesture-handler/docs/#updating-mainactivityjava
(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")))
(rn/Animated.event (clj->js [nil
{:dx bounce-value}])
(clj->js {:useNativeDriver false}))
:onPanResponderRelease (fn [e state]
(-> bounce-value
(rn/Animated.spring #js {:toValue 0
:friction 1
:useNativeDriver false})
(.start)))})]
(fn []
[:> rn/Animated.View (merge (js->clj (.-panHandlers pan-responder))
{:style {:background-color "red"
:height 100
:width 100
:transform [{:translateX bounce-value}]}})])))
this working example that's using animated.event
if u set native driver true you need to pay attention to what values are in the 'event'.
if u set {:useNativeDriver true}
this will break how we saw earlier. Native driver changes this type of this fn call and it isn't compatible with panResponder
if that is false you can use what ever value u want.
(clj->js)
is quite important here what i had before was #js which is shallow
people smarter than me figured out how to use this.
https://lwhorton.github.io/2018/10/20/clojurescript-interop-with-javascript.html
https://github.com/status-im/status-react/blob/5f719ac95b8776d510ed809b06bbc959eab3b9f3/src/quo/animated.cljs#L101working example of react native panResponder (excluding animations.events) https://reactnative.dev/docs/panresponder#example https://gist.github.com/StankovicMarko/eff7726693bc10b714fe403519437d4a
fully working example of react-native-gesture-handler draggable view (including animated.event) that was described https://snack.expo.io/@adamgrzybowski/react-native-gesture-handler-demo done in plain cljsrn (no expo) https://gist.github.com/StankovicMarko/260deed5f57e0bcc15d95444cc5ac5a3
(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")))
(rn/Animated.event (clj->js [nil
{:dx bounce-value}])
(clj->js {:useNativeDriver false}))
:onPanResponderRelease (fn [e state]
(-> bounce-value
(rn/Animated.spring #js {:toValue 0
:friction 1
:useNativeDriver false})
(.start)))})]
(fn []
[:> rn/Animated.View (merge (js->clj (.-panHandlers pan-responder))
{:style {:background-color "red"
:height 100
:width 100
:transform [{:translateX bounce-value}]}})])))
this working example that's using animated.event
if u set native driver true you need to pay attention to what values are in the 'event'.
if u set {:useNativeDriver true}
this will break how we saw earlier. Native driver changes this type of this fn call and it isn't compatible with panResponder
if that is false you can use what ever value u want.
(clj->js)
is quite important here what i had before was #js which is shallow
people smarter than me figured out how to use this.
https://lwhorton.github.io/2018/10/20/clojurescript-interop-with-javascript.html
https://github.com/status-im/status-react/blob/5f719ac95b8776d510ed809b06bbc959eab3b9f3/src/quo/animated.cljs#L101