Permalink
Browse files

Merge pull request #76 from chrisbanes/cb/column-transition

Column aware Fragment transitions
  • Loading branch information...
chrisbanes committed Nov 17, 2017
2 parents b29dd38 + f30189c commit 8b6951371467744c9507fe1e680f4dd6f2f139ef
@@ -18,11 +18,14 @@ package me.banes.chris.tivi.home.discover
import android.arch.lifecycle.ViewModelProviders
import android.os.Bundle
import android.support.transition.Fade
import android.support.transition.TransitionSet
import android.support.v7.widget.GridLayoutManager
import android.view.LayoutInflater
import android.view.Menu
import android.view.View
import android.view.ViewGroup
import android.view.animation.LinearInterpolator
import com.xwray.groupie.GroupAdapter
import com.xwray.groupie.ViewHolder
import kotlinx.android.synthetic.main.fragment_summary.*
@@ -57,6 +60,24 @@ internal class DiscoverFragment : HomeFragment<DiscoverViewModel>() {
super.onCreate(savedInstanceState)
viewModel = ViewModelProviders.of(this, viewModelFactory).get(DiscoverViewModel::class.java)
homeNavigator = ViewModelProviders.of(activity!!, viewModelFactory).get(HomeNavigatorViewModel::class.java)
exitTransition = TransitionSet().apply {
addTransition(Fade().apply {
excludeTarget(R.id.summary_appbarlayout, true)
excludeTarget(R.id.summary_status_scrim, true)
interpolator = LinearInterpolator()
duration = 130
})
addTransition(Fade().apply {
interpolator = LinearInterpolator()
duration = 270
})
}
reenterTransition = Fade().apply {
interpolator = LinearInterpolator()
duration = 270
}
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
@@ -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.

0 comments on commit 8b69513

Please sign in to comment.