Carousel helper infinite in MotionLayout by Rodrigo Dominguez#39
Conversation
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
|
@googlebot I signed it! |
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
1 similar comment
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
|
@googlebot I fixed it |
|
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
1 similar comment
|
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
|
@googlebot I consent |
| int index = mIndex + i - startIndex; | ||
| if (index < 0) { | ||
| updateViewVisibility(view, emptyViewBehavior); | ||
| if (infiniteCarousel) { |
There was a problem hiding this comment.
instead of this -- would it be simpler to check if infiniteCarousel is true and then compute index as the modulo of the count? then the bulk of the code would stay the same
There was a problem hiding this comment.
Great, refactoring done.
| @@ -0,0 +1,49 @@ | |||
| package androidx.constraintlayout.experiments | |||
| app:carousel_backwardTransition="@+id/backward" | ||
| app:carousel_previousState="@+id/previous" | ||
| app:carousel_nextState="@+id/next" | ||
| app:carousel_infinite="true" |
There was a problem hiding this comment.
we probably don't want to have all examples using infinite?
There was a problem hiding this comment.
I have left four infinite examples, and three normals.
| button.setOnClickListener(v -> { | ||
| Intent intent = new Intent(mainActivity, CarouselHelperActivity.class); | ||
| mainActivity.startActivity(intent); | ||
| }); |
There was a problem hiding this comment.
Might be worth instead to modify the Loader.normalMenuStartUp to get an array of activity classes as a parameter instead, and then add them? Something around those lines, so that next demo that wants to be a separate activity would be easy to add.
There was a problem hiding this comment.
Refactoring done, in MainActivity you can load the activity classes with examples activitiesDemo
| @@ -143,13 +149,24 @@ public void onTransitionCompleted(MotionLayout motionLayout, int currentId) { | |||
| mIndex--; | |||
| System.out.println("decrement index..."); | |||
There was a problem hiding this comment.
while here, can you remove the printfs? :)
| if (infiniteCarousel) { | ||
| if (mIndex >= mAdapter.count()) { | ||
| mIndex = 0; | ||
| System.out.println("index capped... " + mIndex); |
There was a problem hiding this comment.
same thing, we can remove those printfs
| @@ -309,17 +360,19 @@ private void updateItems() { | |||
| } | |||
|
|
|||
| final int count = mAdapter.count(); | |||
There was a problem hiding this comment.
can move the count variable inside the if block, or maybe simpler, add if (infiniteCarousel) { return; } before final int count
| updateViewVisibility(view, emptyViewBehavior); | ||
| } else if (index >= mAdapter.count()) { | ||
| updateViewVisibility(view, emptyViewBehavior); | ||
| if (infiniteCarousel) { |
There was a problem hiding this comment.
oh what I meant was more something like:
if (infiniteCarousel) {
index = index % mAdapter.count();
}
but that's fine.
I add a new attribute to configure the infinite carousel.
app:carousel_infinite="true"With this attribute, transition
backwardTransitionandforwardTransitionare enabled always.The iteration of the items is given in the same way as the following sequence: [1, 2, 3, 4, 5, 1, 2, 3, 4, 5].
Demos