feat: allow navigation inside different stacks (#16419)

Signed-off-by: Brian Sztamfater <brian@status.im>
This commit is contained in:
Brian Sztamfater 2023-06-30 11:48:35 -03:00 committed by GitHub
parent 186ac482ee
commit 2d860c363a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 11 deletions

View File

@ -33,6 +33,10 @@
[comp] [comp]
(.showOverlay Navigation (clj->js comp))) (.showOverlay Navigation (clj->js comp)))
(defn pop-to
[comp]
(.popTo Navigation (clj->js comp)))
(defn pop-to-root (defn pop-to-root
[tab] [tab]
(.popToRoot Navigation (clj->js tab))) (.popToRoot Navigation (clj->js tab)))

View File

@ -54,9 +54,10 @@
(reset! state/pushed-screen-id view-id))))) (reset! state/pushed-screen-id view-id)))))
(defn dissmissModal (defn dissmissModal
[] ([] (dissmissModal nil))
([comp-id]
(reset! state/dissmissing true) (reset! state/dissmissing true)
(navigation/dismiss-modal (name (last @state/modals)))) (navigation/dismiss-modal (name (or comp-id (last @state/modals))))))
(defn dismiss-all-modals (defn dismiss-all-modals
[] []
@ -95,8 +96,24 @@
(options/merge-top-bar (options/topbar-options) options) (options/merge-top-bar (options/topbar-options) options)
{:topBar {:visible false}}))}}))) {: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 navigate)
(re-frame/reg-fx :navigate-to-within-stack navigate-to-within-stack)
(re-frame/reg-fx :navigate-replace-fx (re-frame/reg-fx :navigate-replace-fx
(fn [view-id] (fn [view-id]
(navigation/pop (name @state/root-id)) (navigation/pop (name @state/root-id))
@ -108,6 +125,14 @@
(dissmissModal) (dissmissModal)
(navigation/pop (name @state/root-id))))) (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 (defn pop-to-root
[root-id] [root-id]
(navigation/pop-to-root root-id) (navigation/pop-to-root root-id)
@ -126,14 +151,14 @@
(reset! state/curr-modal true) (reset! state/curr-modal true)
(swap! state/modals conj comp) (swap! state/modals conj comp)
(navigation/show-modal (navigation/show-modal
{:component {:stack {:children [{:component
{:name comp {:name comp
:id comp :id comp
:options (merge (options/default-root) :options (merge (options/default-root)
(options/statusbar-and-navbar) (options/statusbar-and-navbar)
options options
(when sheet? (when sheet?
options/sheet-options))}}))))) options/sheet-options))}}]}})))))
(re-frame/reg-fx :open-modal-fx open-modal) (re-frame/reg-fx :open-modal-fx open-modal)

View File

@ -21,6 +21,11 @@
:dispatch-n [[:hide-bottom-sheet]]} :dispatch-n [[:hide-bottom-sheet]]}
(shell.events/shell-navigate-to go-to-view-id screen-params nil nil))) (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 (rf/defn open-modal
{:events [:open-modal]} {:events [:open-modal]}
[{:keys [db]} comp screen-params] [{:keys [db]} comp screen-params]
@ -29,11 +34,26 @@
:dispatch [:hide-bottom-sheet] :dispatch [:hide-bottom-sheet]
:open-modal-fx comp}) :open-modal-fx comp})
(rf/defn dismiss-modal
{:events [:dismiss-modal]}
[_ comp-id]
{:dismiss-modal comp-id})
(rf/defn navigate-back (rf/defn navigate-back
{:events [:navigate-back]} {:events [:navigate-back]}
[cofx] [cofx]
(shell.events/shell-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 (rf/defn pop-to-root
{:events [:pop-to-root]} {:events [:pop-to-root]}
[{:keys [db]} tab] [{:keys [db]} tab]