Description
Transition X aims to simplify construction of Transition instances for using with TransitionManager available since API 19 and now available upto API 14 via AndroidX.
TransitionManager makes it easy to animate simple changes to layout without needing to explicitly calculate and specify from and to like Animator or Animation expects. When you call TransitionManager.beginDelayedTransition(layout, transition) before updating a layout, the framework automatically does a diff on before and after states and animates the difference.
Transition X is intended to simplify construction of these Transition instances to take full advantage of the framework and provide a clear, concise, type safe and extensible DSL.
Transition X alternatives and similar packages
Based on the "Kotlin" category.
Alternatively, view Transition X alternatives based on common mentions on social networks and blogs.
-
android-youtube-player
YouTube Player library for Android and Chromecast, stable and customizable. -
CalendarView
A highly customizable calendar view and compose library for Android. -
Balloon
:balloon: Modernized and sophisticated tooltips, fully customizable with an arrow and animations for Android. -
Kotterknife
Android view injection writen in Kotlin based on ButterKnife -
Shortbread
Android library that creates app shortcuts from annotations -
kotlin-android-template
Android + Kotlin + Github Actions + ktlint + Detekt + Gradle Kotlin DSL + buildSrc = โค๏ธ -
NotyKT ๐๏ธ
๐ NotyKT is a complete ๐Kotlin-stack (Backend + Android) ๐ฑ application built to demonstrate the use of Modern development tools with best practices implementation๐ฆธ. -
Material Chip View
Material Chip view. Can be used as tags for categories, contacts or creating text clouds -
DrawableToolbox
๐ ๏ธ The missing drawable toolbox for Android. Create drawables programmatically and get rid of the boring and always repeated drawable.xml files. -
Navigation Toolbar for Android
:octocat: Navigation toolbar is a slide-modeled UI navigation controller made by @Ramotion -
CodeView
Display code with syntax highlighting :sparkles: in native way. -
Carousel Recyclerview
Carousel Recyclerview let's you create carousel layout with the power of recyclerview by creating custom layout manager. -
Pluto Debug Framework
Pluto is a on-device debugging framework for Android applications, which helps in inspection of HTTP requests/responses, capture Crashes and ANRs and manipulating application data on-the-go. -
CrunchyCalendar โ awesome calendar widget for android apps
A beautiful material calendar with endless scroll, range selection and a lot more! -
MaterialTimelineView
With MaterialTimelineView you can easily create a material looking timeline. -
sliding-panel
Android sliding panel that is part of the view hierarchy, not above it. -
Android Kotlin Samples
Some basic samples of Kotlin for Android -
MaterialDrawerKt
A Kotlin DSL wrapper around the mikepenz/MaterialDrawer library. -
Pdf Viewer For Android
A Lightweight PDF Viewer Android library which only occupies around 125kb while most of the Pdf viewer occupies up to 16MB space. -
Capturable
๐Jetpack Compose utility library for capturing Composable content and transforming it into Bitmap Image๐ผ๏ธ -
SSComposeCookBook
A Collection of major Jetpack compose UI components which are commonly used.๐๐๐ -
Only
:bouquet: An easy way to persist and run code block only as many times as necessary on Android. -
Swagger Gradle Codegen
๐ซ A Gradle Plugin to generate your networking code from Swagger -
SSCustomBottomNavigation
Animated TabBar with native control and Jetpack Navigation support..โจ๐๐ -
EasyPermissions-ktx
๐ Kotlin version of the popular google/easypermissions wrapper library to simplify basic system permissions logic on Android M or higher. -
Awesome Jetpack compose
A collaborative list of awesome jetpack compose resources. -
DeviceInfo-Sample
[Android Library] Get easy access to device information super fast, real quick -
Permission Flow for Android
Know about real-time state of a Android app Permissions with Kotlin Flow APIs. -
CameraViewEx
Easy Android camera integration, advanced features. -
Aimybox voice assistant
Embeddable custom voice assistant for Android applications -
Nextflix-Composable
Includes jetpack compose, navigation, paging, hilt, retrofit, coil, coroutines, flow.. -
Intro Showcase View
Highlight different features of the app using Jetpack Compose -
Events Calendar
Events Calendar is a user-friendly library that helps you achieve a cool Calendar UI with events mapping. You can customise every pixel of the calendar as per your wish and still achieve in implementing all the functionalities of the native android calendar in addition with adding dots to the calendar which represents the presence of an event on the respective dates. It can be done easily, you are just a few steps away from implementing your own badass looking Calendar for your very own project! -
ZoomHelper
ZoomHelper will make any view to be zoomable just like Instagram pinch-to-zoom -
SSCustomEditTextOutLineBorder
Same as the Outlined text fields presented on the Material Design page but with some dynamic changes. ๐ ๐ -
Turtle ๐ข
Run shell commands from a Kotlin script or application with ease -
Vanilla Place Picker
Simple(vanilla) yet 'Do it all' place picker for your place picking needs in Android -
Maildroid
Maildroid is a small robust android library for sending emails using SMTP server -
Mutekt
Simplify mutating "immutable" state models (a Kotlin multiplatform library) -
Crowdin Android SDK
Crowdin Android SDK delivers all new translations from Crowdin project to the application immediately -
TimelineView
A customizable and easy-to-use Timeline View library for Android. Works as a RecyclerView decorator (ItemDecoration) -
Compose Compiler Reports to HTML Generator
A utility (Gradle Plugin + CLI) to convert Jetpack Compose compiler metrics and reports to beautified HTML page.
Appwrite - The Open Source Firebase alternative introduces iOS support
Do you think we are missing an alternative of Transition X or a related project?
README
Transition X
Kotlin DSL for choreographing Android Transitions
TransitionManager
makes it easy to animate simple changes to layout without needing to explicitly calculate and specify from
and to
like Animator
or Animation
expects. When you call TransitionManager.beginDelayedTransition(layout, transition)
before updating a layout, the framework automatically does a diff on before and after states and animates the difference.
Transition X
is intended to simplify construction of these Transition
instances to take full advantage of the framework and provide a clear, concise, type safe and extensible DSL using Kotlin language features.
I highly recommend reading the introduction blog post on my blog.
Download
- Add repository to your project level
build.gradle
file.
allprojects {
repositories {
jcenter()
}
}
- Add library dependency to module level
build.gradle
file.
dependencies{
implementation 'in.arunkumarsampath:transition-x:1.1.0'
}
Introduction
As shown above, instead of creating XML files and later inflating them using TransitionInflator
, it is possible to create Transition
instances directly using tranistionSet{}
block provided by the DSL.
With Transition X, the construction and usage can be greatly simplified with a prepareTransition
extension added to ViewGroup
.
For example:
constraintLayout.prepareTransition {
fadeOut {
startDelay = 100
}
moveResize {
pathMotion = ArcMotion()
}
fadeIn()
+textView // Add textView as target using '+' operator
exclude<RecyclerView>() // Exclude all recyclerViews
ease {
standardEasing // Applies FastOutSlowInInterpolator
}
}
// Performing layout changes here will be animated just like
// calling TransitionManager.beginDelayedTransition()
All blocks are type-safe and has IDE auto complete support thanks to Kotlin.
Getting Started
Writing your first transition
TransitionSet's can be built programmatically like shown below.
val transition = TransitionSet().apply {
addTransition(ChangeBounds().apply {
startDelay = 100
setPathMotion(ArcMotion())
})
}
The Transition X equivalent would be:
val transition = transitionSet {
moveResize {
startDelay = 100
pathMotion = ArcMotion()
}
}
Some of the transition names are opinionated to better express their intent and promote clear code. Here ChangeBounds
transition usually animates a View
's height, width, or location on screen hence the name moveResize
to better convey what it does.
Working with custom transitions
In case you have a custom transition class and want to use with the DSL, it is easy to do so.
- If your transition has a
public no arg
constructor then the transition can be added usingcustomTransition<Type: Transition>{}
method, transition-x takes care of instantiating the transition. Below example shows usage ofChangeCardColor
which animates aCardView
'scardBackground
property.
constraintLayout.prepareTransition {
customTransition<ChangeCardColor> {
+colorChangeCardView
}
}
- If your transition does not have
public no arg
constructor then, you can instantiate the transition yourself and then usecustomTransition(transition) {}
instead to add the transition and configure it.
Accessing custom properties
In addition to the common properties like startDelay
, interpolator
, etc, if your transition has custom properties then customProperties {}
block can be used.
constraintLayout.prepareTransition {
customTransition<ChangeCardColor> {
+colorChangeCardView
customProperties {
myProperty = "hi"
}
}
}
Adding, removing and excluding targets
The DSL provides simplified syntax to deal with targets by talking to Transition
's add/exclude/remove API.
- Use
+
operator oradd()
to add targets of typeString (Transition Name)
orView
orResource Id
.
transitionSet {
+"TransitionName"
+userIconView
add(userIconView)
}
- Use
-
operator orremove()
to remove targets of typeString (Transition Name)
orView
orResource Id
.
transitionSet {
-"TransitionName"
-userIconView
remove(userIconView)
}
exclude
andexcludeChildren
methods are provided for excluding targets which can be useful in advanced transitions. It can be used onViews
,Resource Ids
orType
transitionSet {
exclude<RecyclerView>()
exclude(R.id.accentBackground)
excludeChildren(constraintLayout)
}
Interpolators
- Interpolators can be directly added using
interpolator
property.
transitionSet {
moveResize()
slide()
interpolator = FastOutLinearInInterpolator()
}
- Easing - DSL provides a dedicated
ease
block to add interpolators recommended by material design spec.standardEasing
- Recommended for views that move within visible area of the layout. UsesFastOutSlowInInterpolator
decelerateEasing
- Recommended for views that appear/enter outside visible bounds of the layout. UsesLinearOutSlowInInterpolator
accelerateEasing
- Recommended for Views that exit visible bounds of the layout. UsesFastOutLinearInInterpolator
transitionSet {
moveResize()
ease {
decelerateEasing
}
}
Nesting transitions
Often, for fined grained transitions it it necessary to add different transition sets for different targets. It is simple to nest multiple transition sets just by using transitionSet {}
recursively.
transitionSet {
auto {
+"View 1"
}
transitionSet {
moveResize()
slide()
+"View 2"
}
transitionSet {
sequentially()
fadeOut()
moveResize()
fadeIn()
}
}
Adding listeners to transitions
Transition-X makes it easy to react to Transition
lifecycle by providing lifecycle methods like onEnd
, onStart
which internally uses Transition.addListener
.
Example:
rootCoordinatorLayout.prepareTransition {
onStart {
// Transition Started!
}
moveResize {
+image1
}
onEnd {
// Transition Ended!
}
}
Additional transitions
The library packages additional transitions not present in the support library and the plan is to add more commonly used transitions to provide a full package. Currently the following transitions are packaged:
ChangeText
: Animates changes to aTextView.text
property.ChangeColor
: Animates changes toView.background
if it is aColorDrawable
or changes toTextView.textColor
if the target is aTextView
.
Samples
Sample DSL Demo Snackbar animation Snackbar is anchored below FAB. moveResize is used on on FAB since its position changes. Slide is used on Snackbar since it's visibility changes. constraintLayout.prepareTransition { moveResize { +fab } slide { +snackbarMessage } ease { decelerateEasing } } snackbarMessage.toggleGone() Cascade animation It is possible to write normal logical code in the prepareTransition block. Here we add moveResize using loops and by adding a start delay based on position, we can emulate a cascade transition. constraintLayout.prepareTransition { texts.forEachIndexed { position, view -> moveResize { +view startDelay = ((position + 1) * 150).toLong() } } moveResize { +fab } ease { decelerateEasing } } // Layout changes (if (defaultState) constraint1 else constraint2) .applyTo(constraintLayout) Custom Transition In the following example, ChangeCardColor is a custom transition that animates cardBackgroundColor property of MaterialCardView . constraintLayout.prepareTransition { customTransition<ChangeCardColor> { +cardView } changeColor { +textView } duration = 1000 } // Layout changes cardView.setCardBackgroundColor(color) textView.setTextColor(calcForegroundWhiteOrBlack(color)) Arc motion Here the imageView's gravity is changed from START | CENTER_VERTICAL to TOP | CENTER_HORIZONTAL. By using a pathMotion it is possible to control the motion of the animation to follow material guidelines' arc motion. frameLayout.prepareTransition { moveResize { pathMotion = ArcMotion() +userIconView } } Advanced choreography By using techniques above and coupling it with further customization via lifecycle listeners such as onEnd or onPause it is possible to have finer control over the entire transition process. In the example below, notice how different views are configured with different parameters for transition type, interpolation and ordering. constraintLayout.prepareTransition { auto { ease { standardEasing } exclude(metamorphosisDesc2) } transitionSet { fade() slide() ease { accelerateEasing } +metamorphosisDesc2 } changeImage { add(*imageViews) } onEnd { constraintLayout.prepareTransition { moveResize() changeText { +collapseButton changeTextBehavior = ChangeText.CHANGE_BEHAVIOR_OUT_IN } } collapseButton.setText(R.string.collapse) } duration = 300 } expandConstraint.applyTo(constraintLayout) metamorphosisDesc2.isGone = false metamorphosisDesc.isGone = true Shared element transition Transition instances created by the DSL can be directly used with activity.window.sharedElementEnterTransition or fragment.sharedElementEnterTransition. fragment.sharedElementEnterTransition = transitionSet { transitionSet { changeImage() moveResize() changeClipBounds() scaleRotate() ease { standardEasing } duration = 375 +cartItem.cartImageTransitionName() } transitionSet { ease { standardEasing } moveResize() scaleRotate() add(cartItem.name, cartItem.price) duration = 375 } } Demo - WIP. Example Animated Bottom Navigation Bottom navigation animation implmentend using custom choreography instead of relying on AutoTransition. The implementation uses ConstraintLayout to define the layouts and then simply show/hides the labels and adds tint to the icons. TransitionManager does the rest.
transitionSet {
fadeOut()
moveResize {
startDelay = 50
ease {
standardEasing
}
}
fadeIn {
startDelay = 50
}
changeColor {
navItems.map { it.text }.forEach { text -> add(text) }
+constraintLayout
}
customTransition<ChangeImageTint> {
navItems.map { it.icon }.forEach { icon -> add(icon) }
}
}
Tasks
- [x] Initial release of Kotlin DSL
- [x] Provide samples for Shared Element Transitions
- [x] Package common transition within the library module
- [ ] Add wiki with best practices and gotchas.
Contributions
Contributions are welcome! I would greatly appreciate creating an issue to discuss major changes before submitting a PR directly. How you can help:
- Improving test coverage.
- Finding the DSL not sufficient for your case? Create an issue so we can discuss.
- Adding more animation samples to the sample app.
License
Copyright 2019, Arunkumar.
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.
*Note that all licence references and agreements mentioned in the Transition X README section above
are relevant to that project's source code only.