A custom Shared Element Transition that automatically animates your views based on Figma Smart Animate

AutoAnimate

Platform
API
Maven Central
Join the chat at https://gitter.im/Aghajari/community

AutoAnimate is a custom Shared Element Transition that automatically animates your views based on Figma Smart Animate.

FragmentAFragmentBTransition

Supports:

  • Layout
  • Scale
  • Rotation
  • Translation
  • Background
  • Color
  • TextSize
  • TextColor
  • CornerRadius
  • Elevation

You can customize duration, delay, interpolator and every other properties!

Installation

AutoAnimate is available in the mavenCentral(), so you just need to add it as a dependency (Module gradle)

Gradle

implementation 'io.github.aghajari:AutoAnimate:1.0.2'

Maven

<dependency>
  <groupId>io.github.aghajari</groupId>
  <artifactId>AutoAnimate</artifactId>
  <version>1.0.2</version>
  <type>pom</type>
</dependency>

Usage

  • Step1: Create your fragments (or activities)
  • Step2: Design your layouts
  • Step3: Set sharedElementEnterTransition
  • Step4: Add your views to FragmentTransaction by addSharedElement
  • Step5: Done!
val autoAnimateTransition = AutoAnimateTransition.build(
    duration = 500,
    interpolator = OvershootInterpolator()
)

fragment.sharedElementEnterTransition = autoAnimateTransition
sharedElementReturnTransition = autoAnimateTransition

supportFragmentManager
    .beginTransaction()
    .addToBackStack(null)
    .addSharedElement(view, view.transitionName)
    .replace(R.id.container, fragment)
    .commit()

Example

  • Step1: Create FragmentA and its layout:
sample

Click to see FragmentA layout





  • Step2: Create FragmentB and its layout:
sample

Click to see FragmentB layout





  • Step3: Start FragmentB by clicking on shape and Done!

Click to see the source

private val autoAnimateTransaction = AutoAnimateTransaction.build(
    duration = 800,
    interpolator = OvershootInterpolator()
)




Customize Properties

private val autoAnimateTransaction = AutoAnimateTransaction.build(
    mapOf(
        "shape" to listOf(
            LayoutAutoAnimate().apply {
                maxFraction = 1f
            },
            BackgroundAutoAnimate().apply {
                interpolator = LinearInterpolator()
                duration = 400
            },
            ScaleYAutoAnimate(),
            ScaleXAutoAnimate().apply {
                startDelay = 200
            },
        )
    ),
    duration = 800,
    interpolator = OvershootInterpolator()
)
TransitionCustomized

Author

Amir Hossein Aghajari

SUPPORT ❤️

If you find this library useful, Support it by joining stargazers for this repository ⭐️

License

Copyright 2023 Amir Hossein Aghajari
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.

 Amir Hossein Aghajari • Email • GitHub

GitHub

View Github

Leave a Reply

Your email address will not be published. Required fields are marked *