Skip to content

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

Merged
merged 5 commits into from
Aug 8, 2022

Conversation

dpastor
Copy link
Contributor

@dpastor dpastor commented Aug 4, 2022

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.

@dpastor dpastor requested a review from gmerinojimenez August 4, 2022 08:12
@@ -0,0 +1,91 @@
package com.telefonica.nestedscrollwebview
Copy link
Contributor Author

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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import com.telefonica.nestedscrollwebview.helper.NestedScrollViewChild
import com.telefonica.nestedscrollwebview.helper.NestedScrollViewHelper

class NestedScrollWebView: WebView, NestedScrollViewChild {
Copy link
Contributor Author

@dpastor dpastor Aug 4, 2022

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.

Comment on lines 42 to 48
/**
* 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.
*/
Copy link
Contributor Author

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.

Comment on lines +1 to +15
/*
* 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
*/
Copy link
Contributor Author

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.

Comment on lines 47 to 62
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)
}
}

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

Copy link
Contributor Author

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 {
Copy link

@gmerinojimenez gmerinojimenez Aug 4, 2022

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done

Comment on lines 76 to 90
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)
}

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?

Copy link
Contributor Author

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.

Copy link

@gmerinojimenez gmerinojimenez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congratulations! 👏👏👏

@dpastor dpastor requested a review from gmerinojimenez August 5, 2022 12:23
@dpastor
Copy link
Contributor Author

dpastor commented Aug 5, 2022

Re-requesting review with last changes on configuration and sample app

Copy link

@gmerinojimenez gmerinojimenez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congratulations, amazing job!

@dpastor dpastor merged commit 78e6439 into main Aug 8, 2022
@dpastor dpastor deleted the initial_branch branch August 8, 2022 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants