[#5278][Android] persist webview state during session

This commit is contained in:
Roman Volosovskyi 2018-07-30 16:38:57 +03:00
parent 434046fe9d
commit 48d81a4f95
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
7 changed files with 862 additions and 476 deletions

1
.env
View File

@ -16,3 +16,4 @@ INSTABUG_SURVEYS=1
GROUP_CHATS_ENABLED=0
USE_SYM_KEY=0
SPAM_BUTTON_DETECTION_ENABLED=1
CACHED_WEBVIEWS_ENABLED=1

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -56,7 +56,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",

View File

@ -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]))

View File

@ -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]]
@ -101,7 +101,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

View File

@ -44,3 +44,4 @@
(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 in-app-notifications-enabled? (enabled? (get-config :IN_APP_NOTIFICATIONS_ENABLED 0)))
(def cached-webviews-enabled? (enabled? (get-config :CACHED_WEBVIEWS_ENABLED 0)))