Navigation code cleanup (#15196)

This commit is contained in:
Parvesh Monu 2023-02-27 15:40:11 +05:30 committed by GitHub
parent c28b34ac08
commit 69c3a72357
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 54 additions and 533 deletions

View File

@ -91,7 +91,7 @@
(i18n/label :t/use-valid-contact-code)
:yourself
(i18n/label :t/can-not-add-yourself))
:on-dismiss #(re-frame/dispatch [:pop-to-root-tab :shell-stack])}})))
:on-dismiss #(re-frame/dispatch [:pop-to-root :shell-stack])}})))
(rf/defn qr-code-scanned
{:events [:contact/qr-code-scanned]}

View File

@ -306,8 +306,8 @@
{:db (assoc db
:browser/options
{:browser-id (:browser-id browser)})}
(navigation/change-tab :browser)
(navigation/set-stack-root :browser-stack :browser)
(navigation/change-tab :browser-stack)
(navigation/pop-to-root :shell-stack)
(update-browser browser)
(resolve-url nil)))))

View File

@ -742,7 +742,7 @@
{:events [:communities/navigate-to-community]}
[cofx community-id]
(rf/merge cofx
(navigation/pop-to-root-tab :shell-stack)
(navigation/pop-to-root :shell-stack)
(navigation/navigate-to-nav2 :community community-id true)))
(rf/defn member-role-updated

View File

@ -76,7 +76,7 @@
(re-frame/dispatch [:hide-popover])))
;; reset navigation to avoid going back to non existing one to one chat
(if from-one-to-one-chat?
(navigation/pop-to-root-tab :shell-stack)
(navigation/pop-to-root :shell-stack)
(navigation/navigate-back)))))
(rf/defn contact-unblocked

View File

@ -23,7 +23,7 @@
(rf/merge cofx
{:db (dissoc (:db cofx) :current-chat-id)
:dispatch-n [[:sanitize-messages-and-process-response response]
[:pop-to-root-tab :shell-stack]]}
[:pop-to-root :shell-stack]]}
(activity-center/notifications-fetch-unread-count)))
(rf/defn handle-chat-update
@ -124,7 +124,7 @@
[cofx chat-id]
(rf/merge cofx
(chat.events/deactivate-chat chat-id)
(navigation/pop-to-root-tab :shell-stack)))
(navigation/pop-to-root :shell-stack)))
(def not-blank?
(complement string/blank?))

View File

@ -18,7 +18,8 @@
{:db (-> db
(assoc-in [:keycard :creating-backup?] backup-type))}
(when (:multiaccount db)
(navigation/change-tab :profile))
(navigation/change-tab :browser-stack)) ;; Profile tab - Currently browser tab is used for
;; profile
(navigation/navigate-to-cofx :seed-phrase nil)))
(rf/defn recovery-card-pressed

View File

@ -17,7 +17,7 @@
[{:keys [db] :as cofx}]
(rf/merge cofx
{:db db}
(navigation/pop-to-root-tab :multiaccounts-stack)))
(navigation/pop-to-root :multiaccounts-stack)))
(rf/defn login-pin-more-icon-pressed
{:events [:keycard.login.pin.ui/more-icon-pressed]}
@ -70,7 +70,7 @@
:status nil))
:hide-popover nil})
(when (:multiaccount db)
(navigation/change-tab :profile))
(navigation/change-tab :browser-stack)) ;; Profile tab - Currently browser tab is used for profile
(when-not (:multiaccounts/login db)
(if (:popover/popover db)
(navigation/navigate-replace :keycard-pin nil)

View File

@ -643,7 +643,7 @@
(assoc-in [:keycard :pin :status] nil)
(assoc-in [:keycard :pin :login] []))})
#(if keycard-account?
{:init-root-with-component-fx [:multiaccounts-keycard :multiaccounts]}
{:init-root-fx :multiaccounts-keycard}
{:init-root-fx :multiaccounts})
#(when goto-key-storage?
(navigation/navigate-to-cofx % :actions-not-logged-in nil))))))

View File

@ -55,7 +55,7 @@
(if error
{:utils/show-popup {:title (i18n/label :t/multiaccount-exists-title)
:content (i18n/label :t/multiaccount-exists-title)
:on-dismiss #(re-frame/dispatch [:pop-to-root-tab :multiaccounts])}}
:on-dismiss #(re-frame/dispatch [:pop-to-root :multiaccounts])}}
(let [{:keys [key-uid] :as multiaccount} (get-in db [:intro-wizard :root-key])
keycard-multiaccount? (boolean (get-in db
[:multiaccounts/multiaccounts key-uid
@ -123,10 +123,10 @@
:content (i18n/label :t/multiaccount-exists-content)
:confirm-button-text (i18n/label :t/unlock)
:on-accept #(do
(re-frame/dispatch [:pop-to-root-tab :multiaccounts])
(re-frame/dispatch [:pop-to-root :multiaccounts])
(re-frame/dispatch
[:multiaccounts.login.ui/multiaccount-selected key-uid]))
:on-cancel #(re-frame/dispatch [:pop-to-root-tab :multiaccounts])}})
:on-cancel #(re-frame/dispatch [:pop-to-root :multiaccounts])}})
(rf/defn on-import-multiaccount-success
{:events [::import-multiaccount-success]}

View File

@ -1,468 +0,0 @@
(ns status-im.navigation.core
(:require ["react-native" :as rn]
["react-native-gesture-handler" :refer (gestureHandlerRootHOC)]
["react-native-navigation" :refer (Navigation)]
[clojure.set :as set]
[quo.components.text-input :as quo.text-input]
[quo.design-system.colors :as quo.colors]
[re-frame.core :as re-frame]
[status-im.multiaccounts.login.core :as login-core]
[status-im.navigation.roots :as roots]
[status-im.navigation.state :as state]
[status-im.ui.components.icons.icons :as icons]
[status-im.ui.components.react :as react]
[status-im.ui.screens.views :as views]
[utils.re-frame :as rf]
[status-im.utils.platform :as platform]
[taoensso.timbre :as log]))
(def debug? ^boolean js/goog.DEBUG)
(def splash-screen (-> rn .-NativeModules .-SplashScreen))
(defonce set-navigation-default-options
(.setDefaultOptions Navigation (clj->js {:layout {:orientation "portrait"}})))
;; REGISTER COMPONENT (LAZY)
(defn reg-comp
[key]
(log/debug "reg-comp" key)
(if-let [comp (get views/components (keyword key))]
(.registerComponent Navigation key (fn [] (views/component comp)))
(let [screen (views/screen key)]
(.registerComponent Navigation key (fn [] (gestureHandlerRootHOC screen)) (fn [] screen)))))
(defonce rset-lazy-reg
(.setLazyComponentRegistrator Navigation reg-comp))
(defn dismiss-all-modals
[]
(log/debug "dissmiss-all-modals")
(when @state/curr-modal
(reset! state/curr-modal false)
(reset! state/dissmissing true)
(doseq [modal @state/modals]
(.dismissModal Navigation (name modal)))
(reset! state/modals [])))
;; PUSH SCREEN
(defn navigate
[comp]
(log/debug "NAVIGATE" comp)
(let [{:keys [options]} (get views/screens comp)]
(.push Navigation
(name @state/root-comp-id)
(clj->js
{:component {:id comp
:name comp
:options (merge options
(roots/status-bar-options)
(roots/merge-top-bar (roots/topbar-options) options))}}))
;;if we push the screen from modal, we want to dismiss all modals
(dismiss-all-modals)))
;; OPEN MODAL
(defn update-modal-topbar-options
[options]
(log/debug "update-modal-topbar-options" options)
(merge options
(roots/merge-top-bar {:elevation 0
:noBorder true
:title {:color quo.colors/black}
:background {:color quo.colors/white}
:leftButtonColor quo.colors/black
:leftButtons {:id "dismiss-modal"
:icon (icons/icon-source :main-icons/close)}}
options)))
(defn open-modal
[comp]
(log/debug "open-modal" comp)
(let [{:keys [options]} (get views/screens comp)]
(if @state/dissmissing
(reset! state/dissmissing comp)
(do
(reset! state/curr-modal true)
(swap! state/modals conj comp)
(.showModal Navigation
(clj->js {:stack {:children
[{:component
{:name comp
:id comp
:options (update-modal-topbar-options
(merge (roots/status-bar-options)
(roots/default-root)
options))}}]}}))))))
(re-frame/reg-fx :open-modal-fx open-modal)
;; DISSMISS MODAL
(defn dissmissModal
[]
(log/debug "dissmissModal")
(reset! state/dissmissing true)
(.dismissModal Navigation (name (last @state/modals))))
(defonce register-nav-button-reg
(.registerNavigationButtonPressedListener
(.events Navigation)
(fn [^js evn]
(let [id (.-buttonId evn)]
(if (= "dismiss-modal" id)
(do
(when-let [event (get-in views/screens [(last @state/modals) :on-dissmiss])]
(re-frame/dispatch event))
(dissmissModal))
(when-let [handler (get-in views/screens [(keyword id) :right-handler])]
(handler)))))))
(defn set-view-id
[view-id]
(log/debug "set-view-id" view-id)
(when-let [{:keys [on-focus]} (get views/screens view-id)]
(re-frame/dispatch [:set-view-id view-id])
(re-frame/dispatch [:screens/on-will-focus view-id])
(when on-focus
(re-frame/dispatch on-focus))))
(defonce register-modal-reg
(.registerModalDismissedListener
(.events Navigation)
(fn [_]
(if (> (count @state/modals) 1)
(let [new-modals (butlast @state/modals)]
(reset! state/modals (vec new-modals))
(set-view-id (last new-modals)))
(do
(reset! state/modals [])
(reset! state/curr-modal false)
(set-view-id @state/pushed-screen-id)))
(let [comp @state/dissmissing]
(reset! state/dissmissing false)
(when (keyword? comp)
(open-modal comp))))))
;; SCREEN DID APPEAR
(defonce screen-appear-reg
(.registerComponentDidAppearListener
(.events Navigation)
(fn [^js evn]
(let [view-id (keyword (.-componentName evn))]
(log/debug "screen-appear-reg" view-id)
(when (get views/screens view-id)
(when (and (not= view-id :bottom-sheet)
(not= view-id :popover)
(not= view-id :visibility-status-popover))
(set-view-id view-id)
(when-not @state/curr-modal
(reset! state/pushed-screen-id view-id))))))))
;; SCREEN DID DISAPPEAR
(defonce screen-disappear-reg
(.registerComponentDidDisappearListener
(.events Navigation)
(fn [^js evn]
(let [view-id (keyword (.-componentName evn))]
(when-not (#{"popover" "bottom-sheet" "signing-sheet" "visibility-status-popover"
"wallet-connect-sheet" "wallet-connect-success-sheet"
"wallet-connect-app-management-sheet"}
(.-componentName evn))
(re-frame/dispatch [::view-disappeared view-id])
(doseq [[_ {:keys [ref value]}] @quo.text-input/text-input-refs]
(.setNativeProps ^js ref (clj->js {:text value})))
(doseq [[^js text-input default-value] @react/text-input-refs]
(.setNativeProps text-input (clj->js {:text default-value}))))))))
;; SET ROOT
(re-frame/reg-fx
:init-root-fx
(fn [new-root-id]
(log/debug :init-root-fx new-root-id)
(reset! state/root-comp-id new-root-id)
(reset! state/root-id @state/root-comp-id)
(.setRoot Navigation (clj->js (get (roots/roots) new-root-id)))))
(re-frame/reg-fx
:init-root-with-component-fx
(fn [[new-root-id new-root-comp-id]]
(log/debug :init-root-with-component-fx new-root-id new-root-comp-id)
(reset! state/root-comp-id new-root-comp-id)
(reset! state/root-id @state/root-comp-id)
(.setRoot Navigation (clj->js (get (roots/roots) new-root-id)))))
(rf/defn set-multiaccount-root
{:events [::set-multiaccount-root]}
[{:keys [db]}]
(log/debug :set-multiaccounts-root)
(let [key-uid (get-in db [:multiaccounts/login :key-uid])
keycard-account? (boolean (get-in db
[:multiaccounts/multiaccounts
key-uid
:keycard-pairing]))]
{:init-root-fx (if keycard-account? :multiaccounts-keycard :multiaccounts)}))
(defonce
rset-app-launched
(.registerAppLaunchedListener (.events Navigation)
(fn []
(reset! state/curr-modal false)
(reset! state/dissmissing false)
(if (or (= @state/root-id :multiaccounts)
(= @state/root-id :multiaccounts-keycard))
(re-frame/dispatch-sync [::set-multiaccount-root])
(when @state/root-id
(reset! state/root-comp-id @state/root-id)
(.setRoot Navigation (clj->js (get (roots/roots) @state/root-id)))
(re-frame/dispatch [::login-core/check-last-chat])))
(.hide ^js splash-screen))))
(defn get-screen-component
[comp]
(log/debug :get-screen-component comp)
(let [{:keys [options]} (get views/screens comp)]
{:component {:id comp
:name comp
:options (merge options
(roots/status-bar-options)
(roots/merge-top-bar (roots/topbar-options) options))}}))
;; SET STACK ROOT
(re-frame/reg-fx
:set-stack-root-fx
(fn [[stack comp]]
(log/debug :set-stack-root-fx stack comp)
(.setStackRoot Navigation
(name stack)
(clj->js (if (vector? comp)
(mapv get-screen-component comp)
(get-screen-component comp))))))
;; BOTTOM TABS
(def tab-root-ids
{0 :chat-stack
1 :browser-stack
2 :wallet-stack
3 :status-stack
4 :profile-stack})
(def tab-key-idx
{:chat 0
:browser 1
:wallet 2
:status 3
:profile 4})
(re-frame/reg-fx
:change-tab-fx
(fn [tab]
(log/debug :change-tab-fx)
(reset! state/root-comp-id (get tab-root-ids (get tab-key-idx tab)))
(.mergeOptions Navigation
"tabs-stack"
(clj->js {:bottomTabs {:currentTabIndex (get tab-key-idx tab)}}))
;;when we change tab we want to dismiss all modals
(dismiss-all-modals)))
;issue on ios https://github.com/wix/react-native-navigation/issues/7146
(re-frame/reg-fx
:change-tab-count-fx
(fn [[tab cnt]]
(log/debug :change-tab-count-fx tab cnt)
(.mergeOptions
Navigation
(name (get tab-root-ids (get tab-key-idx tab)))
(clj->js {:bottomTab (cond
(or (pos? cnt) (pos? (:other cnt)))
(if (and (= :chat tab) platform/ios?)
{:dotIndicator {:visible true}}
{:badge (str (or (:other cnt) cnt)) :dotIndicator {:visible false}})
(pos? (:public cnt))
(if platform/ios?
{:dotIndicator {:visible true}}
{:badge nil :dotIndicator {:visible true}})
:else
(if (and (= :chat tab) platform/ios?)
{:dotIndicator {:visible false}}
{:dotIndicator {:visible false} :badge ""}))}))))
(re-frame/reg-fx
:pop-to-root-tab-fx
(fn [comp]
(log/debug :pop-to-root-tab-fx comp)
(dismiss-all-modals)
(.popToRoot Navigation (name comp))))
(defonce register-bottom-tab-reg
(.registerBottomTabSelectedListener
(.events Navigation)
(fn [^js evn]
(let [selected-tab-index (.-selectedTabIndex evn)
comp (get tab-root-ids selected-tab-index)
tab-key (get (set/map-invert tab-key-idx) selected-tab-index)]
(re-frame/dispatch [:set :current-tab tab-key])
(when (= @state/root-comp-id comp)
(when (= :chat tab-key)
(re-frame/dispatch [:chat/close]))
(when platform/android?
(.popToRoot Navigation (name comp))))
(reset! state/root-comp-id comp)))))
;; OVERLAY (Popover and bottom sheets)
(defn dissmiss-overlay
[comp]
(.catch (.dismissOverlay Navigation comp) #()))
(defn show-overlay
[comp]
(dissmiss-overlay comp)
(.showOverlay
Navigation
(clj->js
{:component {:name comp
:id comp
:options (merge (cond-> (roots/status-bar-options)
(and platform/android? (not (quo.colors/dark?)))
(assoc-in [:statusBar :backgroundColor] "#99999A"))
{:layout {:componentBackgroundColor (if platform/android?
(:backdrop @quo.colors/theme)
"transparent")}
:overlay {:interceptTouchOutside true}})}})))
;; POPOVER
(defonce popover-reg
(.registerComponent Navigation
"popover"
(fn [] (gestureHandlerRootHOC views/popover-comp))
(fn [] views/popover-comp)))
(re-frame/reg-fx :show-popover (fn [] (show-overlay "popover")))
(re-frame/reg-fx :hide-popover (fn [] (dissmiss-overlay "popover")))
;; VISIBILITY STATUS POPOVER
(defonce visibility-status-popover-reg
(.registerComponent Navigation
"visibility-status-popover"
(fn [] (gestureHandlerRootHOC views/visibility-status-popover-comp))
(fn [] views/visibility-status-popover-comp)))
(re-frame/reg-fx :show-visibility-status-popover
(fn [] (show-overlay "visibility-status-popover")))
(re-frame/reg-fx :hide-visibility-status-popover
(fn [] (dissmiss-overlay "visibility-status-popover")))
;; BOTTOM SHEETS
(defonce bottom-sheet-reg
(.registerComponent Navigation
"bottom-sheet"
(fn [] (gestureHandlerRootHOC views/sheet-comp))
(fn [] views/sheet-comp)))
(re-frame/reg-fx :show-bottom-sheet-overlay (fn [] (show-overlay "bottom-sheet")))
(re-frame/reg-fx :dismiss-bottom-sheet-overlay (fn [] (dissmiss-overlay "bottom-sheet")))
;; WALLET CONNECT
(defonce wallet-connect-sheet-reg
(.registerComponent Navigation
"wallet-connect-sheet"
(fn [] (gestureHandlerRootHOC views/wallet-connect-comp))
(fn [] views/wallet-connect-comp)))
(defonce wallet-connect-success-sheet-reg
(.registerComponent Navigation
"wallet-connect-success-sheet"
(fn [] (gestureHandlerRootHOC views/wallet-connect-success-comp))
(fn [] views/wallet-connect-success-comp)))
(defonce wallet-connect-app-management-sheet-reg
(.registerComponent Navigation
"wallet-connect-app-management-sheet"
(fn [] (gestureHandlerRootHOC views/wallet-connect-app-management-comp))
(fn [] views/wallet-connect-app-management-comp)))
(re-frame/reg-fx :show-wallet-connect-sheet (fn [] (show-overlay "wallet-connect-sheet")))
(re-frame/reg-fx :hide-wallet-connect-sheet (fn [] (dissmiss-overlay "wallet-connect-sheet")))
(re-frame/reg-fx :show-wallet-connect-success-sheet
(fn [] (show-overlay "wallet-connect-success-sheet")))
(re-frame/reg-fx :hide-wallet-connect-success-sheet
(fn [] (dissmiss-overlay "wallet-connect-success-sheet")))
(re-frame/reg-fx :show-wallet-connect-app-management-sheet
(fn [] (show-overlay "wallet-connect-app-management-sheet")))
(re-frame/reg-fx :hide-wallet-connect-app-management-sheet
(fn [] (dissmiss-overlay "wallet-connect-app-management-sheet")))
;; SIGNING
(defonce signing-sheet-reg
(.registerComponent Navigation
"signing-sheet"
(fn [] (gestureHandlerRootHOC views/signing-comp))
(fn [] views/signing-comp)))
(re-frame/reg-fx :show-signing-sheet (fn [] (show-overlay "signing-sheet")))
(re-frame/reg-fx :hide-signing-sheet (fn [] (dissmiss-overlay "signing-sheet")))
;; Select account
;; TODO why is this not a regular bottom sheet ?
(defonce select-acc-sheet-reg
(.registerComponent Navigation
"select-acc-sheet"
(fn [] (gestureHandlerRootHOC views/select-acc-comp))
(fn [] views/select-acc-comp)))
(re-frame/reg-fx :show-select-acc-sheet (fn [] (show-overlay "select-acc-sheet")))
(re-frame/reg-fx :hide-select-acc-sheet (fn [] (dissmiss-overlay "select-acc-sheet")))
;; NAVIGATION
(re-frame/reg-fx
:navigate-to-fx
(fn [key]
(log/debug :navigate-to-fx key)
(navigate key)))
(re-frame/reg-fx
:navigate-back-fx
(fn []
(log/debug :navigate-back-fx)
(if @state/curr-modal
(dissmissModal)
(.pop Navigation (name @state/root-comp-id)))))
(re-frame/reg-fx
:navigate-replace-fx
(fn [view-id]
(log/debug :navigate-replace-fx view-id)
(.pop Navigation (name @state/root-comp-id))
(navigate view-id)))
(def community-screens
'(:community-management
:community-members
:community-requests-to-join
:create-community-channel
:community-emoji-thumbnail-picker
:create-community-category
:community-edit-chats
:community-edit
:community-reorder-categories))
;; change view-id if it is still same after component is disappeared
;; https://github.com/wix/react-native-navigation/issues/5744#issuecomment-563226820
(rf/defn view-disappeared
{:events [::view-disappeared]}
[{:keys [db]} view-id]
(when (= view-id (:view-id db))
{:db (assoc db
:view-id
(cond
(= view-id :community-emoji-thumbnail-picker)
:create-community-channel
(some #(= view-id %) community-screens)
:community
:else
:home))}))

View File

@ -65,8 +65,8 @@
(let [own (new-chat.db/own-public-key? db public-key)]
(cond
(and public-key own)
{:change-tab-fx :profile
:pop-to-root-tab-fx :profile-stack}
{:shell/change-tab-fx :browser-stack ;; Profile tab - Currently browser tab is used for profile
:pop-to-root-fx :shell-stack}
(and public-key (not own))
(rf/merge cofx
@ -76,14 +76,14 @@
:else
{:utils/show-popup {:title (i18n/label :t/unable-to-read-this-code)
:content (i18n/label :t/ens-name-not-found)
:on-dismiss #(re-frame/dispatch [:pop-to-root-tab :shell-stack])}})))
:on-dismiss #(re-frame/dispatch [:pop-to-root :shell-stack])}})))
(rf/defn handle-eip681
[cofx data]
(rf/merge cofx
{:dispatch [:wallet/parse-eip681-uri-and-resolve-ens data]}
(navigation/change-tab :wallet)
(navigation/pop-to-root-tab :wallet-stack)))
(navigation/change-tab :wallet-stack)
(navigation/pop-to-root :shell-stack)))
(rf/defn handle-wallet-connect
{:events [::handle-wallet-connect-uri]}
@ -116,7 +116,7 @@
:event ::match-scanned-value})
{:dispatch [:navigate-back]
:utils/show-popup {:title (i18n/label :t/unable-to-read-this-code)
:on-dismiss #(re-frame/dispatch [:pop-to-root-tab :shell-stack])}})))
:on-dismiss #(re-frame/dispatch [:pop-to-root :shell-stack])}})))
(rf/defn on-scan
{:events [::on-scan-success]}

View File

@ -109,8 +109,8 @@
(log/info "universal-links: handling view profile" public-key)
(cond
(and public-key (new-chat.db/own-public-key? db public-key))
{:change-tab-fx :profile
:pop-to-root-tab-fx :profile-stack}
{:shell/change-tab-fx :browser-stack ;; Profile tab - Currently browser tab is used for profile
:pop-to-root-fx :shell-stack}
public-key
{:dispatch [:chat.ui/show-profile public-key ens-name]}))

View File

@ -311,7 +311,7 @@
:db (-> db
(assoc :multiaccount/accounts new-accounts)
(update-in [:wallet :accounts] dissoc deleted-address))}
(navigation/pop-to-root-tab :wallet-stack))))
(navigation/pop-to-root :shell-stack))))
(rf/defn delete-account-key
{:events [:wallet.accounts/delete-key]}

View File

@ -204,7 +204,7 @@
(rf/merge cofx
{:dispatch [:navigate-to-nav2 :chat chat-id from-shell?]}
(when-not (or (= (:view-id db) :community) (= (:view-id db) :community-overview))
(navigation/pop-to-root-tab :shell-stack))
(navigation/pop-to-root :shell-stack))
(close-chat false)
(force-close-chat chat-id)
(fn [{:keys [db]}]

View File

@ -175,7 +175,7 @@
(defn bottom-tab-on-press
[stack-id]
(when-not (= stack-id @selected-stack-id)
(when (and @shared-values-atom (not= stack-id @selected-stack-id))
(let [stack-load-delay (if (home-stack-open?)
0
shell.constants/shell-animation-time)]

View File

@ -11,6 +11,12 @@
;; Effects
(re-frame/reg-fx
:shell/change-tab-fx
(fn [stack-id]
(when (some #(= stack-id %) shell.constants/stacks-ids)
(animation/bottom-tab-on-press stack-id))))
(re-frame/reg-fx
:shell/navigate-to-jump-to-fx
(fn []
@ -110,4 +116,4 @@
(rf/merge
cofx
{:shell/navigate-to-jump-to-fx nil}
(navigation/pop-to-root-tab :shell-stack)))
(navigation/pop-to-root :shell-stack)))

View File

@ -52,7 +52,7 @@
(log/debug "NAVIGATE" comp)
(let [{:keys [options]} (get views/screens comp)]
(navigation/push
(name @state/root-comp-id)
(name @state/root-id)
{:component {:id comp
:name comp
:options (merge (status-bar-options)
@ -181,7 +181,6 @@
(= @state/root-id :multiaccounts-keycard))
(re-frame/dispatch-sync [::set-multiaccount-root])
(when @state/root-id
(reset! state/root-comp-id @state/root-id)
(navigation/set-root (get (roots/roots) @state/root-id))
(re-frame/dispatch [::login-core/check-last-chat])))
(rn/hide-splash-screen))
@ -192,17 +191,7 @@
(fn [new-root-id]
(log/debug :init-root-fx new-root-id)
(dismiss-all-modals)
(reset! state/root-comp-id new-root-id)
(reset! state/root-id @state/root-comp-id)
(navigation/set-root (get (roots/roots) new-root-id))))
(re-frame/reg-fx
:init-root-with-component-fx
(fn [[new-root-id new-root-comp-id]]
(log/debug :init-root-with-component-fx new-root-id new-root-comp-id)
(dismiss-all-modals)
(reset! state/root-comp-id new-root-comp-id)
(reset! state/root-id @state/root-comp-id)
(reset! state/root-id new-root-id)
(navigation/set-root (get (roots/roots) new-root-id))))
(rf/defn set-multiaccount-root
@ -230,12 +219,17 @@
(re-frame/reg-fx
:set-stack-root-fx
(fn [[stack comp]]
(log/debug :set-stack-root-fx stack comp)
(navigation/set-stack-root
(name stack)
(if (vector? comp)
(mapv get-screen-component comp)
(get-screen-component comp)))))
;; We don't have bottom tabs as separate stacks anymore,
;; So the old way of pushing screens in specific tabs will not work.
;; Disabled set-stack-root for :shell-stack as it is not working and
;; currently only being used for browser and some rare keycard flows after login
(when-not (= @state/root-id :shell-stack)
(log/debug :set-stack-root-fx stack comp)
(navigation/set-stack-root
(name stack)
(if (vector? comp)
(mapv get-screen-component comp)
(get-screen-component comp))))))
;; OVERLAY (Popover and bottom sheets)
(def dissmiss-overlay navigation/dissmiss-overlay)
@ -369,13 +363,13 @@
(log/debug :navigate-back-fx)
(if @state/curr-modal
(dissmissModal)
(navigation/pop (name @state/root-comp-id)))))
(navigation/pop (name @state/root-id)))))
(re-frame/reg-fx
:navigate-replace-fx
(fn [view-id]
(log/debug :navigate-replace-fx view-id)
(navigation/pop (name @state/root-comp-id))
(navigation/pop (name @state/root-id))
(navigate view-id)))
;; NAVIGATION 2
@ -391,6 +385,6 @@
(navigation/merge-options "shell-stack" {:navigationBar {:backgroundColor color}})))
(re-frame/reg-fx
:pop-to-root-tab-fx
:pop-to-root-fx
(fn [tab]
(navigation/pop-to-root tab)))

View File

@ -27,10 +27,10 @@
[_]
{:navigate-back-fx nil})
(rf/defn pop-to-root-tab
{:events [:pop-to-root-tab]}
(rf/defn pop-to-root
{:events [:pop-to-root]}
[_ tab]
{:pop-to-root-tab-fx tab})
{:pop-to-root-fx tab})
(rf/defn set-stack-root
{:events [:set-stack-root]}
@ -39,9 +39,8 @@
(rf/defn change-tab
{:events [:navigate-change-tab]}
[_ tab])
;{:change-tab-fx tab} ; TODO: effect needs to be implemented (may not be possible:
;https://github.com/wix/react-native-navigation/issues/4837)
[_ stack-id]
{:shell/change-tab-fx stack-id})
(rf/defn navigate-replace
{:events [:navigate-replace]}
@ -64,16 +63,6 @@
[_ root-id]
{:init-root-fx root-id})
(rf/defn init-root-with-component
{:events [:init-root-with-component]}
[_ root-id comp-id]
{:init-root-with-component-fx [root-id comp-id]})
(rf/defn change-tab-count
{:events [:change-tab-count]}
[_ tab cnt]
{:change-tab-count-fx [tab cnt]})
(rf/defn hide-signing-sheet
{:events [:hide-signing-sheet]}
[_]

View File

@ -1,6 +1,5 @@
(ns status-im2.navigation.state)
(defonce root-comp-id (atom nil))
(defonce root-id (atom nil))
(defonce pushed-screen-id (atom nil))
(defonce curr-modal (atom nil))