Skip to content

Commit

Permalink
[#5278][Android] persist webview state during session
Browse files Browse the repository at this point in the history
  • Loading branch information
rasom committed Jul 30, 2018
1 parent a586d17 commit f67373c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
24 changes: 21 additions & 3 deletions src/status_im/ui/components/webview_bridge.cljs
@@ -1,9 +1,27 @@
(ns status-im.ui.components.webview-bridge
(:require [reagent.core :as reagent]
[status-im.react-native.js-dependencies :as js-dependencies]))
[status-im.react-native.js-dependencies :as js-dependencies]
[reagent.core :as reagent.core]
[status-im.utils.platform :as platform]))

(def webview-bridge-class
(reagent/adapt-react-class (.-default js-dependencies/webview-bridge)))

(defn webview-bridge [opts]
[webview-bridge-class opts])
(def module (.-WebViewBridgeModule (.-NativeModules js-dependencies/react-native)))

(defn webview-bridge [{:keys [dapp? dapp-name] :as opts}]
(if (and platform/android? (not dapp?))
[webview-bridge-class opts]
(reagent.core/create-class
(let [dapp-name-sent? (reagent.core/atom false)]
{:component-will-mount
(fn []
;; unfortunately it's impossible to pass some initial params
;; to view, that's why we have to pass dapp-name to the module
;; before showing webview
(.setCurrentDapp module dapp-name
(fn [] (reset! dapp-name-sent? true))))
:reagent-render
(fn [opts]
(when @dapp-name-sent?
[webview-bridge-class opts]))}))))
6 changes: 4 additions & 2 deletions src/status_im/ui/screens/browser/views.cljs
Expand Up @@ -100,7 +100,9 @@
:handler #(re-frame/dispatch [:navigate-to-modal :wallet-modal])}]]]
[react/view components.styles/flex
[components.webview-bridge/webview-bridge
{:ref #(reset! webview %)
{:dapp? dapp?
:dapp-name name
:ref #(reset! webview %)
:source {:uri url}
:java-script-enabled true
:bounces false
Expand Down Expand Up @@ -144,4 +146,4 @@
[icons/icon :icons/refresh]]]
(when-not dapp?
[tooltip/bottom-tooltip-info
(i18n/label :t/browser-warning)])])))
(i18n/label :t/browser-warning)])])))

0 comments on commit f67373c

Please sign in to comment.