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.fillMaxSize
import androidx.compose.foundation.layout.imePadding import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.systemBarsPadding import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState 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.bottomsheets.BottomSheet
import com.afollestad.materialdialogs.callbacks.onDismiss import com.afollestad.materialdialogs.callbacks.onDismiss
import com.afollestad.materialdialogs.customview.customView import com.afollestad.materialdialogs.customview.customView
import com.android.launcher3.GestureNavContract
import com.google.accompanist.systemuicontroller.rememberSystemUiController import com.google.accompanist.systemuicontroller.rememberSystemUiController
import de.mm20.launcher2.icons.DynamicIconController import de.mm20.launcher2.icons.DynamicIconController
import de.mm20.launcher2.ui.R 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.component.NavBarEffects
import de.mm20.launcher2.ui.launcher.modals.EditFavoritesView import de.mm20.launcher2.ui.launcher.modals.EditFavoritesView
import de.mm20.launcher2.ui.launcher.modals.HiddenItemsSheet 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 de.mm20.launcher2.ui.theme.LauncherTheme
import org.koin.android.ext.android.inject import org.koin.android.ext.android.inject
@ -39,6 +43,8 @@ class LauncherActivity : BaseActivity() {
private val viewModel: LauncherActivityVM by viewModels() private val viewModel: LauncherActivityVM by viewModels()
private val homeTransitionManager = HomeTransitionManager()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -47,6 +53,9 @@ class LauncherActivity : BaseActivity() {
viewModel.setDarkMode(resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES) viewModel.setDarkMode(resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES)
setContent { setContent {
CompositionLocalProvider(
LocalHomeTransitionManager provides homeTransitionManager
) {
LauncherTheme { LauncherTheme {
ProvideSettings { ProvideSettings {
val lightStatus by viewModel.lightStatusBar.observeAsState(false) val lightStatus by viewModel.lightStatusBar.observeAsState(false)
@ -74,8 +83,7 @@ class LauncherActivity : BaseActivity() {
PagerScaffold( PagerScaffold(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.systemBarsPadding() .systemBarsPadding(),
.imePadding(),
darkStatusBarIcons = lightStatus, darkStatusBarIcons = lightStatus,
darkNavBarIcons = lightNav, darkNavBarIcons = lightNav,
) )
@ -89,6 +97,7 @@ class LauncherActivity : BaseActivity() {
} }
} }
} }
}
var editFavoritesDialog: MaterialDialog? = null var editFavoritesDialog: MaterialDialog? = null
viewModel.isEditFavoritesShown.observe(this) { viewModel.isEditFavoritesShown.observe(this) {
@ -135,6 +144,11 @@ class LauncherActivity : BaseActivity() {
override fun onNewIntent(intent: Intent?) { override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent) super.onNewIntent(intent)
val navContract = intent?.let { GestureNavContract.fromIntent(it) }
if (navContract != null) {
homeTransitionManager.resolve(navContract)
} else {
onBackPressed() onBackPressed()
} }
}
} }

View File

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

View File

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