Disable shell navigation

Signed-off-by: Parvesh Monu <parvesh.dhullmonu@gmail.com>
This commit is contained in:
Parvesh Monu 2023-06-14 17:33:50 +05:30
parent bcc20c7458
commit ca2fc61061
No known key found for this signature in database
GPG Key ID: F399696520817DE9
8 changed files with 96 additions and 41 deletions

View File

@ -163,3 +163,5 @@
["enrtree://AOGECG2SPND25EEFMAJ5WF3KSGJNSGV356DSTL2YVLLZWIV6SAYBM@test.waku.nodes.status.im"]})
(def default-kdf-iterations 3200)
(def shell-navigation-disabled? true)

View File

@ -3,6 +3,7 @@
[utils.i18n :as i18n]
[utils.re-frame :as rf]
[taoensso.timbre :as log]
[status-im2.config :as config]
[status-im2.contexts.chat.messages.list.state :as chat.state]
[status-im2.contexts.chat.messages.delete-message-for-me.events :as delete-for-me]
[status-im2.contexts.chat.messages.delete-message.events :as delete-message]
@ -168,7 +169,16 @@
(when-let [chat-id (:current-chat-id db)]
(chat.state/reset-visible-item)
(rf/merge cofx
{:db (dissoc db :current-chat-id)}
(merge
{:db (dissoc db :current-chat-id)}
(let [community-id (get-in db [:chats chat-id :community-id])]
;; When navigating back from community chat to community, update switcher card
;; A close chat event is also called while opening any chat.
;; That might lead to duplicate :dispatch keys in fx/merge, that's why dispatch-n is
;; used here.
(when (and community-id config/shell-navigation-disabled? (not navigate-to-shell?))
{:dispatch-n [[:shell/add-switcher-card
:community-overview community-id]]})))
(link-preview/reset-all)
(delete-for-me/sync-all)
(delete-message/send-all)

View File

@ -329,8 +329,7 @@
[keyboard-shown keyboard-height])
[rn/keyboard-avoiding-view
{:style (style/keyboard-avoiding-container insets)
:keyboard-vertical-offset (- (:bottom insets))
:behavior :height}
:keyboard-vertical-offset (- (:bottom insets))}
(when header-comp
[header-comp {:scroll-y scroll-y}])

View File

@ -3,6 +3,7 @@
[utils.i18n :as i18n]
[quo2.core :as quo]
[utils.re-frame :as rf]
[status-im2.config :as config]
[quo2.foundations.colors :as colors]
[react-native.core :as rn]
[react-native.fast-image :as fast-image]
@ -183,19 +184,27 @@
"")))
(defn open-screen
[card-type id]
[card-type id channel-id]
(cond
(#{shell.constants/one-to-one-chat-card
shell.constants/private-group-chat-card
shell.constants/community-channel-card}
shell.constants/private-group-chat-card}
card-type)
(rf/dispatch [:chat/navigate-to-chat id])
(= card-type shell.constants/community-channel-card)
(if config/shell-navigation-disabled?
(do
(rf/dispatch [:navigate-to :community-overview id])
(js/setTimeout
#(rf/dispatch [:chat/navigate-to-chat channel-id])
100))
(rf/dispatch [:chat/navigate-to-chat channel-id]))
(= card-type shell.constants/community-card)
(rf/dispatch [:navigate-to :community-overview id])))
(defn calculate-card-position-and-open-screen
[card-ref card-type id]
[card-ref card-type id channel-id]
(when @card-ref
(.measure
^js
@ -205,7 +214,7 @@
page-x
page-y
card-type)
(open-screen card-type id)))))
(open-screen card-type id channel-id)))))
;; Screens Card
(defn screens-card
@ -219,7 +228,8 @@
{:on-press #(calculate-card-position-and-open-screen
card-ref
type
(or channel-id id))
id
channel-id)
:ref #(reset! card-ref %)
:active-opacity 1}
[rn/view {:style (style/base-container color-50)}

View File

@ -1,6 +1,7 @@
(ns status-im2.contexts.shell.events
(:require [utils.re-frame :as rf]
[re-frame.core :as re-frame]
[status-im2.config :as config]
[status-im.utils.core :as utils]
[status-im2.constants :as constants]
[status-im2.contexts.shell.state :as state]
@ -23,8 +24,9 @@
:shell/navigate-to-jump-to-fx
(fn []
(animation/close-home-stack false)
(some-> ^js @state/jump-to-list-ref
(.scrollToOffset #js {:y 0 :animated false}))))
(when-not config/shell-navigation-disabled?
(some-> ^js @state/jump-to-list-ref
(.scrollToOffset #js {:y 0 :animated false})))))
(re-frame/reg-fx
:shell/pop-to-root-fx
@ -87,14 +89,24 @@
{:events [:shell/add-switcher-card]}
[{:keys [db now] :as cofx} view-id id]
(let [card-data (calculate-card-data db now view-id id)
switcher-card (:switcher-card card-data)]
switcher-card (:switcher-card card-data)
card-type (:type switcher-card)]
(when card-data
(rf/merge
cofx
{:db (assoc-in
db
[:shell/switcher-cards (:card-id card-data)]
switcher-card)}
(merge
{:db (assoc-in
db
[:shell/switcher-cards (:card-id card-data)]
switcher-card)}
(when config/shell-navigation-disabled?
{:shell/change-tab-fx (cond
(#{shell.constants/one-to-one-chat-card
shell.constants/private-group-chat-card}
card-type)
:chats-stack
:else :communities-stack)}))
(switcher-cards-store/upsert-switcher-card-rpc switcher-card)))))
(rf/defn close-switcher-card
@ -111,23 +123,26 @@
[{:keys [db]}]
(let [chat-screen-open? (shell.utils/floating-screen-open? shell.constants/chat-screen)
community-screen-open? (shell.utils/floating-screen-open? shell.constants/community-screen)]
{:db
(cond-> db
(merge
(if config/shell-navigation-disabled?
{:pop-to-root-fx :shell-stack}
{:db
(cond-> db
chat-screen-open?
(assoc-in [:shell/floating-screens shell.constants/chat-screen :animation]
shell.constants/close-screen-with-shell-animation)
chat-screen-open?
(assoc-in [:shell/floating-screens shell.constants/chat-screen :animation]
shell.constants/close-screen-with-shell-animation)
(and chat-screen-open? community-screen-open?)
(assoc-in [:shell/floating-screens shell.constants/community-screen :animation]
shell.constants/close-screen-without-animation)
(and chat-screen-open? community-screen-open?)
(assoc-in [:shell/floating-screens shell.constants/community-screen :animation]
shell.constants/close-screen-without-animation)
(and (not chat-screen-open?) community-screen-open?)
(assoc-in [:shell/floating-screens shell.constants/community-screen :animation]
shell.constants/close-screen-with-shell-animation))
(and (not chat-screen-open?) community-screen-open?)
(assoc-in [:shell/floating-screens shell.constants/community-screen :animation]
shell.constants/close-screen-with-shell-animation))
:dispatch [:set-view-id :shell]
:shell/navigate-to-jump-to-fx nil}))
:dispatch [:set-view-id :shell]})
{:shell/navigate-to-jump-to-fx nil})))
(rf/defn change-shell-status-bar-style
{:events [:change-shell-status-bar-style]}
@ -163,8 +178,15 @@
(not hidden-screen?)
(:current-chat-id db))
(conj [:chat/close]))})
{:db (assoc db :view-id go-to-view-id)
:navigate-to go-to-view-id}))
(merge
{:db (assoc db :view-id go-to-view-id)
:navigate-to go-to-view-id}
(when (and config/shell-navigation-disabled?
(#{: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 shell-navigate-back
{:events [:shell/navigate-back]}

View File

@ -1,6 +1,7 @@
(ns status-im2.contexts.shell.utils
(:require [utils.re-frame :as rf]
[react-native.core :as rn]
[status-im2.config :as config]
[quo2.foundations.colors :as colors]
[react-native.platform :as platform]
[react-native.safe-area :as safe-area]
@ -95,7 +96,8 @@
;;; Navigation
(defn shell-navigation?
[view-id]
(#{:chat :community-overview} view-id))
(when-not config/shell-navigation-disabled?
(#{:chat :community-overview} view-id)))
(defn calculate-view-id
[]

View File

@ -1,8 +1,10 @@
(ns status-im2.contexts.shell.view
(:require [quo2.core :as quo]
(:require [re-frame.db]
[quo2.core :as quo]
[utils.i18n :as i18n]
[utils.re-frame :as rf]
[react-native.core :as rn]
[status-im2.config :as config]
[status-im2.contexts.shell.utils :as utils]
[status-im2.navigation.state :as navigation.state]
[status-im2.contexts.shell.animation :as animation]
@ -15,13 +17,18 @@
(defn navigate-back-handler
[]
(if (and (not @navigation.state/curr-modal)
(or
(utils/floating-screen-open? shell.constants/community-screen)
(utils/floating-screen-open? shell.constants/chat-screen)))
(do (rf/dispatch [:navigate-back])
(let [chat-screen-open? (and config/shell-navigation-disabled?
(= (get @re-frame.db/app-db :view-id) :chat))]
(if (and (not @navigation.state/curr-modal)
(or
chat-screen-open?
(utils/floating-screen-open? shell.constants/community-screen)
(utils/floating-screen-open? shell.constants/chat-screen)))
(do
(when chat-screen-open? (rf/dispatch [:chat/close]))
(rf/dispatch [:navigate-back])
true)
false))
false)))
(defn f-shell-stack
[]
@ -47,7 +54,8 @@
{:position :absolute
:bottom (+ (utils/bottom-tabs-container-height) 12)}
(:home-stack-opacity shared-values)]
[floating-screens/view]]))
(when-not config/shell-navigation-disabled?
[floating-screens/view])]))
(defn shell-stack
[]

View File

@ -1,6 +1,7 @@
(ns status-im2.subs.shell
(:require [re-frame.core :as re-frame]
[utils.datetime :as datetime]
[status-im2.config :as config]
[status-im2.constants :as constants]
[react-native.platform :as platform]
[status-im2.common.resources :as resources]
@ -202,7 +203,8 @@
:shell/animation-complete?
:<- [:shell/loaded-screens]
(fn [screens [_ chat-type]]
(or platform/ios?
(or config/shell-navigation-disabled?
platform/ios?
(cond-> (get screens shell.constants/chat-screen)
(= chat-type constants/community-chat-type)
(and (get screens shell.constants/community-screen))))))