Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Just wondering why duration is fixed? #18

Open
Folcon opened this issue Nov 2, 2018 · 6 comments
Open

Just wondering why duration is fixed? #18

Folcon opened this issue Nov 2, 2018 · 6 comments

Comments

@Folcon
Copy link

Folcon commented Nov 2, 2018

Thanks for this, It's a pretty neat library, I was just trying to work out how to adjust the speed of the text being displayed based on what text is being shown, and how to send a sequence of text to be displayed at different speeds :)...

I was just playing around with a variant of your example which I adapted to slowly fade in text and I was wondering why the optional parameters such as duration are fixed? Essentially is there any way I can pass in an atom of options? Especially as x can be an atom. Or am I using this incorrectly?

(defn test-display-text [text]
  (let [x (reagent/atom 0) speed (reagent/atom 20) t (reagent/atom 20000)
        speed->duration (fn [] (do (println "x" @x "t" @t "speed" @speed)
                                   @t))]
    (fn [text]
      (let [cx (anim/interpolate-to x {:duration (speed->duration)})]
        (fn a-spring-example2-component [text]
          (when (= @cx 100)
            (println "Animation Done!"))
          [:div
           [:button {:on-click (fn [e] (swap! x - 50))} "<"]
           [:button {:on-click (fn [e] (swap! x + 50))} ">"]
           [:button {:on-click (fn [e] (reset! x 0))} "0%"]
           [:button {:on-click (fn [e] (reset! x 100))} "100%"]
           [:div {:style {:width (str @cx "%")
                          :white-space :nowrap
                          :overflow    :hidden}}
            [:p text]]
           [:svg [:circle {:r 20, :cx @cx, :cy 50, :fill "green"}]]])))))
@timothypratley
Copy link
Owner

timothypratley commented Nov 4, 2018 via email

@Folcon
Copy link
Author

Folcon commented Nov 8, 2018

Hey @timothypratley, that sounds great. Little busy at the moment, but I'll put something together this weekend =)...

@Folcon
Copy link
Author

Folcon commented Nov 14, 2018

@timothypratley Ok so I've had a think, perhaps something like?

duration-fn (fn []
               (cond
                 (fn? options)   (:duration (options))
                 (atom? options) (:duration @options)
                 :else           200))

Which would allow you to call (duration-fn) when you need the duration, and do similarly for easing?

With atom? defined as:

(defn atom? [x]
  "Tests if atom."
  (instance? cljs.core/IAtom x))

Can you think of something better?

@timothypratley
Copy link
Owner

timothypratley commented Nov 14, 2018 via email

@Folcon
Copy link
Author

Folcon commented Nov 14, 2018

Might need to make that cljs.core/IDeref then? As I believe the clojure.lang version isn't in cljs?

@timothypratley
Copy link
Owner

timothypratley commented Nov 14, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants