Webview is still active after unmount [#4353]
Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
parent
76f5f020ef
commit
7b8950870f
|
@ -1,29 +1,9 @@
|
||||||
(function () {
|
(function () {
|
||||||
window.statusAPI = {
|
|
||||||
dispatch: function (event, options) {
|
|
||||||
console.log("statusAPI.dispatch: " + JSON.stringify(options));
|
|
||||||
if (options.callback) {
|
|
||||||
console.log(options.callback);
|
|
||||||
statusAPI.callbacks[event] = options.callback;
|
|
||||||
}
|
|
||||||
var json = JSON.stringify({
|
|
||||||
event: event,
|
|
||||||
options: options
|
|
||||||
});
|
|
||||||
console.log("sending from webview: " + json);
|
|
||||||
WebViewBridge.send(json);
|
|
||||||
},
|
|
||||||
callbacks: {}
|
|
||||||
};
|
|
||||||
|
|
||||||
WebViewBridge.onMessage = function (messageString) {
|
WebViewBridge.onMessage = function (messageString) {
|
||||||
console.log("received from react-native: " + messageString);
|
console.log("received from react-native: " + messageString);
|
||||||
var message = JSON.parse(messageString);
|
|
||||||
|
|
||||||
if (message.event === "actions-execute-js") {
|
if (messageString === "navigate-to-blank")
|
||||||
eval(message.js);
|
window.location.href = "about:blank";
|
||||||
} else if (statusAPI.callbacks[message.event]) {
|
|
||||||
statusAPI.callbacks[message.event](message.params);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}());
|
}());
|
||||||
|
|
|
@ -25,8 +25,7 @@
|
||||||
status-im.chat.events.requests
|
status-im.chat.events.requests
|
||||||
status-im.chat.events.send-message
|
status-im.chat.events.send-message
|
||||||
status-im.chat.events.receive-message
|
status-im.chat.events.receive-message
|
||||||
status-im.chat.events.console
|
status-im.chat.events.console))
|
||||||
status-im.chat.events.webview-bridge))
|
|
||||||
|
|
||||||
;;;; Effects
|
;;;; Effects
|
||||||
|
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
(ns status-im.chat.events.webview-bridge
|
|
||||||
(:require [re-frame.core :as re-frame]
|
|
||||||
[status-im.ui.components.nfc :as nfc]
|
|
||||||
[status-im.utils.handlers :as handlers]
|
|
||||||
[status-im.utils.types :as types]
|
|
||||||
[taoensso.timbre :as log]))
|
|
||||||
|
|
||||||
;;;; Effects
|
|
||||||
|
|
||||||
(re-frame/reg-fx
|
|
||||||
::webview-nfc
|
|
||||||
(fn [{:keys [event params]}]
|
|
||||||
(let [callback #(re-frame/dispatch [:chat-webview-bridge/send-to-bridge
|
|
||||||
{:params % :event "nfc"}])]
|
|
||||||
(case (keyword event)
|
|
||||||
:get-card-id (nfc/get-card-id #(callback {:event :get-card-id :card %})
|
|
||||||
#(callback {:event :get-card-id :error %}))
|
|
||||||
:read-tag (let [{:keys [sectors]} params]
|
|
||||||
(nfc/read-tag sectors
|
|
||||||
#(callback {:event :read-tag :card %})
|
|
||||||
#(callback {:event :read-tag :error %})))
|
|
||||||
:write-tag (let [{:keys [sectors id]} params]
|
|
||||||
(nfc/write-tag sectors
|
|
||||||
id
|
|
||||||
#(callback {:event :write-tag :card %})
|
|
||||||
#(callback {:event :write-tag :error %})))
|
|
||||||
:default))))
|
|
||||||
|
|
||||||
(re-frame/reg-fx
|
|
||||||
::send-to-bridge
|
|
||||||
(fn [[webview-bridge data]]
|
|
||||||
(when webview-bridge
|
|
||||||
(.sendToBridge webview-bridge data))))
|
|
||||||
|
|
||||||
;;;; Handlers
|
|
||||||
|
|
||||||
(handlers/register-handler-db
|
|
||||||
:chat-webview-bridge/set-ref
|
|
||||||
(fn [db [_ ref]]
|
|
||||||
(assoc db :webview-bridge ref)))
|
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
|
||||||
:chat-webview-bridge/process-message
|
|
||||||
(fn [{:keys [db]} [_ message-string]]
|
|
||||||
(let [{:keys [event options] :as message} (types/json->clj message-string)
|
|
||||||
event' (keyword event)
|
|
||||||
params (:data options)]
|
|
||||||
(log/debug (str "message from webview: " message))
|
|
||||||
(case event'
|
|
||||||
:nfc {::webview-nfc params}
|
|
||||||
nil))))
|
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
|
||||||
:chat-webview-bridge/send-to-bridge
|
|
||||||
(fn [{{:keys [webview-bridge]} :db} [_ data]]
|
|
||||||
{::send-to-bridge [webview-bridge data]}))
|
|
|
@ -85,6 +85,7 @@
|
||||||
[toolbar.view/toolbar {}
|
[toolbar.view/toolbar {}
|
||||||
[toolbar.view/nav-button-with-count
|
[toolbar.view/nav-button-with-count
|
||||||
(actions/close (fn []
|
(actions/close (fn []
|
||||||
|
(.sendToBridge @webview "navigate-to-blank")
|
||||||
(re-frame/dispatch [:navigate-back])
|
(re-frame/dispatch [:navigate-back])
|
||||||
(when error?
|
(when error?
|
||||||
(re-frame/dispatch [:remove-browser browser-id]))))]
|
(re-frame/dispatch [:remove-browser browser-id]))))]
|
||||||
|
|
Loading…
Reference in New Issue