diff --git a/src/status_im/communities/core.cljs b/src/status_im/communities/core.cljs index 9d7d3733b5..fc4437d698 100644 --- a/src/status_im/communities/core.cljs +++ b/src/status_im/communities/core.cljs @@ -276,7 +276,7 @@ (vals (get-in db [:communities community-id :chats])))] (when (and id (not= (:current-chat-id db) (str community-id id))) - (chat.events/navigate-to-chat cofx (str community-id id) nil)))) + (chat.events/navigate-to-chat cofx (str community-id id))))) (rf/defn fetch [_] @@ -817,7 +817,7 @@ [cofx community-id] (rf/merge cofx (navigation/pop-to-root :shell-stack) - (navigation/navigate-to-nav2 :community community-id true))) + (navigation/navigate-to-cofx :community-overview community-id))) (rf/defn member-role-updated {:events [:community.member/role-updated]} diff --git a/src/status_im/group_chats/core.cljs b/src/status_im/group_chats/core.cljs index 41e56914c2..4c1413d8e6 100644 --- a/src/status_im/group_chats/core.cljs +++ b/src/status_im/group_chats/core.cljs @@ -15,7 +15,7 @@ {:events [:navigate-chat-updated]} [cofx chat-id] (when (get-in cofx [:db :chats chat-id]) - (chat.events/navigate-to-chat cofx chat-id nil))) + (chat.events/navigate-to-chat cofx chat-id))) (rf/defn handle-chat-removed {:events [:chat-removed]} diff --git a/src/status_im/multiaccounts/login/core.cljs b/src/status_im/multiaccounts/login/core.cljs index 59759f652b..5e2eacf621 100644 --- a/src/status_im/multiaccounts/login/core.cljs +++ b/src/status_im/multiaccounts/login/core.cljs @@ -44,6 +44,7 @@ [status-im2.navigation.events :as navigation] [status-im2.common.log :as logging] [taoensso.timbre :as log] + [status-im2.contexts.shell.animation :as shell.animation] [utils.security.core :as security])) (re-frame/reg-fx @@ -520,6 +521,7 @@ tos-accepted? (get db :tos/accepted?) {:networks/keys [current-network networks]} db network-id (str (get-in networks [current-network :config :NetworkId]))] + (shell.animation/change-selected-stack-id :communities-stack true) (rf/merge cofx {:db (-> db (dissoc :multiaccounts/login) diff --git a/src/status_im/ui/screens/communities/views.cljs b/src/status_im/ui/screens/communities/views.cljs index f554e7ae4f..33cfe7612a 100644 --- a/src/status_im/ui/screens/communities/views.cljs +++ b/src/status_im/ui/screens/communities/views.cljs @@ -48,7 +48,7 @@ :on-press (fn [] (rf/dispatch [:communities/load-category-states id]) (rf/dispatch [:dismiss-keyboard]) - (rf/dispatch [:navigate-to-nav2 :community {:community-id id}])) + (rf/dispatch [:navigate-to :community-overview id])) :on-long-press #(rf/dispatch [:bottom-sheet/show-sheet {:content (fn [] [community/community-actions community])}])} @@ -111,7 +111,7 @@ (i18n/label :t/open-membership))]] :on-press #(do (rf/dispatch [:dismiss-keyboard]) - (rf/dispatch [:navigate-to-nav2 :community {:community-id id}]))}])) + (rf/dispatch [:navigate-to :community-overview id]))}])) (defn communities-actions [] diff --git a/src/status_im/ui2/screens/chat/messages/message.cljs b/src/status_im/ui2/screens/chat/messages/message.cljs index 07e71375d3..26037a41df 100644 --- a/src/status_im/ui2/screens/chat/messages/message.cljs +++ b/src/status_im/ui2/screens/chat/messages/message.cljs @@ -384,7 +384,7 @@ [rn/touchable-opacity {:on-press #(re-frame/dispatch [:communities/navigate-to-community - {:community-id (:id community)}])} + (:id community)])} [rn/text {:style {:text-align :center :color quo.colors/blue}} (i18n/label :t/view)]]]]))) diff --git a/src/status_im2/contexts/chat/events.cljs b/src/status_im2/contexts/chat/events.cljs index 109185fb7a..527c2e3202 100644 --- a/src/status_im2/contexts/chat/events.cljs +++ b/src/status_im2/contexts/chat/events.cljs @@ -202,9 +202,9 @@ (rf/defn navigate-to-chat "Takes coeffects map and chat-id, returns effects necessary for navigation and preloading data" {:events [:chat/navigate-to-chat]} - [{db :db :as cofx} chat-id from-shell?] + [{db :db :as cofx} chat-id] (rf/merge cofx - {:dispatch [:navigate-to-nav2 :chat chat-id from-shell?]} + {:dispatch [:navigate-to :chat chat-id]} (when-not (or (= (:view-id db) :community) (= (:view-id db) :community-overview)) (navigation/pop-to-root :shell-stack)) (close-chat false) diff --git a/src/status_im2/contexts/chat/events_test.cljs b/src/status_im2/contexts/chat/events_test.cljs index 0fd48fb98d..1673e6e97a 100644 --- a/src/status_im2/contexts/chat/events_test.cljs +++ b/src/status_im2/contexts/chat/events_test.cljs @@ -88,7 +88,7 @@ (let [chat-id "test_chat" db {:pagination-info {chat-id {:all-loaded? true}}}] (testing "Pagination info should be reset on navigation" - (let [res (chat/navigate-to-chat {:db db} chat-id false)] + (let [res (chat/navigate-to-chat {:db db} chat-id)] (is (nil? (get-in res [:db :pagination-info chat-id :all-loaded?]))))))) (deftest camera-roll-loading-more-test diff --git a/src/status_im2/contexts/communities/discover/view.cljs b/src/status_im2/contexts/communities/discover/view.cljs index 13e9c6fd87..81818fc430 100644 --- a/src/status_im2/contexts/communities/discover/view.cljs +++ b/src/status_im2/contexts/communities/discover/view.cljs @@ -34,7 +34,7 @@ {:on-press (fn [] (rf/dispatch [:communities/load-category-states (:id item)]) (rf/dispatch [:dismiss-keyboard]) - (rf/dispatch [:navigate-to :community {:community-id (:id item)}])) + (rf/dispatch [:navigate-to :community-overview (:id item)])) :on-long-press #(rf/dispatch [:bottom-sheet/show-sheet {:content (fn [] @@ -144,7 +144,7 @@ {:on-press (fn [] (rf/dispatch [:communities/load-category-states (:id community)]) (rf/dispatch [:dismiss-keyboard]) - (rf/dispatch [:navigate-to :community (:id community)])) + (rf/dispatch [:navigate-to :community-overview (:id community)])) :on-long-press #(rf/dispatch [:bottom-sheet/show-sheet {:content (fn [] ;; TODO implement with quo2 diff --git a/src/status_im2/contexts/communities/home/view.cljs b/src/status_im2/contexts/communities/home/view.cljs index 8cb22a8e49..4b9ede0792 100644 --- a/src/status_im2/contexts/communities/home/view.cljs +++ b/src/status_im2/contexts/communities/home/view.cljs @@ -18,7 +18,7 @@ item (merge item unviewed-counts)] [quo/communities-membership-list-item {:style {:padding-horizontal 18} - :on-press #(rf/dispatch [:navigate-to-nav2 :community-overview id]) + :on-press #(rf/dispatch [:navigate-to :community-overview id]) :on-long-press #(rf/dispatch [:bottom-sheet/show-sheet {:content (fn [] diff --git a/src/status_im2/contexts/shell/animation.cljs b/src/status_im2/contexts/shell/animation.cljs index 7a2e7b1313..2d03a39b2c 100644 --- a/src/status_im2/contexts/shell/animation.cljs +++ b/src/status_im2/contexts/shell/animation.cljs @@ -26,6 +26,16 @@ (or (= state shell.constants/open-with-animation) (= state shell.constants/open-without-animation)))) +(defn calculate-home-stack-state-value + [stack-id & animate?] + (if animate? + (if (some? stack-id) + shell.constants/open-with-animation + shell.constants/close-with-animation) + (if (some? stack-id) + shell.constants/open-without-animation + shell.constants/close-without-animation))) + (defn load-stack [stack-id] (case stack-id @@ -35,14 +45,14 @@ :browser-stack (reset! load-browser-stack? true) "")) -(defn selected-stack-id-loaded - [stack-id] - (reset! selected-stack-id stack-id) - (reset! - home-stack-state - (if (some? stack-id) - shell.constants/open-with-animation - shell.constants/close-with-animation))) +(defn change-selected-stack-id + [stack-id & [store? home-stack-state-value]] + (let [home-stack-state-value (or home-stack-state-value + (calculate-home-stack-state-value stack-id))] + (reset! selected-stack-id stack-id) + (reset! home-stack-state home-stack-state-value) + (when store? + (async-storage/set-item! :selected-stack-id stack-id)))) (defn calculate-home-stack-position [] @@ -133,28 +143,17 @@ (defn open-home-stack [stack-id animate?] - (let [home-stack-state-value (if animate? - shell.constants/open-with-animation - shell.constants/open-without-animation)] - (reanimated/set-shared-value - (:selected-stack-id @shared-values-atom) - (name stack-id)) - (reanimated/set-shared-value - (:home-stack-state @shared-values-atom) - home-stack-state-value) - (reset! home-stack-state home-stack-state-value) - (js/setTimeout - change-root-status-bar-style - shell.constants/shell-animation-time) - (reset! selected-stack-id stack-id) - (async-storage/set-item! :selected-stack-id stack-id))) + (let [home-stack-state-value (calculate-home-stack-state-value stack-id animate?)] + (reanimated/set-shared-value (:selected-stack-id @shared-values-atom) (name stack-id)) + (reanimated/set-shared-value (:home-stack-state @shared-values-atom) home-stack-state-value) + (js/setTimeout change-root-status-bar-style shell.constants/shell-animation-time) + (change-selected-stack-id stack-id true home-stack-state-value))) (defn change-tab [stack-id] (reanimated/set-shared-value (:animate-home-stack-left @shared-values-atom) false) (reanimated/set-shared-value (:selected-stack-id @shared-values-atom) (name stack-id)) - (reset! selected-stack-id stack-id) - (async-storage/set-item! :selected-stack-id stack-id)) + (change-selected-stack-id stack-id true)) (defn bottom-tab-on-press [stack-id] @@ -169,16 +168,9 @@ (defn close-home-stack [animate?] - (let [home-stack-state-value (if animate? - shell.constants/close-with-animation - shell.constants/close-without-animation)] - (reanimated/set-shared-value - (:animate-home-stack-left @shared-values-atom) - true) - (reanimated/set-shared-value - (:home-stack-state @shared-values-atom) - home-stack-state-value) - (reset! home-stack-state home-stack-state-value) + (let [stack-id nil + home-stack-state-value (calculate-home-stack-state-value stack-id animate?)] + (reanimated/set-shared-value (:animate-home-stack-left @shared-values-atom) true) + (reanimated/set-shared-value (:home-stack-state @shared-values-atom) home-stack-state-value) (change-root-status-bar-style) - (reset! selected-stack-id nil) - (async-storage/set-item! :selected-stack-id nil))) + (change-selected-stack-id stack-id true home-stack-state-value))) diff --git a/src/status_im2/core.cljs b/src/status_im2/core.cljs index cfd4c799ad..b06462f487 100644 --- a/src/status_im2/core.cljs +++ b/src/status_im2/core.cljs @@ -42,7 +42,7 @@ (utils.universal-links/initialize) ;; TODO(parvesh) - Remove while moving functionality to status-go - (async-storage/get-item :selected-stack-id #(animation/selected-stack-id-loaded %)) + (async-storage/get-item :selected-stack-id #(animation/change-selected-stack-id %)) (async-storage/get-item :screen-height #(reset! animation/screen-height %)) diff --git a/src/status_im2/navigation/events.cljs b/src/status_im2/navigation/events.cljs index b0e4ed36e4..a6c5447df5 100644 --- a/src/status_im2/navigation/events.cljs +++ b/src/status_im2/navigation/events.cljs @@ -11,11 +11,16 @@ (assoc-in [:navigation/screen-params view] screen-params))) (rf/defn navigate-to-cofx - [{:keys [db]} go-to-view-id screen-params] - {:db - (-> (assoc db :view-id go-to-view-id) - (all-screens-params go-to-view-id screen-params)) - :navigate-to-fx go-to-view-id}) + [{:keys [db] :as cofx} go-to-view-id screen-params] + (merge + {:db (-> (assoc db :view-id go-to-view-id) + (all-screens-params go-to-view-id screen-params)) + :navigate-to-fx go-to-view-id} + (when (#{:chat :community-overview} go-to-view-id) + {:dispatch-later + ;; 300 ms delay because, navigation is priority over shell card update + [{:dispatch [:shell/add-switcher-card go-to-view-id screen-params] + :ms 300}]}))) (rf/defn navigate-to {:events [:navigate-to]} @@ -100,14 +105,6 @@ {:shell/reset-bottom-tabs nil :dispatch [:init-root :shell-stack]}) -(rf/defn navigate-to-nav2 - {:events [:navigate-to-nav2]} - [cofx view-id screen-params from-shell?] - (rf/merge - cofx - {:dispatch [:shell/add-switcher-card view-id screen-params from-shell?]} - (navigate-to-cofx view-id screen-params))) - (rf/defn change-root-status-bar-style {:events [:change-root-status-bar-style]} [_ style] diff --git a/src/status_im2/subs/shell.cljs b/src/status_im2/subs/shell.cljs index 99ad44c911..afcaa58021 100644 --- a/src/status_im2/subs/shell.cljs +++ b/src/status_im2/subs/shell.cljs @@ -67,7 +67,7 @@ (str profile-picture "&addRing=0"))} :customization-color (or (:customization-color contact) :primary) :on-close #(re-frame/dispatch [:shell/close-switcher-card id]) - :on-press #(re-frame/dispatch [:chat/navigate-to-chat id true]) + :on-press #(re-frame/dispatch [:chat/navigate-to-chat id]) :content (get-card-content chat communities)})) (defn private-group-chat-card @@ -76,7 +76,7 @@ :avatar-params {} :customization-color (or (:customization-color chat) :primary) :on-close #(re-frame/dispatch [:shell/close-switcher-card id]) - :on-press #(re-frame/dispatch [:chat/navigate-to-chat id true]) + :on-press #(re-frame/dispatch [:chat/navigate-to-chat id]) :content (get-card-content chat communities)}) (defn community-card @@ -88,7 +88,7 @@ {:name (:name community)}) :customization-color (or (:customization-color community) :primary) :on-close #(re-frame/dispatch [:shell/close-switcher-card id]) - :on-press #(re-frame/dispatch [:navigate-to-nav2 :community-overview id true]) + :on-press #(re-frame/dispatch [:navigate-to :community-overview id]) :content {:community-info {:type :permission}}})) (defn community-channel-card @@ -98,9 +98,9 @@ {:content {:community-channel {:emoji (:emoji channel) :channel-name (str "# " (:name channel))}} :on-press (fn [] - (re-frame/dispatch [:navigate-to-nav2 :community-overview community-id true]) + (re-frame/dispatch [:navigate-to :community-overview community-id]) (js/setTimeout - #(re-frame/dispatch [:chat/navigate-to-chat channel-id true]) + #(re-frame/dispatch [:chat/navigate-to-chat channel-id]) 100))})) (re-frame/reg-sub