Keep chat screen loaded (#17839)

This commit is contained in:
Parvesh Monu 2023-12-29 14:55:12 +05:30 committed by GitHub
parent 169a092e7f
commit 7af62c04eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 26 deletions

View File

@ -13,8 +13,7 @@
;; NOTE(parvesh) - I am working on refactoring/optimization of the chat screen for performance ;; NOTE(parvesh) - I am working on refactoring/optimization of the chat screen for performance
;; improvement. Please avoid refactoring these files. Also if you are not already working on bug ;; improvement. Please avoid refactoring these files. Also if you are not already working on bug
;; fixes related to the chat navigation bar, please skip them. ;; fixes related to the composer, please skip them. And ping me, so I can address them while refactoring
;; And ping me, so I can address them while refactoring
(defn- f-chat-screen (defn- f-chat-screen
[calculations-complete?] [calculations-complete?]
(let [insets (safe-area/get-insets) (let [insets (safe-area/get-insets)
@ -47,6 +46,8 @@
(defn lazy-chat-screen (defn lazy-chat-screen
[calculations-complete?] [calculations-complete?]
(let [screen-loaded? (rf/sub [:shell/chat-screen-loaded?])] (let [screen-loaded? (rf/sub [:shell/chat-screen-loaded?])]
(when-not screen-loaded?
(reanimated/set-shared-value calculations-complete? false))
(when screen-loaded? (when screen-loaded?
[:f> f-chat-screen calculations-complete?]))) [:f> f-chat-screen calculations-complete?])))

View File

@ -1,6 +1,5 @@
(ns status-im.contexts.shell.jump-to.animation (ns status-im.contexts.shell.jump-to.animation
(:require (:require
[react-native.platform :as platform]
[react-native.reanimated :as reanimated] [react-native.reanimated :as reanimated]
[status-im.contexts.shell.jump-to.constants :as shell.constants] [status-im.contexts.shell.jump-to.constants :as shell.constants]
[status-im.contexts.shell.jump-to.state :as state] [status-im.contexts.shell.jump-to.state :as state]
@ -47,11 +46,6 @@
;;;; Floating Screen ;;;; Floating Screen
;; Dispatch Delay - Animation time for the opening of a screen is 200 ms,
;; But starting and completion of animation sometimes takes a little extra time,
;; according to the performance of the device. And if before the animation is
;; complete we start other tasks like rendering messages or opening of the home screen
;; in the background then the animation breaks. So we are adding a small delay for that dispatch.
(defn animate-floating-screen (defn animate-floating-screen
[screen-id {:keys [id animation community-id hidden-screen?]}] [screen-id {:keys [id animation community-id hidden-screen?]}]
(when (not= animation (get @state/floating-screens-state screen-id)) (when (not= animation (get @state/floating-screens-state screen-id))
@ -66,13 +60,7 @@
shell.constants/close-screen-without-animation} shell.constants/close-screen-without-animation}
animation) animation)
0 0
shell.constants/shell-animation-time) shell.constants/shell-animation-time)]
dispatch-delay (cond
(not floating-screen-open?) 0
js/goog.DEBUG 100
platform/android? 75
:else 50)
dispatch-time (+ animation-time dispatch-delay)]
(js/setTimeout (js/setTimeout
(fn [floating-screen-open?] (fn [floating-screen-open?]
(if floating-screen-open? (if floating-screen-open?
@ -81,7 +69,7 @@
id community-id hidden-screen?]) id community-id hidden-screen?])
;; Events realted to closing of a screen ;; Events realted to closing of a screen
(rf/dispatch [:shell/floating-screen-closed screen-id]))) (rf/dispatch [:shell/floating-screen-closed screen-id])))
dispatch-time animation-time
floating-screen-open?)))) floating-screen-open?))))
(defn set-floating-screen-position (defn set-floating-screen-position

View File

@ -33,12 +33,9 @@
[rn/view [rn/view
{:style (style/screen-container (utils/dimensions)) {:style (style/screen-container (utils/dimensions))
:accessibility-label (str screen-id "-floating-screen") :accessibility-label (str screen-id "-floating-screen")
:accessible true :accessible true}
:key id}
[(get screens-map screen-id) id]]])) [(get screens-map screen-id) id]]]))
;; Currently chat screen and events both depends on current-chat-id, once we remove
;; use of current-chat-id from view then we can keep last chat loaded, for fast navigation
(defn lazy-screen (defn lazy-screen
[screen-id] [screen-id]
(let [screen-param (rf/sub [:shell/floating-screen screen-id])] (let [screen-param (rf/sub [:shell/floating-screen screen-id])]

View File

@ -201,9 +201,9 @@
(rf/defn floating-screen-closed (rf/defn floating-screen-closed
{:events [:shell/floating-screen-closed]} {:events [:shell/floating-screen-closed]}
[{:keys [db]} screen-id] [{:keys [db]} screen-id]
(merge {:db (cond-> (update db :shell/loaded-screens dissoc screen-id)
{:db (-> (update db :shell/floating-screens dissoc screen-id) (= screen-id shell.constants/discover-communities-screen)
(update :shell/loaded-screens dissoc screen-id)) (update :shell/floating-screen dissoc screen-id))
:dispatch-n (cond-> [[:set-view-id :shell-stack]] :dispatch-n (cond-> [[:set-view-id :shell-stack]]
(= screen-id shell.constants/chat-screen) (= screen-id shell.constants/chat-screen)
(conj [:chat/close]))})) (conj [:chat/close]))})