mirror of
https://github.com/penpot/penpot.git
synced 2025-02-12 10:09:03 -05:00
🐛 Avoid extra render calls on page initialization with wasm render (#5701)
This commit is contained in:
parent
979de39768
commit
ce67550195
3 changed files with 26 additions and 13 deletions
|
@ -133,6 +133,7 @@
|
|||
frame-hover (mf/use-state nil)
|
||||
active-frames (mf/use-state #{})
|
||||
canvas-init? (mf/use-state false)
|
||||
initialized? (mf/use-state false)
|
||||
|
||||
;; REFS
|
||||
[viewport-ref
|
||||
|
@ -293,23 +294,28 @@
|
|||
(wasm.api/resize-viewbox (:width vport) (:height vport))))
|
||||
|
||||
(mf/with-effect [@canvas-init? base-objects]
|
||||
(when @canvas-init?
|
||||
(when (and @canvas-init? @initialized?)
|
||||
(wasm.api/set-objects base-objects)))
|
||||
|
||||
(mf/with-effect [@canvas-init? preview-blend]
|
||||
(when (and @canvas-init? preview-blend)
|
||||
(wasm.api/request-render "with-effect")))
|
||||
|
||||
(mf/with-effect [@canvas-init? vbox]
|
||||
(when @canvas-init?
|
||||
(mf/with-effect [@canvas-init? zoom vbox background]
|
||||
(when (and @canvas-init? (not @initialized?))
|
||||
(wasm.api/initialize base-objects zoom vbox background)
|
||||
(reset! initialized? true)))
|
||||
|
||||
(mf/with-effect [vbox]
|
||||
(when (and @canvas-init? initialized?)
|
||||
(wasm.api/set-view-zoom zoom vbox)))
|
||||
|
||||
(mf/with-effect [@canvas-init? vbox]
|
||||
(when @canvas-init?
|
||||
(mf/with-effect [vbox]
|
||||
(when (and @canvas-init? initialized?)
|
||||
(wasm.api/set-view-box zoom vbox)))
|
||||
|
||||
(mf/with-effect [@canvas-init? background]
|
||||
(when @canvas-init?
|
||||
(mf/with-effect [background]
|
||||
(when (and @canvas-init? initialized?)
|
||||
(wasm.api/set-canvas-background background)))
|
||||
|
||||
(hooks/setup-dom-events zoom disable-paste in-viewport? read-only? drawing-tool drawing-path?)
|
||||
|
|
|
@ -573,6 +573,19 @@
|
|||
(rx/reduce conj [])
|
||||
(rx/subs! request-render)))))
|
||||
|
||||
(defn set-canvas-background
|
||||
[background]
|
||||
(let [rgba (rgba-from-hex background 1)]
|
||||
(h/call internal-module "_set_canvas_background" rgba)
|
||||
(request-render "set-canvas-background")))
|
||||
|
||||
(defn initialize
|
||||
[base-objects zoom vbox background]
|
||||
(let [rgba (rgba-from-hex background 1)]
|
||||
(h/call internal-module "_set_canvas_background" rgba)
|
||||
(h/call internal-module "_set_view" zoom (- (:x vbox)) (- (:y vbox)))
|
||||
(set-objects base-objects)))
|
||||
|
||||
(def ^:private canvas-options
|
||||
#js {:antialias false
|
||||
:depth true
|
||||
|
@ -610,11 +623,6 @@
|
|||
;; TODO: perform corresponding cleaning
|
||||
(h/call internal-module "_clean_up"))
|
||||
|
||||
(defn set-canvas-background
|
||||
[background]
|
||||
(let [rgba (rgba-from-hex background 1)]
|
||||
(h/call internal-module "_set_canvas_background" rgba)))
|
||||
|
||||
(defonce module
|
||||
(delay
|
||||
(if (exists? js/dynamicImport)
|
||||
|
|
|
@ -67,6 +67,5 @@ impl<'a> State<'a> {
|
|||
|
||||
pub fn set_background_color(&mut self, color: skia::Color) {
|
||||
self.render_state.set_background_color(color);
|
||||
self.render_all(true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue