Fix PullDownScaffold IME behavior

This commit is contained in:
MM20 2022-05-12 19:59:45 +02:00
parent d0328da2f9
commit 466b7c2384
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
3 changed files with 53 additions and 39 deletions

View File

@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
@ -23,6 +24,7 @@ import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
import com.afollestad.materialdialogs.callbacks.onDismiss
import com.afollestad.materialdialogs.customview.customView
import com.android.launcher3.GestureNavContract
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import de.mm20.launcher2.icons.DynamicIconController
import de.mm20.launcher2.ui.R
@ -31,6 +33,8 @@ import de.mm20.launcher2.ui.base.ProvideSettings
import de.mm20.launcher2.ui.component.NavBarEffects
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.LocalHomeTransitionManager
import de.mm20.launcher2.ui.theme.LauncherTheme
import org.koin.android.ext.android.inject
@ -39,6 +43,8 @@ class LauncherActivity : BaseActivity() {
private val viewModel: LauncherActivityVM by viewModels()
private val homeTransitionManager = HomeTransitionManager()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -47,44 +53,47 @@ class LauncherActivity : BaseActivity() {
viewModel.setDarkMode(resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES)
setContent {
LauncherTheme {
ProvideSettings {
val lightStatus by viewModel.lightStatusBar.observeAsState(false)
val lightNav by viewModel.lightNavBar.observeAsState(false)
val hideStatus by viewModel.hideStatusBar.observeAsState(false)
val hideNav by viewModel.hideNavBar.observeAsState(false)
val dimBackground by viewModel.dimBackground.observeAsState(false)
CompositionLocalProvider(
LocalHomeTransitionManager provides homeTransitionManager
) {
LauncherTheme {
ProvideSettings {
val lightStatus by viewModel.lightStatusBar.observeAsState(false)
val lightNav by viewModel.lightNavBar.observeAsState(false)
val hideStatus by viewModel.hideStatusBar.observeAsState(false)
val hideNav by viewModel.hideNavBar.observeAsState(false)
val dimBackground by viewModel.dimBackground.observeAsState(false)
val systemUiController = rememberSystemUiController()
val systemUiController = rememberSystemUiController()
LaunchedEffect(hideStatus) {
systemUiController.isStatusBarVisible = !hideStatus
}
LaunchedEffect(hideNav) {
systemUiController.isNavigationBarVisible = !hideNav
}
LaunchedEffect(hideStatus) {
systemUiController.isStatusBarVisible = !hideStatus
}
LaunchedEffect(hideNav) {
systemUiController.isNavigationBarVisible = !hideNav
}
Box(
modifier = Modifier
.fillMaxSize()
.background(if (dimBackground) Color.Black.copy(alpha = 0.30f) else Color.Transparent),
contentAlignment = Alignment.BottomCenter
) {
NavBarEffects(modifier = Modifier.fillMaxSize())
PagerScaffold(
Box(
modifier = Modifier
.fillMaxSize()
.systemBarsPadding()
.imePadding(),
darkStatusBarIcons = lightStatus,
darkNavBarIcons = lightNav,
)
}
val showHiddenItems by viewModel.isHiddenItemsShown.observeAsState(false)
if (showHiddenItems) {
HiddenItemsSheet(onDismiss = {
viewModel.hideHiddenItems()
})
.background(if (dimBackground) Color.Black.copy(alpha = 0.30f) else Color.Transparent),
contentAlignment = Alignment.BottomCenter
) {
NavBarEffects(modifier = Modifier.fillMaxSize())
PagerScaffold(
modifier = Modifier
.fillMaxSize()
.systemBarsPadding(),
darkStatusBarIcons = lightStatus,
darkNavBarIcons = lightNav,
)
}
val showHiddenItems by viewModel.isHiddenItemsShown.observeAsState(false)
if (showHiddenItems) {
HiddenItemsSheet(onDismiss = {
viewModel.hideHiddenItems()
})
}
}
}
}
@ -135,6 +144,11 @@ class LauncherActivity : BaseActivity() {
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
onBackPressed()
val navContract = intent?.let { GestureNavContract.fromIntent(it) }
if (navContract != null) {
homeTransitionManager.resolve(navContract)
} else {
onBackPressed()
}
}
}

View File

@ -7,10 +7,7 @@ import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.slideIn
import androidx.compose.animation.slideOut
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
@ -157,7 +154,8 @@ fun PagerScaffold(
size = it
}
.verticalScroll(searchScrollState, reverseScrolling = true)
.padding(start = 8.dp, end = 8.dp, top = 8.dp, bottom = 56.dp)
.imePadding()
.padding(start = 8.dp, end = 8.dp, top = 8.dp, bottom = 64.dp)
.padding(bottom = webSearchPadding),
reverse = true,
)
@ -223,6 +221,7 @@ fun PagerScaffold(
modifier = Modifier
.align(Alignment.BottomCenter)
.padding(start = 8.dp, end = 8.dp, bottom = 8.dp)
.imePadding()
.offset(y = widgetEditModeOffset),
level = searchBarLevel, focused = focusSearchBar, onFocusChange = {
if (it) viewModel.openSearch()

View File

@ -235,6 +235,7 @@ fun PullDownScaffold(
.padding(8.dp)
.padding(top = 56.dp)
.padding(top = webSearchPadding)
.imePadding()
)
}