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 Aug 2, 2018
1 parent 6d2161c commit 36473fc
Show file tree
Hide file tree
Showing 7 changed files with 841 additions and 479 deletions.
1 change: 1 addition & 0 deletions .env
Expand Up @@ -16,3 +16,4 @@ INSTABUG_SURVEYS=1
GROUP_CHATS_ENABLED=0
USE_SYM_KEY=0
SPAM_BUTTON_DETECTION_ENABLED=1
CACHED_WEBVIEWS_ENABLED=1
1 change: 1 addition & 0 deletions .env.jenkins
Expand Up @@ -17,3 +17,4 @@ GROUP_CHATS_ENABLED=0
USE_SYM_KEY=0
SPAM_BUTTON_DETECTION_ENABLED=1
MAINNET_WARNING_ENABLED=1
CACHED_WEBVIEWS_ENABLED=1
1,282 changes: 810 additions & 472 deletions mobile_files/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion mobile_files/package.json
Expand Up @@ -57,7 +57,7 @@
"react-native-tcp": "3.3.0",
"react-native-testfairy": "2.10.0",
"react-native-udp": "2.2.1",
"react-native-webview-bridge": "https://github.com/status-im/react-native-webview-bridge.git",
"react-native-webview-bridge": "git+https://github.com/status-im/react-native-webview-bridge.git#feature/cached-webviews",
"realm": "2.3.3",
"rn-snoopy": "https://github.com/status-im/rn-snoopy.git",
"string_decoder": "0.10.31",
Expand Down
25 changes: 22 additions & 3 deletions src/status_im/ui/components/webview_bridge.cljs
@@ -1,9 +1,28 @@
(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]
[status-im.utils.config :as config]))

(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 config/cached-webviews-enabled? platform/android? dapp?)
(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]))}))
[webview-bridge-class opts]))
8 changes: 5 additions & 3 deletions src/status_im/ui/screens/browser/views.cljs
Expand Up @@ -77,7 +77,7 @@
(views/defview browser []
(views/letsubs [webview (atom nil)
{:keys [address]} [:get-current-account]
{:keys [browser-id] :as browser} [:get-current-browser]
{:keys [browser-id dapp? name] :as browser} [:get-current-browser]
{:keys [error? loading? url-editing? show-tooltip]} [:get :browser/options]
rpc-url [:get :rpc-url]
network-id [:get-network-id]]
Expand All @@ -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 @@ -147,4 +149,4 @@
(if (= show-tooltip :secure)
(i18n/label :t/browser-secure)
(i18n/label :t/browser-not-secure))
#(re-frame/dispatch [:update-browser-options {:show-tooltip nil}])])])))
#(re-frame/dispatch [:update-browser-options {:show-tooltip nil}])])])))
1 change: 1 addition & 0 deletions src/status_im/utils/config.cljs
Expand Up @@ -43,3 +43,4 @@
(def group-chats-enabled? (enabled? (get-config :GROUP_CHATS_ENABLED)))
(def spam-button-detection-enabled? (enabled? (get-config :SPAM_BUTTON_DETECTION_ENABLED "0")))
(def mainnet-warning-enabled? (enabled? (get-config :MAINNET_WARNING_ENABLED 0)))
(def cached-webviews-enabled? (enabled? (get-config :CACHED_WEBVIEWS_ENABLED 0)))

0 comments on commit 36473fc

Please sign in to comment.