Add transition animation to timer form fragment

This commit is contained in:
William Brawner 2020-10-10 09:12:09 -07:00
parent fbf60ac13e
commit 35c1162262
9 changed files with 49 additions and 4 deletions

View file

@ -1,6 +1,22 @@
<component name="ProjectCodeStyleConfiguration"> <component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173"> <code_scheme name="Project" version="173">
<JetCodeStyleSettings> <JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value>
<package name="java.util" alias="false" withSubpackages="false" />
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
<package name="io.ktor" alias="false" withSubpackages="true" />
</value>
</option>
<option name="PACKAGES_IMPORT_LAYOUT">
<value>
<package name="" alias="false" withSubpackages="true" />
<package name="java" alias="false" withSubpackages="true" />
<package name="javax" alias="false" withSubpackages="true" />
<package name="kotlin" alias="false" withSubpackages="true" />
<package name="" alias="true" withSubpackages="true" />
</value>
</option>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" /> <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings> </JetCodeStyleSettings>
<codeStyleSettings language="XML"> <codeStyleSettings language="XML">

View file

@ -78,8 +78,8 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0' implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.transition:transition-ktx:1.4.0-beta01'
implementation 'com.google.android.material:material:1.2.0-alpha05' implementation 'com.google.android.material:material:1.3.0-alpha02'
implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0'

View file

@ -9,6 +9,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import com.google.android.material.transition.MaterialContainerTransform
import com.wbrawner.trainterval.R import com.wbrawner.trainterval.R
import com.wbrawner.trainterval.shared.IntervalTimer import com.wbrawner.trainterval.shared.IntervalTimer
import com.wbrawner.trainterval.timerform.IntervalTimerEditState.* import com.wbrawner.trainterval.timerform.IntervalTimerEditState.*
@ -47,6 +48,17 @@ class TimerFormFragment : Fragment() {
it.setSupportActionBar(toolbar) it.setSupportActionBar(toolbar)
it.supportActionBar?.setDisplayHomeAsUpEnabled(true) it.supportActionBar?.setDisplayHomeAsUpEnabled(true)
} }
val context = view.context
sharedElementEnterTransition = MaterialContainerTransform().apply {
duration = resources.getInteger(android.R.integer.config_longAnimTime).toLong()
fadeMode = MaterialContainerTransform.FADE_MODE_CROSS
scrimColor = resources.getColor(R.color.colorSurface, context.theme)
}
sharedElementReturnTransition = MaterialContainerTransform().apply {
duration = resources.getInteger(android.R.integer.config_longAnimTime).toLong()
fadeMode = MaterialContainerTransform.FADE_MODE_CROSS
scrimColor = resources.getColor(R.color.colorSurface, context.theme)
}
coroutineScope = CoroutineScope(Dispatchers.Main) coroutineScope = CoroutineScope(Dispatchers.Main)
coroutineScope!!.launch { coroutineScope!!.launch {
timerFormViewModel.timerState.observe(viewLifecycleOwner, Observer { state -> timerFormViewModel.timerState.observe(viewLifecycleOwner, Observer { state ->

View file

@ -6,11 +6,14 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.doOnPreDraw
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import androidx.navigation.fragment.FragmentNavigatorExtras
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.transition.MaterialElevationScale
import com.wbrawner.trainterval.R import com.wbrawner.trainterval.R
import com.wbrawner.trainterval.shared.IntervalTimer import com.wbrawner.trainterval.shared.IntervalTimer
import com.wbrawner.trainterval.timerlist.IntervalTimerListState.* import com.wbrawner.trainterval.timerlist.IntervalTimerListState.*
@ -33,6 +36,11 @@ class TimerListFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
postponeEnterTransition()
view.doOnPreDraw { startPostponedEnterTransition() }
exitTransition = MaterialElevationScale(false)
reenterTransition = MaterialElevationScale(true)
allowReturnTransitionOverlap = false
(activity as? AppCompatActivity)?.let { (activity as? AppCompatActivity)?.let {
it.setSupportActionBar(toolbar) it.setSupportActionBar(toolbar)
it.supportActionBar?.setDisplayHomeAsUpEnabled(false) it.supportActionBar?.setDisplayHomeAsUpEnabled(false)
@ -55,7 +63,12 @@ class TimerListFragment : Fragment() {
is EmptyListState -> renderEmptyList() is EmptyListState -> renderEmptyList()
is SuccessListState -> renderSuccessState(state.timers) is SuccessListState -> renderSuccessState(state.timers)
is ErrorState -> renderErrorState(state.message) is ErrorState -> renderErrorState(state.message)
is CreateTimer -> findNavController().navigate(R.id.timerFormFragment) is CreateTimer -> findNavController().navigate(
R.id.timerFormFragment,
null,
null,
FragmentNavigatorExtras(addTimerButton to "fabContainer")
)
is EditTimer -> findNavController().navigate(R.id.timerFormFragment) is EditTimer -> findNavController().navigate(R.id.timerFormFragment)
is OpenTimer -> findNavController().navigate( is OpenTimer -> findNavController().navigate(
R.id.activeTimerFragment, R.id.activeTimerFragment,

View file

@ -1,11 +1,13 @@
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/timerFormFragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:animateLayoutChanges="true" android:animateLayoutChanges="true"
android:fillViewport="true" android:fillViewport="true"
android:fitsSystemWindows="true" android:fitsSystemWindows="true"
android:transitionName="fabContainer"
tools:context="com.wbrawner.trainterval.timerform.TimerFormFragment"> tools:context="com.wbrawner.trainterval.timerform.TimerFormFragment">
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView

View file

@ -47,6 +47,7 @@
android:layout_gravity="bottom|end" android:layout_gravity="bottom|end"
android:layout_margin="16dp" android:layout_margin="16dp"
android:src="@drawable/ic_add" android:src="@drawable/ic_add"
android:transitionName="fabContainer"
android:visibility="gone" android:visibility="gone"
app:backgroundTint="@color/colorAccent" app:backgroundTint="@color/colorAccent"
tools:visibility="visible" /> tools:visibility="visible" />

View file

@ -8,6 +8,7 @@
<item name="colorAccent">@color/colorAccent</item> <item name="colorAccent">@color/colorAccent</item>
<item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item> <item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowContentTransitions">true</item>
</style> </style>
</resources> </resources>

View file

@ -11,7 +11,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.0.1' classpath 'com.android.tools.build:gradle:4.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong

0
gradlew vendored Normal file → Executable file
View file