From 2d860c363a6825c06987934de7c28584e09a1b04 Mon Sep 17 00:00:00 2001 From: Brian Sztamfater Date: Fri, 30 Jun 2023 11:48:35 -0300 Subject: [PATCH] feat: allow navigation inside different stacks (#16419) Signed-off-by: Brian Sztamfater --- src/react_native/navigation.cljs | 4 +++ src/status_im2/navigation/core.cljs | 47 ++++++++++++++++++++------- src/status_im2/navigation/events.cljs | 20 ++++++++++++ 3 files changed, 60 insertions(+), 11 deletions(-) diff --git a/src/react_native/navigation.cljs b/src/react_native/navigation.cljs index a41dfd05c9..fbce207798 100644 --- a/src/react_native/navigation.cljs +++ b/src/react_native/navigation.cljs @@ -33,6 +33,10 @@ [comp] (.showOverlay Navigation (clj->js comp))) +(defn pop-to + [comp] + (.popTo Navigation (clj->js comp))) + (defn pop-to-root [tab] (.popToRoot Navigation (clj->js tab))) diff --git a/src/status_im2/navigation/core.cljs b/src/status_im2/navigation/core.cljs index 755eae6ad9..1a9c7095a8 100644 --- a/src/status_im2/navigation/core.cljs +++ b/src/status_im2/navigation/core.cljs @@ -54,9 +54,10 @@ (reset! state/pushed-screen-id view-id))))) (defn dissmissModal - [] - (reset! state/dissmissing true) - (navigation/dismiss-modal (name (last @state/modals)))) + ([] (dissmissModal nil)) + ([comp-id] + (reset! state/dissmissing true) + (navigation/dismiss-modal (name (or comp-id (last @state/modals)))))) (defn dismiss-all-modals [] @@ -95,8 +96,24 @@ (options/merge-top-bar (options/topbar-options) options) {:topBar {:visible false}}))}}))) +;; NAVIGATE-TO-WITHIN-STACK +(defn navigate-to-within-stack + [[comp comp-id]] + (let [{:keys [options]} (get views/screens comp)] + (navigation/push + (name comp-id) + {:component {:id comp + :name comp + :options (merge (options/statusbar-and-navbar) + options + (if (:topBar options) + (options/merge-top-bar (options/topbar-options) options) + {:topBar {:visible false}}))}}))) + (re-frame/reg-fx :navigate-to navigate) +(re-frame/reg-fx :navigate-to-within-stack navigate-to-within-stack) + (re-frame/reg-fx :navigate-replace-fx (fn [view-id] (navigation/pop (name @state/root-id)) @@ -108,6 +125,14 @@ (dissmissModal) (navigation/pop (name @state/root-id))))) +(re-frame/reg-fx :navigate-back-within-stack + (fn [comp-id] + (navigation/pop (name comp-id)))) + +(re-frame/reg-fx :navigate-back-to + (fn [comp-id] + (navigation/pop-to (name comp-id)))) + (defn pop-to-root [root-id] (navigation/pop-to-root root-id) @@ -126,14 +151,14 @@ (reset! state/curr-modal true) (swap! state/modals conj comp) (navigation/show-modal - {:component - {:name comp - :id comp - :options (merge (options/default-root) - (options/statusbar-and-navbar) - options - (when sheet? - options/sheet-options))}}))))) + {:stack {:children [{:component + {:name comp + :id comp + :options (merge (options/default-root) + (options/statusbar-and-navbar) + options + (when sheet? + options/sheet-options))}}]}}))))) (re-frame/reg-fx :open-modal-fx open-modal) diff --git a/src/status_im2/navigation/events.cljs b/src/status_im2/navigation/events.cljs index 9060e0e530..7b96d02973 100644 --- a/src/status_im2/navigation/events.cljs +++ b/src/status_im2/navigation/events.cljs @@ -21,6 +21,11 @@ :dispatch-n [[:hide-bottom-sheet]]} (shell.events/shell-navigate-to go-to-view-id screen-params nil nil))) +(rf/defn navigate-to-within-stack + {:events [:navigate-to-within-stack]} + [_ comp-id] + {:navigate-to-within-stack comp-id}) + (rf/defn open-modal {:events [:open-modal]} [{:keys [db]} comp screen-params] @@ -29,11 +34,26 @@ :dispatch [:hide-bottom-sheet] :open-modal-fx comp}) +(rf/defn dismiss-modal + {:events [:dismiss-modal]} + [_ comp-id] + {:dismiss-modal comp-id}) + (rf/defn navigate-back {:events [:navigate-back]} [cofx] (shell.events/shell-navigate-back cofx)) +(rf/defn navigate-back-within-stack + {:events [:navigate-back-within-stack]} + [_ comp-id] + {:navigate-back-within-stack comp-id}) + +(rf/defn navigate-back-to + {:events [:navigate-back-to]} + [_ comp-id] + {:navigate-back-to comp-id}) + (rf/defn pop-to-root {:events [:pop-to-root]} [{:keys [db]} tab]