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 spritz library and demo #32

Merged
merged 28 commits into from Sep 26, 2017
Merged

Add spritz library and demo #32

merged 28 commits into from Sep 26, 2017

Conversation

frapontillo
Copy link
Contributor

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:
spritz-demo

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.

@rock3r rock3r self-assigned this Sep 21, 2017
@rock3r rock3r self-requested a review September 21, 2017 09:52
Copy link
Contributor

@mr-archano mr-archano left a 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'
Copy link
Contributor

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).

Copy link
Contributor Author

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!

@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
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 this file?

Copy link
Contributor Author

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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

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)

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

@lgvalle lgvalle Sep 22, 2017

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);

Copy link
Contributor Author

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

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 :/

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in e2a51cd! 💯

Copy link
Contributor

@rock3r rock3r left a 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
Copy link
Contributor

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.

Copy link
Contributor Author

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:

```
Copy link
Contributor

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.

Copy link
Contributor Author

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`
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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

Choose a reason for hiding this comment

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

Double space: stops dragging

Copy link
Contributor Author

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

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

Copy link
Contributor Author

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

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

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

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.

compile 'com.android.support:design:26.1.0'
compile 'com.airbnb.android:lottie:2.1.0'

testCompile 'junit:junit:4.12'
Copy link
Contributor

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

}

dependencies {
compile 'com.android.support:appcompat-v7:26.1.0'
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in f44b30d.

@rock3r
Copy link
Contributor

rock3r commented Sep 22, 2017

Nice! Only #32 (comment) and #32 (comment) left to address from me

@frapontillo
Copy link
Contributor Author

Comments by @rock3r addressed, waiting for @mr-archano for better API ideas.

Copy link
Contributor

@lgvalle lgvalle left a 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);

Copy link
Contributor

@rock3r rock3r left a 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 👍

@@ -0,0 +1,23 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
Copy link
Contributor

Choose a reason for hiding this comment

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

Good to know :D

Copy link
Contributor Author

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

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?

@frapontillo
Copy link
Contributor Author

@mr-archano I slightly changed the API so that you build a Spritz instance first, then you can:

  • get the view page change listener and attach it/detach it yourself
  • start pending animations
    See d0615f0.

@frapontillo
Copy link
Contributor Author

frapontillo commented Sep 25, 2017

@lgvalle I can remove the with prefix, but then I would have to remove it from the SpritzStep.Builder too, right?

@lgvalle
Copy link
Contributor

lgvalle commented Sep 25, 2017

@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 👍

@frapontillo
Copy link
Contributor Author

@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 👍 .

@mr-archano mr-archano merged commit 0404907 into master Sep 26, 2017
@mr-archano mr-archano deleted the spritz branch September 26, 2017 15:32
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.

None yet

4 participants