Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cats-oss/android-tab-animation
Easily create TabLayout.Tab animations that sync with the scrolling progress of ViewPager
https://github.com/cats-oss/android-tab-animation
android animation tablayout viewpager viewpager2
Last synced: 3 days ago
JSON representation
Easily create TabLayout.Tab animations that sync with the scrolling progress of ViewPager
- Host: GitHub
- URL: https://github.com/cats-oss/android-tab-animation
- Owner: cats-oss
- License: apache-2.0
- Created: 2019-09-17T09:44:22.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-03-02T10:29:02.000Z (over 3 years ago)
- Last Synced: 2024-03-26T19:13:00.404Z (8 months ago)
- Topics: android, animation, tablayout, viewpager, viewpager2
- Language: Kotlin
- Size: 2.12 MB
- Stars: 104
- Watchers: 3
- Forks: 6
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tab Animation
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Release](https://img.shields.io/maven-central/v/jp.co.cyberagent.android/tab-animation)](https://search.maven.org/artifact/jp.co.cyberagent.android/tab-animation/)
![CI](https://github.com/cats-oss//android-tab-animation/workflows/Android%20CI/badge.svg)Easily create `TabLayout.Tab` animations that sync with the scrolling progress of `ViewPager`.
## Features
- Animate Tab when scrolling ViewPager
- Animate Tab after selected/unselected
- Support ViewPager and ViewPager2
- Create animations with DSL## Demo
|[Tab](sample/src/main/java/jp/co/cyberagent/android/tabanimationsample/TextTabActivity.kt)|[Indicator](sample/src/main/java/jp/co/cyberagent/android/tabanimationsample/IndicatorActivity.kt)|[Bottom Navigation](sample/src/main/java/jp/co/cyberagent/android/tabanimationsample/BottomNavigationActivity.kt)|
|-|-|-|
||||## Usage
### Gradle
```gradle
implementation 'jp.co.cyberagent.android:tab-animation:x.y.z'```
### Step 1
Create animation info for Tab:
```kotlin
val animationInfo = viewIdAnimationInfo {
animateText {
property(View.SCALE_X)
startValue(0.8f)
endValue(1f)
}
animateText {
property(View.SCALE_Y)
startValue(0.8f)
endValue(1f)
}
}
```### Step 2
Link the TabLayout, ViewPager and animation info:
```kotlin
// TabLayout extension function
tabLayout.setupAnimationTabWithViewPager(
viewPager,
animationInfo,
SimpleTab.TEXT
)
```## Advanced Usage
### Custom tab view
Provide the layout file id instead of SimpleTab:
```kotlin
tabLayout.setupAnimationTabWithViewPager(
viewPager,
animationInfo,
R.layout.my_custom_tab
) { tab, view, position ->
// bind data here
}
```### Custom animate target
Specify the target id in viewIdAnimationInfo:
```kotlin
viewIdAnimationInfo {
animate(R.id.my_view) {
...
}
}
```### Custom property
```kotlin
// Create tint property
animateIcon {
property(
getter = { ImageViewCompat.getImageTintList(this)!! },
setter = { ImageViewCompat.setImageTintList(this, it) }
)
...
}
```### Custom evaluator
Current support property types:
- Int (ARGB)
- Float
- IntArray
- FloatArray
- PointF
- Rect
- ColorStateListYou must specify the evaluator if the property type you want to animate is not listed:
```kotlin
animate {
evaluator(MyEvaluator)
...
}
```### Specify KeyFrames
```kotlin
animateText {
property(View.ALPHA)
startValue(0f)
endValue(1f)
keyFrame(0.8f, 0.2f)
}
```### Lazy value
Animation info will be evaluated after the layout of Tab.
You can calculate the value based on the view:```kotlin
animateIcon {
property(View.TRANSLATION_X)
startValue { view ->
view.width / 2f
}
endValue { 0f }
}
```## License
Copyright 2019 CyberAgent, 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 athttp://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.