-
Notifications
You must be signed in to change notification settings - Fork 663
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 spritz library and demo #32
Conversation
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 only glanced at the API and setup, will spend sometime later to look into the details, but I left some initial remarks.
settings.gradle
Outdated
include 'MapApiV2Demo' | ||
include 'MultipleContacts' | ||
include 'OptionalDependencies' | ||
include 'PinchZoomDetector' | ||
include 'simperAudioStreamer' | ||
include 'sms' | ||
include 'spritz' |
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.
Please let's not do this. There's literally no reason to include this in the root project. It's an anti-pattern coming from historical reasons, that we should not adopt going forward (happens the same with the dojo repo).
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 was merely adhering to what I read in there 😂
Done in 96a580d!
spritz/app/proguard-rules.pro
Outdated
@@ -0,0 +1,25 @@ | |||
# Add project specific ProGuard rules here. |
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.
Do we need this file?
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.
❌ in 4bfb165.
@@ -0,0 +1,25 @@ | |||
# Add project specific ProGuard rules here. |
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.
Lot of leftover from the IDE default wizard. Probably good idea to clean up.
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.
❌ in 4bfb165.
return this; | ||
} | ||
|
||
public Spritz attachTo(ViewPager viewPager) { |
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'm not a fan of this, it seems like we're trying to emphasise on fluent API missing flexibility and explicitness. I'd expect a Spritz
instance to implement ViewPager.OnPageChangeListener
and let the final user decide when to attach or detach it. (The latter case is not considered at all)
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'm actually ok with this being the point where you attach to a viewPager, but then we need a detach()
method on Spritz
itself as Toto suggests.
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.
Sorry I wasn't clear: I meant I'm not a fan to be built-in the builder. It should be part of the Spritz
instance API imo.
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.
Yeah I understood that, I meant I don't have a problem with that to be honest
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.
So @mr-archano what would be your idea for this API to be?
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 what @mr-archano means is removing attachTo
from the builder API and add it to the Spritz object returned by the builder API.
So you'll do:
Spritz sp = Spritz
.with(lottieAnimationView)
.withDefaultSwipeAnimationDuration(300, TimeUnit.MILLISECONDS)
.withDefaultSwipeForwardInterpolator(SWIPE_FORWARD_INTERPOLATOR)
.withSteps(...)
.build();
// Later on
sp.attachTo(viewPager);
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.
Or maybe he meant returning a ViewPager.OnPageChangeListener
and let the user setting it on the ViewPager
?
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
public class SpritzPage { |
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 reads "page" but it just contains only info about animation :/
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 Step
is clearer and clashes less with the ViewPager
's Page
domain?
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 in e2a51cd! 💯
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.
Nice library! Few comments to address tho.
@@ -0,0 +1,9 @@ | |||
*.iml |
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.
May I suggest using a more thorough .gitignore
? Like one from client projects, or Squanchy's.
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.
Shamelessly copied from squanchy: 62ad738
spritz/README.md
Outdated
|
||
After getting your `LottieAnimationView` and your `ViewPager`, just create a `Spritz` object with the following syntax: | ||
|
||
``` |
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 you put the language here so it does syntax highlighting?
```java
Same elsewhere.
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 in 7adc463.
spritz/README.md
Outdated
|
||
After that, you can proceed setting your view pager transitions. | ||
|
||
#### `withDefaultSwipeAnimationDuration` |
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 would rather go with a use-case oriented docs, not with a semi-javadoc-in-the-readme thing like this. E.g., Specify animation durations which would then have some explanation of what it means, and a list of the methods to achieve things.
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.
Shall I do this in my next PR?
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 ¯\_(ツ)_/¯
spritz/README.md
Outdated
#### `withDefaultSwipeBackwardsInterpolator` | ||
|
||
`withDefaultSwipeBackwardsInterpolator(TimeInterpolator swipeBackwardsInterpolator)` sets the interpolator to use for all pages to complete the swipe | ||
animation if the user stops dragging backwards at any point. If you don't set this, it will default to `LinearInterpolator`. You can always override |
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.
Double space: stops dragging
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 in 30085d0.
spritz/README.md
Outdated
|
||
#### `withPages` | ||
|
||
`withPages(SpritzPage... pages)` lets you specify the number of pages to animate through. The library is made to work with the same number of pages as |
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.
lets you specify the number of pages to animate through
I would also explain better the idea behind the next sentence, something like The number of pages you pass in must match the number of pages on the ViewPager
you'll attach Spritz
to
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 as part of e2a51cd.
return this; | ||
} | ||
|
||
public Spritz attachTo(ViewPager viewPager) { |
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'm actually ok with this being the point where you attach to a viewPager, but then we need a detach()
method on Spritz
itself as Toto suggests.
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
public class SpritzPage { |
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 Step
is clearer and clashes less with the ViewPager
's Page
domain?
return swipeBackwardsInterpolator; | ||
} | ||
|
||
static List<SpritzPageWithOffset> fromSpritzPages(SpritzPage... spritzPages) { |
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.
Not sure this should be here, I am not a fan of a (List<ModelA>) -> List<ModelB>
sitting in ModelB
. Would move to another class.
spritz/spritz-android/build.gradle
Outdated
compile 'com.android.support:design:26.1.0' | ||
compile 'com.airbnb.android:lottie:2.1.0' | ||
|
||
testCompile 'junit:junit:4.12' |
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 is unused too as far as I can tell
spritz/spritz-android/build.gradle
Outdated
} | ||
|
||
dependencies { | ||
compile 'com.android.support:appcompat-v7:26.1.0' |
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 both the support
dependencies here are unused
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 in f44b30d.
Nice! Only #32 (comment) and #32 (comment) left to address from me |
Comments by @rock3r addressed, waiting for @mr-archano for better API ideas. |
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.
A general comment on naming for the builder API.
Why so many withXXX
?
From my point of view the "with"
semantic is implicit the moment you call a method.
Why not removing most of them?
Spritz
.with(lottieAnimationView)
.defaultSwipeAnimationDuration(300, TimeUnit.MILLISECONDS)
.defaultSwipeForwardInterpolator(SWIPE_FORWARD_INTERPOLATOR)
.steps(
new SpritzStep.Builder()
.withAutoPlayDuration(500, TimeUnit.MILLISECONDS)
.withSwipeDuration(500, TimeUnit.MILLISECONDS)
.build(),
new SpritzStep.Builder()
.withAutoPlayDuration(500, TimeUnit.MILLISECONDS)
.withSwipeDuration(500, TimeUnit.MILLISECONDS)
.swipeBackwardsInterpolator(SWIPE_BACKWARDS_INTERPOLATOR)
.build(),
new SpritzStep.Builder()
.withAutoPlayDuration(500, TimeUnit.MILLISECONDS)
.build()
)
.attachTo(viewPager);
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 my concerns addressed 👍
spritz/build.gradle
Outdated
@@ -0,0 +1,23 @@ | |||
// Top-level build file where you can add configuration options common to all sub-projects/modules. |
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.
Good to know :D
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.
Removed in b2e8c6d.
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { | ||
|
||
@Override | ||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { |
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.
The only real business logic is in this method. Perhaps you can extract stuff and unit test it?
@mr-archano I slightly changed the API so that you build a
|
@lgvalle I can remove the |
@frapontillo I guess so. It's a discussion for a separate PR anyway in my opinion: once this is merged we can get philosophical with naming and improve it 👍 |
@mr-archano your comments have been addressed in 97a9682 after our talk IRL. @rock3r README is now more compact, see 6062a0f. Thanks to @chris95x8, we have a nice spritz icon that has been added to the demo app and to the README, see 98543eb and 6062a0f. @lgvalle I would extract the business logic in a following PR so we can properly test it 👍 . |
Spritz is a new library for seamlessly animating a Lottie view by swiping in a ViewPager.
Documentation
The root directory of the project has a
README
that explains how to use the library with a detailed list of all methods. The library doesn't have a Javadoc yet.GIF
The outcome is shown in the demo app:
Next steps
As soon as this library is merged on master, I'll add the
publish
plugin so we can release it as an open source library on maven.