From f736ec813e67108131abcde4bb9d7d93b41a35ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Fri, 9 Sep 2022 12:01:06 +0200 Subject: [PATCH] :bug: Fix origin-frame calculation --- frontend/src/app/main/ui/viewer.cljs | 34 ++++++++++++--------- frontend/src/app/main/ui/viewer/shapes.cljs | 2 +- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/frontend/src/app/main/ui/viewer.cljs b/frontend/src/app/main/ui/viewer.cljs index 4880504ef2..5eef0464d2 100644 --- a/frontend/src/app/main/ui/viewer.cljs +++ b/frontend/src/app/main/ui/viewer.cljs @@ -235,7 +235,6 @@ viewer-section-ref (mf/use-ref nil) current-animations (mf/deref current-animations-ref) - first-animation (first (vals current-animations)) page-id (or page-id (-> file :data :pages first)) @@ -259,8 +258,13 @@ scroll (mf/use-state nil) orig-frame - (when (:orig-frame-id first-animation) - (d/seek #(= (:id %) (:orig-frame-id first-animation)) frames)) + (mf/with-memo [current-animations] + ;; We assume there can only be one animation with origin (this is used only in + ;; navigation animations, and we cannot navigate to two different destinations + ;; at the same time). + (let [animation-with-origin (d/seek :orig-frame-id (vals current-animations))] + (when animation-with-origin + (d/seek #(= (:id %) (:orig-frame-id animation-with-origin)) frames)))) size (mf/with-memo [frame zoom] @@ -385,21 +389,21 @@ (wapi/exit-fullscreen)))))) (mf/use-layout-effect - (mf/deps index) + (mf/deps index current-animations) (fn [] ;; Navigate animation needs to be started after navigation ;; is complete, and we have the next page index. - (when (and first-animation - (= (:kind first-animation) :go-to-frame)) - (let [orig-viewport (mf/ref-val orig-viewport-ref) - current-viewport (mf/ref-val current-viewport-ref)] - (interactions/animate-go-to-frame - (:animation first-animation) - current-viewport - orig-viewport - size - orig-size - wrapper-size))))) + (let [nav-animation (d/seek #(= (:kind %) :go-to-frame) (vals current-animations))] + (when nav-animation + (let [orig-viewport (mf/ref-val orig-viewport-ref) + current-viewport (mf/ref-val current-viewport-ref)] + (interactions/animate-go-to-frame + (:animation nav-animation) + current-viewport + orig-viewport + size + orig-size + wrapper-size)))))) (mf/use-layout-effect (mf/deps current-animations) diff --git a/frontend/src/app/main/ui/viewer/shapes.cljs b/frontend/src/app/main/ui/viewer/shapes.cljs index 6c25990914..d0609383f3 100644 --- a/frontend/src/app/main/ui/viewer/shapes.cljs +++ b/frontend/src/app/main/ui/viewer/shapes.cljs @@ -69,7 +69,7 @@ :toggle-overlay (let [frame-id (:destination interaction) - dest-frame (get objects frame-id) + dest-frame (get objects frame-id) position (ctsi/calc-overlay-position interaction base-frame dest-frame