Giter Site home page Giter Site logo

florent37 / kotlinpleaseanimate Goto Github PK

View Code? Open in Web Editor NEW
558.0 14.0 40.0 4.88 MB

Kotlin, please, can you animate my views ?

License: Apache License 2.0

Kotlin 98.53% Java 1.30% Shell 0.17%
kotlin animate view animation animator java interpolator duration design material

kotlinpleaseanimate's Introduction

Kotlin Please Animate

Android Arsenal CircleCI Language

Kotlin, please, can you animate my views ?

A Kotlin way to declare and run beautiful animations ! Please be gentle with Kotlin :)

Android app on Google Play

gif

please {
   animate(avatar) toBe {
      bottomOfItsParent(marginDp = 36f)
      leftOfItsParent(marginDp = 16f)
      width(40, keepRatio = true, toDp = true)
   }
}.start()

Download

Buy Me a Coffee at ko-fi.com

In your module Download

implementation 'com.github.florent37:kotlinpleaseanimate:1.0.2'

This code describe the video above

please(duration = 1500L) {
   animate(avatar) toBe {
      bottomOfItsParent(marginDp = 36f)
      leftOfItsParent(marginDp = 16f)
      visible()
      width(40, keepRatio = true, toDp = true)
   }
   animate(name) toBe {
      rightOf(avatar, marginDp = 16f)
      sameCenterVerticalAs(avatar)
      textColor(Color.WHITE)
   }
   animate(subname) toBe {
      rightOf(name, marginDp = 5f)
      sameCenterVerticalAs(name)
      textColor(Color.WHITE)
   }
   animate(revert) toBe {
      rightOfItsParent(marginDp = 4f)
      bottomOfItsParent(marginDp = 12f)
      backgroundAlpha(0f)
   }
   animate(start) toBe {
      aboveOf(revert, marginDp = 4f)
      rightOfItsParent(marginDp = 4f)
      backgroundAlpha(0f)
   }
   animate(bottomLayout) toBe {
      originalPosition()
   }
   animate(content) toBe {
      originalPosition()
      visible()
   }
}.start()

Follow scroll

gif

Use setPercent to apply modify the current step of the animation

Exemple with a scrollview

val animation = please {
        animate(avatar) toBe {
           topOfItsParent(marginDp = 20f)
           leftOfItsParent(marginDp = 20f)
           scale(0.5f, 0.5f)
        }

        animate(username) toBe {
           rightOf(avatar, marginDp = 16f)
           sameCenterVerticalAs(avatar)

           alpha(0.5f)
        }

        animate(revert) toBe {
           rightOfItsParent(marginDp = 20f)
           sameCenterVerticalAs(avatar)
        }

        animate(background) toBe {
           height(h, horizontalGravity = Gravity.LEFT, verticalGravity = Gravity.TOP)
        }
}
scrollview.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
    val percent = scrollY * 1f / v.maxScrollAmount
    animation.setPercent(percent)
})

Chain animations

Just ask the kotlin's animation if he wants to execute another animation after, using thenCouldYou animate

please(duration = 1000L) {
   animate(image, withCameraDistance = 500f) toBe {
      flippedHorizontally()
   }
}.thenCouldYou(duration = 500L) {
   animate(image, withCameraDistance = 1000f) toBe {
      alpha(0.5f)
   }
}.start()

Apply directly

If you want your animation to be applied directly, be bossy with kotlin and force it to apply it using now() !

please {
   animate(view) toBe {
      outOfScreen(Gravity.BOTTOM)
   }
}.now();

Reset

Use reset to return to the initial state of views

animation.reset():

List of expectations

please {
  animate(view) { //toBe is optional

     rightOf(view, marginDp=)
     leftOf(view, marginDp=)
     belowOf(view, marginDp=)
     aboveOf(view, marginDp=)

     originalPosition()

     sameCenterAs(view, horizontal=, vertical=)
     sameCenterHorizontalAs(view)
     sameCenterVerticalAs(view)
     centerInParent(horizontal=, vertical=)
     centerVerticalInParent()
     centerHorizontalInParent()

     centerBetweenViews(view1, view2, horizontal, vertical)
     centerBetweenViewAndParent(otherView, horizontal, vertical, toBeOnRight, toBeOnBottom)

     topOfItsParent()
     rightOfItsParent()
     bottomOfItsParent()
     leftOfItsParent()

     alignBottom(otherView, marginDp=)
     alignTop(otherView)
     alignLeft(otherView)
     alignRight(otherView)

     outOfScreen(gravitiy)  //Gravity.LEFT / Gravity.RIGHT / Gravity.TOP / Gravity.BOTTOM

     alpha(alpha)
     sameAlphaAs(otherView)
     visible()
     invisible()

     custom(object: CustomAnimExpectation(){ ... })

     originalScale()

     scale(scaleX, scaleY)
     height(height, keepRatio=, useDp=)
     width(width, keepRatio=, useDp=)
     sameScaleAs(otherView)
     sameWidthAs(otherView)
     sameHeightAs(otherView)

     marginTop(margin)
     marginBottom(margin)
     marginRight(margin)
     marginLeft(margin)

     paddingTop(padding)
     paddingBottom(padding)
     paddingRight(padding)
     paddingLeft(padding)

     textColor(textColor)
     textSize(textSize)
     backgroundAlpha(alpha)

     rotated(rotation)
     vertical(bottomOfViewAtLeft)
     atItsOriginalRotation()
}

Credits

Author: Florent Champigny

Blog : http://www.tutos-android-france.com/

Fiches Plateau Moto : https://www.fiches-plateau-moto.fr/

Forked from ExpectAnim: https://github.com/florent37/ExpectAnim

Android app on Google Play Follow me on Google+ Follow me on Twitter Follow me on LinkedIn

License

Copyright 2018 florent37, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

kotlinpleaseanimate's People

Contributors

florent37 avatar mcgalanes avatar rhysmcknz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kotlinpleaseanimate's Issues

Ability to create customAnimations

Hi, first of all awesome library, makes animation much more fun!

To the question:

I'm trying to create other animations that are missing or for custom view.
I can do that by extending CustomAnimExpectation but I cannot add it to Expectations like all the other already present, because the list variable "expectations" is internal and not accessible.

Can we have it public?
I think having the possibility to create custom animations on the fly (and contribute to the project) would add a lot of value to this lib.

Thanks in advance for the response.

kotlin-stdlib-jdk7

hi
kotlin-stdlib-jre7/1.2.30/kotlin-stdlib-jre7-1.2.30.jar: kotlin-stdlib-jre7 is deprecated.
Please use kotlin-stdlib-jdk7 instead

API Naming inconsistencies - pronoun usage

Some of the API's use His while another use Its. Stay consistent.

Why did you change from no pronouns in the Java version of the API to pronouns in the Kotlin version? I suggest you use Its if you want a pronoun, or just drop it completely (suggested). I don't usually think of a guy when I think about my views.

Scroll Type Animation doesn't restore properly when state is lost (e.g. Don't Keep Activities Enabled)

I'm using an animation similar to the AnimScrollActivity and ran into issue when I tested restoring my app from state loss.

In developer settings I turned on "Don't keep activities" and then I opened the app and scrolled the activity all the way up which works as expected. I then leave the app and return, and the animation is now like this

afterreturning

If I then scroll, it turns into this

afterscrolling

I've tried things like adding this into the onCreate but it causes an animation at the start, and still doesn't fully place items in the correct spots, and if I take it out of the post, it's wrong right away.

 scrollview.post {
            scrollview.scrollTo(0, 0)
            animation.reset()
 }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.