webview loading indicator

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
Andrey Shovkoplyas 2018-07-23 16:22:32 +03:00
parent 56eb0b57a7
commit c5771f3168
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
3 changed files with 42 additions and 34 deletions

View File

@ -9,10 +9,12 @@
(spec/def :browser/error? (spec/nilable boolean?))
(spec/def :browser/history (spec/nilable vector?))
(spec/def :browser/history-index (spec/nilable int?))
(spec/def :browser/loading? (spec/nilable boolean?))
(spec/def :browser/options
(allowed-keys
:opt-un [:browser/browser-id
:browser/loading?
:browser/error?]))
(spec/def :browser/browser

View File

@ -39,9 +39,15 @@
:justify-content :center})
(def web-view-loading
{:flex 1
:align-items :center
:justify-content :center})
{:flex 1
:background-color colors/gray-transparent
:align-items :center
:justify-content :center
:position :absolute
:top 0
:bottom 0
:left 0
:right 0})
(def web-view-error
{:flex 1

View File

@ -18,7 +18,8 @@
[status-im.ui.components.toolbar.actions :as actions]
[status-im.ui.components.tooltip.views :as tooltip]
[status-im.models.browser :as model]
[status-im.utils.http :as http]))
[status-im.utils.http :as http]
[status-im.ui.components.styles :as components.styles]))
(views/defview toolbar-content-dapp [name]
(views/letsubs [dapp [:get-dapp-by-name name]]
@ -61,13 +62,9 @@
[react/text {:style styles/web-view-error-text}
(str desc)]]))
(defn web-view-loading []
(reagent/as-element
[react/view styles/web-view-loading
[components/activity-indicator {:animating true}]]))
(defn on-navigation-change [event browser]
(let [{:strs [url loading]} (js->clj event)]
(re-frame/dispatch [:update-browser-options {:loading? loading}])
(when (not= "about:blank" url)
(re-frame/dispatch [:update-browser-on-nav-change browser url loading]))))
@ -79,7 +76,7 @@
(views/letsubs [webview (atom nil)
{:keys [address]} [:get-current-account]
{:keys [dapp? browser-id name] :as browser} [:get-current-browser]
{:keys [error?]} [:get :browser/options]
{:keys [error? loading?]} [:get :browser/options]
rpc-url [:get :rpc-url]
network-id [:get-network-id]]
(let [can-go-back? (model/can-go-back? browser)
@ -98,30 +95,33 @@
(if dapp?
[toolbar-content-dapp name]
[toolbar-content url browser])]
[components.webview-bridge/webview-bridge
{:ref #(reset! webview %)
:source {:uri url}
:java-script-enabled true
:bounces false
:local-storage-enabled true
:start-in-loading-state true
:render-error web-view-error
:render-loading web-view-loading
:on-navigation-state-change #(on-navigation-change % browser)
:on-bridge-message #(re-frame/dispatch [:on-bridge-message
(js->clj (.parse js/JSON %)
:keywordize-keys true)
browser
webview])
:on-load #(re-frame/dispatch [:update-browser-options {:error? false}])
:on-error #(re-frame/dispatch [:update-browser-options {:error? true}])
:injected-on-start-loading-java-script (str js-res/web3
(get-inject-js url)
(js-res/web3-init
rpc-url
(ethereum/normalized-address address)
(str network-id)))
:injected-java-script js-res/webview-js}]
[react/view components.styles/flex
[components.webview-bridge/webview-bridge
{:ref #(reset! webview %)
:source {:uri url}
:java-script-enabled true
:bounces false
:local-storage-enabled true
:render-error web-view-error
:on-navigation-state-change #(on-navigation-change % browser)
:on-bridge-message #(re-frame/dispatch [:on-bridge-message
(js->clj (.parse js/JSON %)
:keywordize-keys true)
browser
webview])
:on-load #(re-frame/dispatch [:update-browser-options {:error? false}])
:on-error #(re-frame/dispatch [:update-browser-options {:error? true
:loading? false}])
:injected-on-start-loading-java-script (str js-res/web3
(get-inject-js url)
(js-res/web3-init
rpc-url
(ethereum/normalized-address address)
(str network-id)))
:injected-java-script js-res/webview-js}]
(when loading?
[react/view styles/web-view-loading
[components/activity-indicator {:animating true}]])]
[react/view styles/toolbar
[react/touchable-highlight {:on-press #(re-frame/dispatch [:browser-nav-back browser])
:disabled (not can-go-back?)