Add transition when returning to home using gesture navigation
This commit is contained in:
parent
cf2f353441
commit
ff2c293ba6
@ -10,17 +10,17 @@ import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.livedata.observeAsState
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.geometry.Size
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsControllerCompat
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.flowWithLifecycle
|
||||
import com.afollestad.materialdialogs.LayoutMode
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
|
||||
@ -34,9 +34,11 @@ import de.mm20.launcher2.ui.R
|
||||
import de.mm20.launcher2.ui.base.BaseActivity
|
||||
import de.mm20.launcher2.ui.base.ProvideSettings
|
||||
import de.mm20.launcher2.ui.component.NavBarEffects
|
||||
import de.mm20.launcher2.ui.ktx.animateTo
|
||||
import de.mm20.launcher2.ui.launcher.modals.EditFavoritesView
|
||||
import de.mm20.launcher2.ui.launcher.modals.HiddenItemsSheet
|
||||
import de.mm20.launcher2.ui.launcher.transitions.HomeTransitionManager
|
||||
import de.mm20.launcher2.ui.launcher.transitions.HomeTransitionParams
|
||||
import de.mm20.launcher2.ui.launcher.transitions.LocalHomeTransitionManager
|
||||
import de.mm20.launcher2.ui.locals.LocalSnackbarHostState
|
||||
import de.mm20.launcher2.ui.locals.LocalWindowSize
|
||||
@ -79,6 +81,18 @@ class LauncherActivity : BaseActivity() {
|
||||
|
||||
val systemUiController = rememberSystemUiController()
|
||||
|
||||
val enterTransition = remember { mutableStateOf(1f) }
|
||||
|
||||
LaunchedEffect(null) {
|
||||
homeTransitionManager
|
||||
.currentTransition
|
||||
.flowWithLifecycle(lifecycle, Lifecycle.State.RESUMED)
|
||||
.collect {
|
||||
enterTransition.value = 0f
|
||||
enterTransition.animateTo(1f)
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(hideStatus) {
|
||||
systemUiController.isStatusBarVisible = !hideStatus
|
||||
}
|
||||
@ -93,12 +107,17 @@ class LauncherActivity : BaseActivity() {
|
||||
contentAlignment = Alignment.BottomCenter
|
||||
) {
|
||||
NavBarEffects(modifier = Modifier.fillMaxSize())
|
||||
when(layout) {
|
||||
when (layout) {
|
||||
Settings.AppearanceSettings.Layout.PullDown -> {
|
||||
PullDownScaffold(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.systemBarsPadding(),
|
||||
.systemBarsPadding()
|
||||
.graphicsLayer {
|
||||
scaleX = 0.5f + enterTransition.value * 0.5f
|
||||
scaleY = 0.5f + enterTransition.value * 0.5f
|
||||
alpha = enterTransition.value
|
||||
},
|
||||
darkStatusBarIcons = lightStatus,
|
||||
darkNavBarIcons = lightNav,
|
||||
)
|
||||
@ -107,7 +126,12 @@ class LauncherActivity : BaseActivity() {
|
||||
PagerScaffold(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.systemBarsPadding(),
|
||||
.systemBarsPadding()
|
||||
.graphicsLayer {
|
||||
scaleX = enterTransition.value
|
||||
scaleY = enterTransition.value
|
||||
alpha = enterTransition.value
|
||||
},
|
||||
darkStatusBarIcons = lightStatus,
|
||||
darkNavBarIcons = lightNav,
|
||||
)
|
||||
@ -116,7 +140,9 @@ class LauncherActivity : BaseActivity() {
|
||||
}
|
||||
SnackbarHost(
|
||||
snackbarHostState,
|
||||
modifier = Modifier.navigationBarsPadding().imePadding()
|
||||
modifier = Modifier
|
||||
.navigationBarsPadding()
|
||||
.imePadding()
|
||||
)
|
||||
}
|
||||
val showHiddenItems by viewModel.isHiddenItemsShown.observeAsState(false)
|
||||
|
||||
@ -1,13 +1,17 @@
|
||||
package de.mm20.launcher2.ui.launcher.transitions
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.compositionLocalOf
|
||||
import androidx.compose.ui.geometry.Rect
|
||||
import androidx.compose.ui.graphics.toAndroidRectF
|
||||
import com.android.launcher3.GestureNavContract
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
|
||||
class HomeTransitionManager {
|
||||
|
||||
val currentTransition = MutableSharedFlow<HomeTransitionParams?>(1)
|
||||
|
||||
private val handlers = mutableSetOf<HomeTransitionHandler>()
|
||||
|
||||
fun resolve(gestureNavContract: GestureNavContract) {
|
||||
@ -15,13 +19,11 @@ class HomeTransitionManager {
|
||||
val result = handler.handle(gestureNavContract)
|
||||
if (result != null) {
|
||||
gestureNavContract.sendEndPosition(result.targetBounds.toAndroidRectF())
|
||||
break
|
||||
currentTransition.tryEmit(result)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun dispatch(params: HomeTransitionParams) {
|
||||
|
||||
currentTransition.tryEmit(null)
|
||||
}
|
||||
|
||||
fun registerHandler(handler: HomeTransitionHandler) {
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
package de.mm20.launcher2.ui.launcher.transitions
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.ui.geometry.Rect
|
||||
|
||||
@Stable
|
||||
data class HomeTransitionParams(
|
||||
val targetBounds: Rect,
|
||||
val icon: (@Composable () -> Unit)? = null
|
||||
|
||||
@ -375,6 +375,7 @@ fun IconShapePreference(
|
||||
LocalContext.current,
|
||||
R.mipmap.ic_launcher_foreground
|
||||
)!!,
|
||||
foregroundScale = 1.5f,
|
||||
background = ColorDrawable(LocalContext.current.getColor(R.color.ic_launcher_background))
|
||||
),
|
||||
onClick = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user