From 7af62c04eb937e4e8d16df50c58811b893838f1f Mon Sep 17 00:00:00 2001 From: Parvesh Monu Date: Fri, 29 Dec 2023 14:55:12 +0530 Subject: [PATCH] Keep chat screen loaded (#17839) --- src/status_im/contexts/chat/messages/view.cljs | 5 +++-- .../contexts/shell/jump_to/animation.cljs | 16 ++-------------- .../components/floating_screens/view.cljs | 5 +---- src/status_im/contexts/shell/jump_to/events.cljs | 12 ++++++------ 4 files changed, 12 insertions(+), 26 deletions(-) diff --git a/src/status_im/contexts/chat/messages/view.cljs b/src/status_im/contexts/chat/messages/view.cljs index e63726aacf..44b6bba7a4 100644 --- a/src/status_im/contexts/chat/messages/view.cljs +++ b/src/status_im/contexts/chat/messages/view.cljs @@ -13,8 +13,7 @@ ;; 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 -;; fixes related to the chat navigation bar, please skip them. -;; And ping me, so I can address them while refactoring +;; fixes related to the composer, please skip them. And ping me, so I can address them while refactoring (defn- f-chat-screen [calculations-complete?] (let [insets (safe-area/get-insets) @@ -47,6 +46,8 @@ (defn lazy-chat-screen [calculations-complete?] (let [screen-loaded? (rf/sub [:shell/chat-screen-loaded?])] + (when-not screen-loaded? + (reanimated/set-shared-value calculations-complete? false)) (when screen-loaded? [:f> f-chat-screen calculations-complete?]))) diff --git a/src/status_im/contexts/shell/jump_to/animation.cljs b/src/status_im/contexts/shell/jump_to/animation.cljs index 9ebbcfcca5..5d0f48e89a 100644 --- a/src/status_im/contexts/shell/jump_to/animation.cljs +++ b/src/status_im/contexts/shell/jump_to/animation.cljs @@ -1,6 +1,5 @@ (ns status-im.contexts.shell.jump-to.animation (:require - [react-native.platform :as platform] [react-native.reanimated :as reanimated] [status-im.contexts.shell.jump-to.constants :as shell.constants] [status-im.contexts.shell.jump-to.state :as state] @@ -47,11 +46,6 @@ ;;;; 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 [screen-id {:keys [id animation community-id hidden-screen?]}] (when (not= animation (get @state/floating-screens-state screen-id)) @@ -66,13 +60,7 @@ shell.constants/close-screen-without-animation} animation) 0 - 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)] + shell.constants/shell-animation-time)] (js/setTimeout (fn [floating-screen-open?] (if floating-screen-open? @@ -81,7 +69,7 @@ id community-id hidden-screen?]) ;; Events realted to closing of a screen (rf/dispatch [:shell/floating-screen-closed screen-id]))) - dispatch-time + animation-time floating-screen-open?)))) (defn set-floating-screen-position diff --git a/src/status_im/contexts/shell/jump_to/components/floating_screens/view.cljs b/src/status_im/contexts/shell/jump_to/components/floating_screens/view.cljs index 6f5f6d4d18..c597e015ca 100644 --- a/src/status_im/contexts/shell/jump_to/components/floating_screens/view.cljs +++ b/src/status_im/contexts/shell/jump_to/components/floating_screens/view.cljs @@ -33,12 +33,9 @@ [rn/view {:style (style/screen-container (utils/dimensions)) :accessibility-label (str screen-id "-floating-screen") - :accessible true - :key id} + :accessible true} [(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 [screen-id] (let [screen-param (rf/sub [:shell/floating-screen screen-id])] diff --git a/src/status_im/contexts/shell/jump_to/events.cljs b/src/status_im/contexts/shell/jump_to/events.cljs index eb5020504f..31214bf88e 100644 --- a/src/status_im/contexts/shell/jump_to/events.cljs +++ b/src/status_im/contexts/shell/jump_to/events.cljs @@ -201,9 +201,9 @@ (rf/defn floating-screen-closed {:events [:shell/floating-screen-closed]} [{:keys [db]} screen-id] - (merge - {:db (-> (update db :shell/floating-screens dissoc screen-id) - (update :shell/loaded-screens dissoc screen-id)) - :dispatch-n (cond-> [[:set-view-id :shell-stack]] - (= screen-id shell.constants/chat-screen) - (conj [:chat/close]))})) + {:db (cond-> (update db :shell/loaded-screens dissoc screen-id) + (= screen-id shell.constants/discover-communities-screen) + (update :shell/floating-screen dissoc screen-id)) + :dispatch-n (cond-> [[:set-view-id :shell-stack]] + (= screen-id shell.constants/chat-screen) + (conj [:chat/close]))})