-
Notifications
You must be signed in to change notification settings - Fork 176
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
Carousel helper infinite in MotionLayout by Rodrigo Dominguez #39
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 |
@@ -294,9 +312,36 @@ private void updateItems() { | |||
View view = mList.get(i); | |||
int index = mIndex + i - startIndex; | |||
if (index < 0) { | |||
updateViewVisibility(view, emptyViewBehavior); | |||
if (infiniteCarousel) { |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, refactoring done.
@@ -0,0 +1,49 @@ | |||
package androidx.constraintlayout.experiments |
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.
(c) notice missing
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.
Done ✅
@@ -85,6 +85,7 @@ | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably don't want to have all examples using infinite?
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while here, can you remove the printfs? :)
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.
Done✅
if (infiniteCarousel) { | ||
if (mIndex >= mAdapter.count()) { | ||
mIndex = 0; | ||
System.out.println("index capped... " + mIndex); |
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.
same thing, we can remove those printfs
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.
Done ✅
@@ -309,17 +360,19 @@ private void updateItems() { | |||
} | |||
|
|||
final int count = mAdapter.count(); |
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.
can move the count variable inside the if block, or maybe simpler, add if (infiniteCarousel) { return; } before final int count
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.
Done ✅
updateViewVisibility(view, emptyViewBehavior); | ||
} else if (index >= mAdapter.count()) { | ||
updateViewVisibility(view, emptyViewBehavior); | ||
if (infiniteCarousel) { |
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.
oh what I meant was more something like:
if (infiniteCarousel) {
index = index % mAdapter.count();
}
but that's fine.
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 add a new attribute to configure the infinite carousel.
app:carousel_infinite="true"
With this attribute, transition
backwardTransition
andforwardTransition
are 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