improve profile screen performance (#18281)

This commit is contained in:
flexsurfer 2023-12-22 16:59:12 +01:00 committed by GitHub
parent eda8c0ccb0
commit 31acb8e9c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 17 deletions

View File

@ -15,10 +15,12 @@
:size :paragraph-2 :size :paragraph-2
:style (style/label props)} :style (style/label props)}
label]) label])
[rn/flat-list [rn/view {:style (style/settings-items props)}
{:data data (for [item data]
:style (style/settings-items props) ^{:key item}
:render-fn settings-item/view [:<>
:separator [rn/view {:style (style/settings-separator props)}]}]]) [settings-item/view item]
(when-not (= item (last data))
[rn/view {:style (style/settings-separator props)}])])]])
(def settings-category (quo.theme/with-theme category-internal)) (def settings-category (quo.theme/with-theme category-internal))

View File

@ -16,11 +16,12 @@
(defn- settings-item-view (defn- settings-item-view
[data] [data]
[rf/delay-render
[quo/category [quo/category
{:list-type :settings {:list-type :settings
:container-style {:padding-bottom 0} :container-style {:padding-bottom 0}
:blur? true :blur? true
:data data}]) :data data}]])
(defn scroll-handler (defn scroll-handler
[event scroll-y] [event scroll-y]
@ -29,12 +30,13 @@
(defn- footer (defn- footer
[logout-press] [logout-press]
[rf/delay-render
[rn/view {:style style/footer-container} [rn/view {:style style/footer-container}
[quo/logout-button {:on-press logout-press}]]) [quo/logout-button {:on-press logout-press}]]])
(defn- get-item-layout (defn- get-item-layout
[_ index] [_ index]
#js {:length 48 :offset (* 48 index) :index index}) #js {:length 100 :offset (* 100 index) :index index})
(defn- settings-view (defn- settings-view
[theme] [theme]
@ -60,12 +62,9 @@
{:key :list {:key :list
:header [settings.header/view {:scroll-y scroll-y}] :header [settings.header/view {:scroll-y scroll-y}]
:data settings.items/items :data settings.items/items
:key-fn :title
:get-item-layout get-item-layout
:initial-num-to-render 6
:max-to-render-per-batch 6
:shows-vertical-scroll-indicator false :shows-vertical-scroll-indicator false
:render-fn settings-item-view :render-fn settings-item-view
:get-item-layout get-item-layout
:footer [footer logout-press] :footer [footer logout-press]
:scroll-event-throttle 16 :scroll-event-throttle 16
:on-scroll #(scroll-handler % scroll-y) :on-scroll #(scroll-handler % scroll-y)

View File

@ -3,6 +3,7 @@
(:require (:require
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[re-frame.interceptor :as interceptor] [re-frame.interceptor :as interceptor]
[reagent.core :as reagent]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[utils.datetime :as datetime]) [utils.datetime :as datetime])
(:refer-clojure :exclude [merge reduce])) (:refer-clojure :exclude [merge reduce]))
@ -76,6 +77,14 @@
(swap! handler-nesting-level dec) (swap! handler-nesting-level dec)
res)) res))
(defn delay-render
[content]
(let [render? (reagent/atom false)]
(js/setTimeout #(reset! render? true) 0)
(fn []
(when @render?
content))))
(def sub (comp deref re-frame/subscribe)) (def sub (comp deref re-frame/subscribe))
(def dispatch re-frame/dispatch) (def dispatch re-frame/dispatch)