Fix settings search insets by moving top & horizontal insets to the top of the setting screen. (#1510)

This commit is contained in:
Eran Leshem 2025-04-27 17:03:18 +03:00 committed by GitHub
parent 54c2c364a0
commit bedb9d1517
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 81 additions and 92 deletions

View file

@ -64,8 +64,7 @@ fun SearchSettingsScreen(
if (content != null) content()
else {
Scaffold(
contentWindowInsets = WindowInsets.safeDrawing
.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom)
contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Bottom)
) { innerPadding ->
Column(
Modifier.verticalScroll(rememberScrollState()).then(Modifier.padding(innerPadding))
@ -123,97 +122,89 @@ fun <T: Any?> SearchScreen(
// keyboard in unexpected situations such as going back from another screen, which is rather annoying
var searchText by remember { mutableStateOf(TextFieldValue()) }
var showSearch by remember { mutableStateOf(false) }
Column(Modifier.fillMaxSize()) {
Scaffold(contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top))
{ innerPadding ->
Column(Modifier.fillMaxSize().padding(innerPadding)) {
fun setShowSearch(value: Boolean) {
showSearch = value
if (!value) searchText = TextFieldValue()
}
BackHandler {
if (showSearch || searchText.text.isNotEmpty()) setShowSearch(false)
else onClickBack()
}
Surface(
color = MaterialTheme.colorScheme.surfaceContainer,
) {
Column {
TopAppBar(
title = title,
windowInsets = TopAppBarDefaults.windowInsets,
navigationIcon = {
IconButton(onClick = {
if (showSearch) setShowSearch(false)
else onClickBack()
}) {
Icon(
painterResource(R.drawable.ic_arrow_back),
stringResource(R.string.spoken_description_action_previous)
)
}
},
actions = {
if (icon == null)
IconButton(onClick = { setShowSearch(!showSearch) }) { SearchIcon() }
else
icon()
if (menu != null)
Box {
var showMenu by remember { mutableStateOf(false) }
IconButton(
onClick = { showMenu = true }
) { Icon(painterResource(R.drawable.ic_arrow_left), "menu", Modifier.rotate(-90f)) }
DropdownMenu(
expanded = showMenu,
onDismissRequest = { showMenu = false }
) {
menu.forEach {
DropdownMenuItem(
text = { Text(it.first) },
onClick = { showMenu = false; it.second() }
)
fun setShowSearch(value: Boolean) {
showSearch = value
if (!value) searchText = TextFieldValue()
}
BackHandler {
if (showSearch || searchText.text.isNotEmpty()) setShowSearch(false)
else onClickBack()
}
Surface(
color = MaterialTheme.colorScheme.surfaceContainer,
) {
Column {
TopAppBar(
title = title,
windowInsets = WindowInsets(0),
navigationIcon = {
IconButton(onClick = {
if (showSearch) setShowSearch(false)
else onClickBack()
}) {
Icon(
painterResource(R.drawable.ic_arrow_back),
stringResource(R.string.spoken_description_action_previous)
)
}
},
actions = {
if (icon == null)
IconButton(onClick = { setShowSearch(!showSearch) }) { SearchIcon() }
else
icon()
if (menu != null)
Box {
var showMenu by remember { mutableStateOf(false) }
IconButton(
onClick = { showMenu = true }
) { Icon(painterResource(R.drawable.ic_arrow_left), "menu", Modifier.rotate(-90f)) }
DropdownMenu(
expanded = showMenu,
onDismissRequest = { showMenu = false }
) {
menu.forEach {
DropdownMenuItem(
text = { Text(it.first) },
onClick = { showMenu = false; it.second() }
)
}
}
}
}
},
)
ExpandableSearchField(
expanded = showSearch,
onDismiss = { setShowSearch(false) },
search = searchText,
onSearchChange = { searchText = it },
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
colors = TextFieldDefaults.colors(
focusedContainerColor = MaterialTheme.colorScheme.surface
},
)
ExpandableSearchField(
expanded = showSearch,
onDismiss = { setShowSearch(false) },
search = searchText,
onSearchChange = { searchText = it },
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
colors = TextFieldDefaults.colors(
focusedContainerColor = MaterialTheme.colorScheme.surface
)
)
)
}
}
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.bodyLarge) {
if (searchText.text.isBlank() && content != null) {
Column(
// todo: how and where to best deal with insets?
// here? manifest android:windowSoftInputMode="adjustResize"?
// other?
// Modifier
// .windowInsetsPadding(
// WindowInsets.safeDrawing.only(
// WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom
// )
// )
) {
content()
}
} else {
val items = filteredItems(searchText.text)
Scaffold(
contentWindowInsets = WindowInsets.safeDrawing
.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom)
) { innerPadding ->
LazyColumn(contentPadding = innerPadding) {
items(items) {
itemContent(it)
}
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.bodyLarge) {
if (searchText.text.isBlank() && content != null) {
Column {
content()
}
} else {
val items = filteredItems(searchText.text)
Scaffold(
contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Bottom)
) { innerPadding ->
LazyColumn(contentPadding = innerPadding) {
items(items) {
itemContent(it)
}
}
}
}

View file

@ -48,9 +48,7 @@ fun MainSettingsScreen(
settings = emptyList(),
) {
val enabledSubtypes = SubtypeSettings.getEnabledSubtypes(true)
Scaffold(
contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom)
) { innerPadding ->
Scaffold(contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Bottom)) { innerPadding ->
Column(
Modifier.verticalScroll(rememberScrollState()).then(Modifier.padding(innerPadding))
) {

View file

@ -146,7 +146,7 @@ fun SubtypeScreen(
filteredItems = { emptyList<String>() }
) {
Scaffold(
contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom)
contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Bottom)
) { innerPadding ->
Column(
modifier = Modifier.verticalScroll(scrollState).padding(horizontal = 12.dp)