Copyright (C) 2015 takahirom
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
webview-in-coordinatorlayout's Introduction
webview-in-coordinatorlayout's People
Forkers
kingideayou abdelhady hkmopen eduardo-gb blueflychief howard9891 crowbarsolutions xuezhichan paulkayc muxi166 radiationx csshuai liqiang861220 rockman9x geofbot droidsky ricots 14core vssh yuye1124956 alexandersvyatetsky mlevytskiy ailiboy520 phpeng-ms horselai chenlove randhirgupta kawmra irfanirawansukirman she1014 victorpurmar penpan85 binhndicts achillh yccheok 754442658 jingmeng breankingbad lvfeimeng mehrrizwan lldfx1314 halit4603 carbaj03 ogapants lowtension hpustudent cuichanghao dat-vu martinbaraya jinjoochoi eugenepoplavsky tonygshliu wdziemia jianguoshu hassoon1986 swillk zhangbingbin kelalaka153 rametechie okmarco matejhrazdira goyourfly xiexiang89 zhuqingyuan drachuojin mshq37 weiwenhuaming yomigatz ohhyea examine928 iq-scmwebview-in-coordinatorlayout's Issues
How to use GestureDetector.
How i can implement GestureDetector for single and double tap.
Not working correctly
I put this web view in a coordinator layout with another view and attached a behavior to this view. In the behavior I override onNestedPreScroll
, where I always consume dy
(as a test), so the webview shouldn't scroll, but it still does.
My code works as expected if I just replace this webview with NestedScrollView
.
Edit:
I downloaded your example and added this to the behaviour:
@Override
public void onNestedPreScroll(final CoordinatorLayout coordinatorLayout, final LinearLayout child, final View target, final int dx, final int dy, final int[] consumed) {
consumed[1] = dy;
super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed);
}
And the webview still scroll normally. Shouldn't return dy
as consumed
make it stop scrolling entirely?
I wrote NestedWebView with Kotlin and fix some codes.
package input.your.package.name
/*
- Copyright (C) 2015 takahirom
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
*/
import android.annotation.SuppressLint
import android.content.Context
import android.support.v4.view.NestedScrollingChild
import android.support.v4.view.NestedScrollingChildHelper
import android.support.v4.view.ViewCompat
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.MotionEvent.*
import android.webkit.WebView
open class NestedWebView(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = android.R.attr.webViewStyle) : WebView(context, attrs, defStyleAttr), NestedScrollingChild {
private val mScrollOffset = IntArray(2)
private val mScrollConsumed = IntArray(2)
private val mChildHelper = NestedScrollingChildHelper(rootView)
private var mLastY: Float = 0F
private var mNestedOffsetY: Float = 0F
init {
isNestedScrollingEnabled = true
}
@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(ev: MotionEvent): Boolean {
val event = obtain(ev)
var returnValue = false
event.offsetLocation(0f, mNestedOffsetY)
when (ev.action) {
ACTION_DOWN -> {
returnValue = super.onTouchEvent(event)
mLastY = event.y
// start NestedScroll
startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL)
}
ACTION_MOVE -> {
var deltaY = mLastY - event.y
// NestedPreScroll
if (dispatchNestedPreScroll(0, deltaY.toInt(), mScrollConsumed, mScrollOffset)) {
deltaY -= mScrollConsumed[1]
mLastY = event.y - mScrollOffset[1]
event.offsetLocation(0f, (-mScrollOffset[1]).toFloat())
mNestedOffsetY += mScrollOffset[1]
}
returnValue = super.onTouchEvent(event)
// NestedScroll
if (dispatchNestedScroll(0, mScrollOffset[1], 0, deltaY.toInt(), mScrollOffset)) {
event.offsetLocation(0f, mScrollOffset[1].toFloat())
mNestedOffsetY += mScrollOffset[1]
mLastY -= mScrollOffset[1]
}
}
ACTION_UP, ACTION_CANCEL -> {
mNestedOffsetY = 0F
returnValue = super.onTouchEvent(event)
// end NestedScroll
stopNestedScroll()
}
}
return returnValue
}
// Nested Scroll implements
override fun setNestedScrollingEnabled(enabled: Boolean) {
mChildHelper.isNestedScrollingEnabled = enabled
}
override fun stopNestedScroll() {
mChildHelper.stopNestedScroll()
}
override fun isNestedScrollingEnabled() = mChildHelper.isNestedScrollingEnabled
override fun startNestedScroll(axes: Int) = mChildHelper.startNestedScroll(axes)
override fun hasNestedScrollingParent() = mChildHelper.hasNestedScrollingParent()
override fun dispatchNestedPreScroll(dx: Int, dy: Int, consumed: IntArray?, offsetInWindow: IntArray?) = mChildHelper.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow)
override fun dispatchNestedFling(velocityX: Float, velocityY: Float, consumed: Boolean) = mChildHelper.dispatchNestedFling(velocityX, velocityY, consumed)
override fun dispatchNestedPreFling(velocityX: Float, velocityY: Float) = mChildHelper.dispatchNestedPreFling(velocityX, velocityY)
override fun dispatchNestedScroll(dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int,
offsetInWindow: IntArray?) = mChildHelper.dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, offsetInWindow)
}
toolbar shouldnt autohide when viewing pannable content like Google Maps
WebView scrolling back to the top
Hi there, I've been using your webview for a while and it works great, but now I noticed something weird.
When navigating on Facebook or any other website that loads content while you are scrolling, the webview scrolls all the way to the top by itself.
Do you have any idea of what's happening?
Thanks.
When selecting a text input/field inside the WebView, the soft keyboard is never shown.
This could possibly be a duplicate of Issue #1, but I'm creating a separate issue just in case.
When tapping the text input/field the input got focus and a cursor appeared; however, Android's soft keyboard never appeared. After hacking around and through trial and elimination, I found that removing all the code this class had and only using the constructors provided that the issue still existed. So I looked at Android's WebView constructor with 2 parms and noticed it passes com.android.internal.R.attr.webViewStyle for the defStyleAttr parameter. I took a shot in the dark and tried passing android.R.attr.webViewStyle as the defStyleAttr parm instead of 0 and now the soft keyboard appears.
So the fix is to remove this constructor:
public NestedWebView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
and instead use this one:
public NestedWebView(Context context, AttributeSet attrs) {
this(context, attrs, android.R.attr.webViewStyle);
}
I have no idea why this fixes the issue. I would have to take a closer look at what android.R.attr.webViewStyle declares.
Webview jumps after pinch to zoom or any multi-finger gesture
Your webview works great for single finger gestures but starts acting strange when doing multi-finger gestures such as pinch to zoom. The webview seems to jump after a multi finger gesture is completed.
the webview can not get focused on using nestedwebview
pls fix
Screen gif image
First scroll down doesn't work properly until a scroll up happens
The first continuous scroll down doesn't propagate the event as expected, I had to scroll 1 down then 1 up, then all is working fine,
I'm using a real device (LG G2) running KitKat 4.4.2, and here is the layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".HomeActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/brand_color"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<net.begether.chaino.utils.NestedWebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
This doesn't work if the webview itself has some scrolling content. For example : a drop down in webview which is scrollable; unable to scroll it.
NestedWebview's Scroll not same as in CollapsingToolbarLayout
I've come into this library with stackoverflow suggestions to Android bug with Webview and NestedScrollView.
The replacement is very easy and I've got rid of the app crush on large web pages. However, the scrolling not same as the default CollapsingToolbarLayout.
- The webview scroll into the CollapsingToolbar as soon as scrolling started.
- The CollapsingToolbar coming down very fast on down scrool
I think the CollapsingToolbar and the webview scrolls together.
Can we solve this?
XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".ArticleReaderActivity"
>
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="200dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.MaterialComponents.ActionBar.Primary">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:expandedTitleTextAppearance="@style/ExpandedAppBar"
app:collapsedTitleTextAppearance="@style/CollapsedAppBar"
app:expandedTitleGravity="bottom|center_horizontal"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/imageview_section_reader"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
app:layout_collapseMode="parallax"
android:contentDescription="@string/desc"
/>
<include layout="@layout/toolbar"/>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<com.test.NestedWebView
android:id="@+id/webviev_section_reader"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>`
</androidx.coordinatorlayout.widget.CoordinatorLayout>
How to properly use this with swiperefreshlayout?
Hi!
I want to use the nestedWebView together with a SwipeRefreshLayout inside a CoordinatorLayout with two Toolbars (top and bottom), but the SwipeRefreshLayout is too sensible now. Is there a way to fix this?
SwipeRefresh works fine with webview.setNestedScrollingEnabled(false), but then the Toolbars do not hide.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.