Skip to content

Commit c480449

Browse files
authored
Show scrollbars on webview. Also, moved webview config back to XML. (#171)
* Show scrollbars on webview. Also, moved webview config back to XML. * Restore layout to use `NestedWebView` * Use correct WebView constructors * Change to a grey colour for scrollbar thumb and tweak toolbar style
1 parent 7e3ad98 commit c480449

File tree

4 files changed

+42
-18
lines changed

4 files changed

+42
-18
lines changed

app/src/main/java/com/duckduckgo/app/browser/BrowserActivity.kt

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import android.arch.lifecycle.ViewModelProviders
2424
import android.content.Context
2525
import android.content.Intent
2626
import android.net.Uri
27-
import android.os.Build
2827
import android.os.Bundle
2928
import android.support.v7.widget.LinearLayoutManager
3029
import android.text.Editable
@@ -73,7 +72,7 @@ class BrowserActivity : DuckDuckGoActivity(), BookmarkDialogCreationListener {
7372

7473
@Inject
7574
lateinit var viewModelFactory: ViewModelFactory
76-
75+
7776
@Inject
7877
lateinit var cookieManagerProvider: Provider<CookieManager>
7978

@@ -99,8 +98,8 @@ class BrowserActivity : DuckDuckGoActivity(), BookmarkDialogCreationListener {
9998
super.onCreate(savedInstanceState)
10099

101100
setContentView(R.layout.activity_browser)
101+
102102
createPopupMenu()
103-
createWebView()
104103
configureObservers()
105104
configureToolbar()
106105
configureWebView()
@@ -126,17 +125,6 @@ class BrowserActivity : DuckDuckGoActivity(), BookmarkDialogCreationListener {
126125
}
127126
}
128127

129-
private fun createWebView() {
130-
webView = NestedWebView(this)
131-
webView.gone()
132-
webView.isFocusableInTouchMode = true
133-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
134-
webView.focusable = View.FOCUSABLE
135-
}
136-
137-
webViewContainer.addView(webView)
138-
}
139-
140128
private fun configureObservers() {
141129
viewModel.viewState.observe(this, Observer<BrowserViewModel.ViewState> {
142130
it?.let { render(it) }
@@ -345,6 +333,7 @@ class BrowserActivity : DuckDuckGoActivity(), BookmarkDialogCreationListener {
345333

346334
@SuppressLint("SetJavaScriptEnabled")
347335
private fun configureWebView() {
336+
webView = layoutInflater.inflate(R.layout.include_duckduckgo_browser_webview, webViewContainer, true).findViewById(R.id.browserWebView) as WebView
348337
webView.webViewClient = webViewClient
349338
webView.webChromeClient = webChromeClient
350339

app/src/main/java/com/duckduckgo/app/browser/NestedWebView.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,15 @@ import android.webkit.WebView
3131
* Based on https://github.com/takahirom/webview-in-coordinatorlayout
3232
*/
3333
class NestedWebView : WebView, NestedScrollingChild {
34-
3534
private var lastY: Int = 0
3635
private val scrollOffset = IntArray(2)
3736
private val scrollConsumed = IntArray(2)
3837
private var nestedOffetY: Int = 0
3938
private var nestedScrollHelper: NestedScrollingChildHelper = NestedScrollingChildHelper(this)
4039

4140
constructor(context: Context) : this(context, null)
42-
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
43-
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
44-
nestedScrollHelper = NestedScrollingChildHelper(this)
41+
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
42+
{
4543
isNestedScrollingEnabled = true
4644
}
4745

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
~ Copyright (c) 2018 DuckDuckGo
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
-->
16+
17+
<com.duckduckgo.app.browser.NestedWebView xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:tools="http://schemas.android.com/tools"
19+
android:id="@+id/browserWebView"
20+
android:layout_width="match_parent"
21+
android:layout_height="match_parent"
22+
android:fadeScrollbars="true"
23+
android:focusable="true"
24+
android:focusableInTouchMode="true"
25+
android:scrollbarSize="4dp"
26+
android:scrollbarStyle="outsideInset"
27+
android:scrollbarThumbHorizontal="@color/webViewScrollbarThumbColor"
28+
android:scrollbarThumbVertical="@color/webViewScrollbarThumbColor"
29+
android:scrollbarTrackHorizontal="@color/webViewScrollbarTrackColor"
30+
android:scrollbarTrackVertical="@color/webViewScrollbarTrackColor"
31+
android:visibility="gone"
32+
tools:visibility="visible">
33+
34+
</com.duckduckgo.app.browser.NestedWebView>

app/src/main/res/values/colors.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,7 @@
3333

3434
<color name="white_two">#e4e4e4</color>
3535

36+
<color name="webViewScrollbarTrackColor">#FF333333</color>
37+
<color name="webViewScrollbarThumbColor">#FFABABAB</color>
38+
3639
</resources>

0 commit comments

Comments
 (0)