fix: nav conflicts when return from bg from link (#17853)

This commit is contained in:
yqrashawn 2023-11-10 09:15:02 +08:00 committed by GitHub
parent ffeb06f36c
commit b4919261cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 11 deletions

View File

@ -18,12 +18,14 @@
(log/error e)))) (log/error e))))
(defn set-item! (defn set-item!
[k value] ([k value] (set-item! k value identity))
(-> ^js async-storage ([k value cb]
(.setItem (str k) (-> ^js async-storage
(clj->transit value)) (.setItem (str k)
(.catch (fn [error] (clj->transit value))
(log/error "[async-storage]" error))))) (.then (fn [_] (cb)))
(.catch (fn [error]
(log/error "[async-storage]" error))))))
(defn set-item-factory (defn set-item-factory
[] []

View File

@ -158,7 +158,9 @@
(rf/defn on-going-in-background (rf/defn on-going-in-background
[{:keys [db now]}] [{:keys [db now]}]
{:db (assoc db :app-in-background-since now)}) {:db (-> db
(assoc :app-in-background-since now)
(dissoc :universal-links/handling))})
;; event not implemented ;; event not implemented
;; :dispatch-n [[:audio-recorder/on-background] [:audio-message/on-background]] ;; :dispatch-n [[:audio-recorder/on-background] [:audio-message/on-background]]

View File

@ -3,6 +3,7 @@
[clojure.string :as string] [clojure.string :as string]
[native-module.core :as native-module] [native-module.core :as native-module]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[react-native.async-storage :as async-storage]
[react-native.core :as rn] [react-native.core :as rn]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[taoensso.timbre :as log] [taoensso.timbre :as log]
@ -118,7 +119,10 @@
"Dispatch url so we can get access to re-frame/db" "Dispatch url so we can get access to re-frame/db"
[url] [url]
(if-not (nil? url) (if-not (nil? url)
(re-frame/dispatch [:universal-links/handle-url url]) (do
(async-storage/set-item! (str :chat-id) nil #(rf/dispatch [:universal-links/remove-handling]))
(re-frame/dispatch [:universal-links/handling])
(re-frame/dispatch [:universal-links/handle-url url]))
(log/debug "universal-links: no url"))) (log/debug "universal-links: no url")))
(rf/defn on-handle (rf/defn on-handle
@ -151,6 +155,16 @@
(log/info :store-url-for-later) (log/info :store-url-for-later)
{:db (assoc db :universal-links/url url)}) {:db (assoc db :universal-links/url url)})
(rf/defn handling
{:events [:universal-links/handling]}
[{:keys [db]}]
{:db (assoc db :universal-links/handling true)})
(rf/defn remove-handling
{:events [:universal-links/remove-handling]}
[{:keys [db]}]
{:db (dissoc db :universal-links/handling)})
(rf/defn handle-url (rf/defn handle-url
"Store url in the database if the user is not logged in, to be processed "Store url in the database if the user is not logged in, to be processed
on login, otherwise just handle it." on login, otherwise just handle it."

View File

@ -113,8 +113,9 @@
(fn [accounts tokens custom-tokens favourites] (fn [accounts tokens custom-tokens favourites]
(re-frame/dispatch [:wallet-legacy/initialize-wallet (re-frame/dispatch [:wallet-legacy/initialize-wallet
accounts tokens custom-tokens favourites]))] accounts tokens custom-tokens favourites]))]
:check-eip1559-activation {:network-id network-id} :check-eip1559-activation {:network-id network-id}}
:chat/open-last-chat (get-in db [:profile/profile :key-uid])} (not (:universal-links/handling db))
(assoc :chat/open-last-chat (get-in db [:profile/profile :key-uid]))
notifications-enabled? notifications-enabled?
(assoc :effects/push-notifications-enable nil)) (assoc :effects/push-notifications-enable nil))
(transport/start-messenger) (transport/start-messenger)

View File

@ -20,8 +20,9 @@
(defn handle-notification-press (defn handle-notification-press
[{{deep-link :deepLink} :userInfo [{{deep-link :deepLink} :userInfo
interaction :userInteraction}] interaction :userInteraction}]
(async-storage/set-item! (str :chat-id) nil) (async-storage/set-item! (str :chat-id) nil #(rf/dispatch [:universal-links/remove-handling]))
(when (and deep-link (or platform/ios? (and platform/android? interaction))) (when (and deep-link (or platform/ios? (and platform/android? interaction)))
(rf/dispatch [:universal-links/handling])
(rf/dispatch [:universal-links/handle-url deep-link]))) (rf/dispatch [:universal-links/handle-url deep-link])))
(defn listen-notifications (defn listen-notifications