Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #76 from chrisbanes/cb/column-transition
Column aware Fragment transitions
- Loading branch information
Showing
8 changed files
with
505 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
app/src/main/java/me/banes/chris/tivi/ui/transitions/BabySlide.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2017 Google, 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. | ||
*/ | ||
|
||
package me.banes.chris.tivi.ui.transitions | ||
|
||
import android.animation.Animator | ||
import android.animation.ObjectAnimator | ||
import android.animation.PropertyValuesHolder | ||
import android.support.transition.TransitionValues | ||
import android.support.transition.Visibility | ||
import android.view.Gravity | ||
import android.view.View | ||
import android.view.ViewGroup | ||
|
||
class BabySlide( | ||
private val gravity: Int = Gravity.START, | ||
private val babyFraction: Float = 2f | ||
) : Visibility() { | ||
|
||
override fun onAppear(sceneRoot: ViewGroup, view: View, | ||
startValues: TransitionValues?, | ||
endValues: TransitionValues?): Animator { | ||
setupTranslation(view) | ||
view.alpha = 0f | ||
|
||
return ObjectAnimator.ofPropertyValuesHolder(view, | ||
PropertyValuesHolder.ofFloat(View.TRANSLATION_X, 0f), | ||
PropertyValuesHolder.ofFloat(View.ALPHA, 1f)) | ||
} | ||
|
||
override fun onDisappear(sceneRoot: ViewGroup, view: View, | ||
startValues: TransitionValues?, endValues: TransitionValues?): Animator { | ||
return ObjectAnimator.ofPropertyValuesHolder(view, | ||
translatePropValForGravity(view), | ||
PropertyValuesHolder.ofFloat(View.ALPHA, 0f)) | ||
} | ||
|
||
private fun translatePropValForGravity(view: View): PropertyValuesHolder = | ||
when (Gravity.getAbsoluteGravity(gravity, view.layoutDirection)) { | ||
Gravity.TOP -> PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, -view.height / babyFraction) | ||
Gravity.RIGHT -> PropertyValuesHolder.ofFloat(View.TRANSLATION_X, view.width / babyFraction) | ||
Gravity.BOTTOM -> PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, view.height / babyFraction) | ||
else -> PropertyValuesHolder.ofFloat(View.TRANSLATION_X, -view.width / babyFraction) | ||
} | ||
|
||
private fun setupTranslation(view: View) { | ||
when (Gravity.getAbsoluteGravity(gravity, view.layoutDirection)) { | ||
Gravity.TOP -> view.translationY = -view.height / babyFraction | ||
Gravity.RIGHT -> view.translationX = view.width / babyFraction | ||
Gravity.BOTTOM -> view.translationY = view.width / babyFraction | ||
else -> view.translationX = -view.width / babyFraction | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.