Skip to content
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

Add view visibility checks to EpoxyVisibilityItem and decouple RecyclerView #1052

Merged

Conversation

pmecho
Copy link
Collaborator

@pmecho pmecho commented Sep 11, 2020

Problems

  1. If the view transitions to a visibility of GONE, it will retain a non-zero width and height. This causes the methods inside EpoxyVisibilityItem to continue to return true even though the view is not visible on the screen.
  2. The EpoxyVisibilityItem is strongly coupled with a RecyclerView. We have code in our app that uses epoxy outside of a RecyclerView and wish to incorporate the visibility tracking with that.

Solutions

  1. Store the visibility value of the view during the update call and check it when the handle... methods are called.
  2. We can just change the RecyclerView argument to use a ViewGroup. This will support the existing use case as well as allowing it to be used outside of RecyclerViews. A default constructor was added out of convenience but is by no means needed. The existing constructor really just sets the adapter position which isn't used if not using a RecyclerView

Peter Elliott added 2 commits September 10, 2020 20:48
Make EpoxyVisibilityItem more generic so it can work with a ViewGroup instead of just a RecyclerView
Fix docs in OnVisibilityStateChanged
@@ -68,7 +68,8 @@ rootProject.ext.deps = [
androidArchCoreTesting : "android.arch.core:core-testing:$ANDROID_ARCH_TESTING",
androidTestRunner : "com.android.support.test:runner:$ANDROID_TEST_RUNNER",
androidAnnotations : "androidx.annotation:annotation:$ANDROIDX_ANNOTATION",
androidTestCore : "androidx.test:core:1.2.0",
androidTestCore : "androidx.test:core:1.3.0",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I needed to update this to run the activity scenario tests. Otherwise the tests would crash.

@@ -10,10 +10,10 @@
* with this annotation will be called when the visibility state is changed.
* <p>
* Annotated methods should follow this signature :
* `@OnVisibilityStateChange
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These references were incorrect so I updated them

Copy link
Contributor

@elihart elihart left a comment

Choose a reason for hiding this comment

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

@pmecho looks great to me, just had one question.

Thanks for all the clean tests too!

visibleHeight, visibleWidth
);
if (viewVisibility == View.GONE) {
epoxyHolder.visibilityChanged(0f, 0f, 0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to check that viewVisibility changed? could it have already been gone but had the size change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice catch! I'd agree it makes sense to also check that. I'll make that change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@elihart While testing this I realized the size won't change while it's gone since the layout pass won't re-measure. I did find a case that makes us need this last visibility notified check though. If the view transitions from gone to visible the size won't change so we would need that check. I've added it and this should be good to go now.

@eboudrant
Copy link
Contributor

Nice addition! We are also starting to have models outside of RecyclerView.

What I am missing where how do you use it? Don't you need to update/refactor the EpoxyVisibilityTraker which can only be attached to a RecyclerView.

@elihart
Copy link
Contributor

elihart commented Sep 14, 2020

@eboudrant thanks for taking a look, glad you approve.

You're right that usage is missing. we have a fair amount of tooling internally for using models outside of a RecyclerView, part of which handles visibility tracking for models outside of a recyclerview. This PR upstreams just part of that.

I think this may be a good time to upstream more of it (maybe in a new module).

@pmecho
Copy link
Collaborator Author

pmecho commented Sep 14, 2020

@eboudrant Eli was spot on. We're using an internal class for the visibility tracking when used outside of a RecyclerView. That's still sort of a work in progress but I totally agree that we should upstream it, along with how we use epoxy outside of RecylcerViews. Once I finish up with the tracking I can make another PR if that works.

@eboudrant
Copy link
Contributor

Well now I can't wait these other PRs 👍

@pmecho
Copy link
Collaborator Author

pmecho commented Sep 15, 2020

Oof looks like CI is failing due to the flaky integration tests noted here: #1050

@elihart
Copy link
Contributor

elihart commented Sep 17, 2020

@pmecho if you rebase the tests should be fixed! then we can merge and get a release out

@elihart elihart merged commit 6b243e0 into airbnb:master Sep 17, 2020
@eboudrant
Copy link
Contributor

@eboudrant Eli was spot on. We're using an internal class for the visibility tracking when used outside of a RecyclerView. That's still sort of a work in progress but I totally agree that we should upstream it, along with how we use epoxy outside of RecylcerViews. Once I finish up with the tracking I can make another PR if that works.

Hi @pmecho ... when do you think it is a good time work on a new change to upstream the EpoxyViewBinder (outside of RV) and the visibility tracking? We use EpoxyViewBinder without visibility tracking but we may need it soon and I don't want to re-invent the wheel :)

@pmecho
Copy link
Collaborator Author

pmecho commented Feb 18, 2021

@eboudrant heh it keeps getting bumped down my priority list. This may be the nudge I needed though. I will work on it this next week and maybe have something by end of week or the beginning of the next. When are you thinking you'll need it?

@eboudrant
Copy link
Contributor

@pmecho the timing you propose works for me. I don't want to change your priorities list. I would say we would starts to need visibility in about a month. Thanks!

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.

3 participants