0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-15 11:38:24 -05:00

Refactor viewer shape-container component

Still need a rething for the fixed position shapes
feature because watching scroll position on all shapes
is killing viewer performance.
This commit is contained in:
Andrey Antukh 2022-08-23 07:46:35 +02:00 committed by Andrés Moya
parent b9f767a614
commit f9b44ccc5c

View file

@ -383,31 +383,43 @@
image-wrapper (image-wrapper) image-wrapper (image-wrapper)
circle-wrapper (circle-wrapper)] circle-wrapper (circle-wrapper)]
(mf/fnc shape-container (mf/fnc shape-container
{::mf/wrap-props false} {::mf/wrap-props false
::mf/wrap [mf/memo]}
[props] [props]
(let [scroll (mf/use-ctx ctx/scroll-ctx) (let [shape (unchecked-get props "shape")
local (mf/deref refs/viewer-local)
zoom (:zoom local)
shape (unchecked-get props "shape")
parents (map (d/getf objects) (cph/get-parent-ids objects (:id shape)))
fixed? (or (:fixed-scroll shape) (some :fixed-scroll parents))
frame (unchecked-get props "frame") frame (unchecked-get props "frame")
delta {:x (/ (:scroll-left scroll) zoom) :y (/ (:scroll-top scroll) zoom)}
;; TODO: this watch of scroll position is killing
;; performance of the viewer.
scroll (mf/use-ctx ctx/current-scroll)
zoom (mf/use-ctx ctx/current-zoom)
fixed? (mf/with-memo [shape objects]
(->> (cph/get-parent-ids objects (:id shape))
(map (d/getf objects))
(concat [shape])
(some :fixed-scroll)))
delta {:x (/ (:scroll-left scroll) zoom)
:y (/ (:scroll-top scroll) zoom)}
group-container group-container
(mf/use-memo (mf/deps objects) (mf/with-memo [objects]
#(group-container-factory objects)) (group-container-factory objects))
frame-container frame-container
(mf/use-memo (mf/deps objects) (mf/with-memo [objects]
#(frame-container-factory objects)) (frame-container-factory objects))
bool-container bool-container
(mf/use-memo (mf/deps objects) (mf/with-memo [objects]
#(bool-container-factory objects)) (bool-container-factory objects))
svg-raw-container svg-raw-container
(mf/use-memo (mf/deps objects) (mf/with-memo [objects]
#(svg-raw-container-factory objects))] (svg-raw-container-factory objects))
]
(when (and shape (not (:hidden shape))) (when (and shape (not (:hidden shape)))
(let [shape (-> (gsh/transform-shape shape) (let [shape (-> (gsh/transform-shape shape)
(gsh/translate-to-frame frame) (gsh/translate-to-frame frame)
@ -425,4 +437,3 @@
:group [:> group-container {:shape shape :frame frame :objects objects :fixed? fixed? :delta delta}] :group [:> group-container {:shape shape :frame frame :objects objects :fixed? fixed? :delta delta}]
:bool [:> bool-container {:shape shape :frame frame :objects objects}] :bool [:> bool-container {:shape shape :frame frame :objects objects}]
:svg-raw [:> svg-raw-container {:shape shape :frame frame :objects objects}]))))))) :svg-raw [:> svg-raw-container {:shape shape :frame frame :objects objects}])))))))