-
Notifications
You must be signed in to change notification settings - Fork 7
ANDROID-10730 Initial branch with nested scroll webview implementation #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -0,0 +1,91 @@ | |||
package com.telefonica.nestedscrollwebview |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most important class
import android.view.ViewParent | ||
import androidx.coordinatorlayout.widget.CoordinatorLayout | ||
|
||
class CoordinatorLayoutChildHelper { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Workaround for --> https://issuetracker.google.com/issues/37093004
import com.telefonica.nestedscrollwebview.helper.NestedScrollViewChild | ||
import com.telefonica.nestedscrollwebview.helper.NestedScrollViewHelper | ||
|
||
class NestedScrollWebView: WebView, NestedScrollViewChild { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Workaround to solve two main problems when using a webView inside a NestedScrollView:
- WebView height calculation.
- WebView must process its own scrolling from touch events.
/** | ||
* This class extracts the following functionality from NestedScrollView class (Android Support Library Compat 1.8.0): | ||
* * NestedScrollView.onTouchEvent(@NonNull MotionEvent ev) implementation | ||
* * NestedScrollView.computeScroll() implementation | ||
* * NestedScrollView NestedScrollingChild3 interface implementation | ||
* Views can delegate nested scrolling logic to this class, by implementing NestedChildView interface. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explanation for this class. Idea of it is that implementation use composition instead of inheritance to apply this functionality. Also, it isolates support library original code from NestedScrollWebView implementation.
/* | ||
* 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. | ||
* | ||
* Based on the implementation of NestedScrollView from The Android Open Source Project | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should include license file, as the code is from app compat library.
override fun onCreateOptionsMenu(menu: Menu): Boolean { | ||
// Inflate the menu; this adds items to the action bar if it is present. | ||
menuInflater.inflate(R.menu.menu_scrolling, menu) | ||
return true | ||
} | ||
|
||
override fun onOptionsItemSelected(item: MenuItem): Boolean { | ||
// Handle action bar item clicks here. The action bar will | ||
// automatically handle clicks on the Home/Up button, so long | ||
// as you specify a parent activity in AndroidManifest.xml. | ||
|
||
return when (item.itemId) { | ||
R.id.action_settings -> true | ||
else -> super.onOptionsItemSelected(item) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this can be deleted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adapted on last commits to toogle between the different behaviours
import com.telefonica.nestedscrollwebview.helper.NestedScrollViewChild | ||
import com.telefonica.nestedscrollwebview.helper.NestedScrollViewHelper | ||
|
||
class NestedScrollWebView: WebView, NestedScrollViewChild { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be open
, so it can be extended, also I would open the methods, as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, done
override fun computeHorizontalScrollRange(): Int = | ||
super.computeHorizontalScrollRange() | ||
|
||
override fun computeHorizontalScrollExtent(): Int = | ||
super.computeHorizontalScrollExtent() | ||
|
||
override fun computeVerticalScrollRange(): Int = | ||
super.computeVerticalScrollRange() | ||
|
||
override fun computeVerticalScrollExtent(): Int = | ||
super.computeVerticalScrollExtent() | ||
|
||
override fun onOverScrolled(scrollX: Int, scrollY: Int, clampedX: Boolean, clampedY: Boolean) { | ||
super.onOverScrolled(scrollX, scrollY, clampedX, clampedY) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be deleted, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these have protected visibility in webView class, so it is just to expose visibility to the NesteScrollViewHelper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Congratulations! 👏👏👏
…erface + Cleanup
…hing behaviour optional and disabled by default
…tching enabling
Re-requesting review with last changes on configuration and sample app |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Congratulations, amazing job!
Initial commit for the repo.
It contains a library module and a simple sample app to check the implementation.
There's still some formalities to do, as documentation and prepare the artifact publishing.
Please check this firstly so I can get feedback on it to prepare the repo completely.