Add swap animation

This commit is contained in:
Jonas Lochmann 2023-02-06 01:00:00 +01:00
parent 2971e3f55d
commit ca0e33e942
No known key found for this signature in database
GPG key ID: 8B8C9AEE10FA5B36
2 changed files with 31 additions and 1 deletions

View file

@ -242,7 +242,7 @@ class MainActivity : AppCompatActivity(), ActivityViewModelHolder, U2fManager.De
if (isOpening) Transition.openScreen
else if (isClosing) Transition.closeScreen
else Transition.none
else Transition.swap
}
}
) { screen ->

View file

@ -1,6 +1,24 @@
/*
* TimeLimit Copyright <C> 2019 - 2023 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package io.timelimit.android.ui.animation
import androidx.compose.animation.*
import androidx.compose.animation.core.FastOutLinearInEasing
import androidx.compose.animation.core.LinearOutSlowInEasing
import androidx.compose.animation.core.tween
@OptIn(ExperimentalAnimationApi::class)
object Transition {
@ -15,6 +33,18 @@ object Transition {
targetContentZIndex = -1f
)
val swap = run {
val speed = 250
fun <T> phase1() = tween<T>(speed, 0, FastOutLinearInEasing)
fun <T> phase2() = tween<T>(speed, speed, LinearOutSlowInEasing)
ContentTransform(
initialContentExit = slideOutVertically(phase1()) { it / 2 } + fadeOut(phase1()),
targetContentEnter = slideInVertically(phase2()) { it / 2 } + fadeIn(phase2())
)
}
val none = ContentTransform(
targetContentEnter = EnterTransition.None,
initialContentExit = ExitTransition.None