mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-10 00:27:45 +00:00
Fix settings search insets by moving top & horizontal insets to the top of the setting screen. (#1510)
This commit is contained in:
parent
54c2c364a0
commit
bedb9d1517
3 changed files with 81 additions and 92 deletions
|
@ -64,8 +64,7 @@ fun SearchSettingsScreen(
|
||||||
if (content != null) content()
|
if (content != null) content()
|
||||||
else {
|
else {
|
||||||
Scaffold(
|
Scaffold(
|
||||||
contentWindowInsets = WindowInsets.safeDrawing
|
contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Bottom)
|
||||||
.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom)
|
|
||||||
) { innerPadding ->
|
) { innerPadding ->
|
||||||
Column(
|
Column(
|
||||||
Modifier.verticalScroll(rememberScrollState()).then(Modifier.padding(innerPadding))
|
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
|
// keyboard in unexpected situations such as going back from another screen, which is rather annoying
|
||||||
var searchText by remember { mutableStateOf(TextFieldValue()) }
|
var searchText by remember { mutableStateOf(TextFieldValue()) }
|
||||||
var showSearch by remember { mutableStateOf(false) }
|
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) {
|
fun setShowSearch(value: Boolean) {
|
||||||
showSearch = value
|
showSearch = value
|
||||||
if (!value) searchText = TextFieldValue()
|
if (!value) searchText = TextFieldValue()
|
||||||
}
|
}
|
||||||
BackHandler {
|
BackHandler {
|
||||||
if (showSearch || searchText.text.isNotEmpty()) setShowSearch(false)
|
if (showSearch || searchText.text.isNotEmpty()) setShowSearch(false)
|
||||||
else onClickBack()
|
else onClickBack()
|
||||||
}
|
}
|
||||||
Surface(
|
Surface(
|
||||||
color = MaterialTheme.colorScheme.surfaceContainer,
|
color = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
) {
|
) {
|
||||||
Column {
|
Column {
|
||||||
TopAppBar(
|
TopAppBar(
|
||||||
title = title,
|
title = title,
|
||||||
windowInsets = TopAppBarDefaults.windowInsets,
|
windowInsets = WindowInsets(0),
|
||||||
navigationIcon = {
|
navigationIcon = {
|
||||||
IconButton(onClick = {
|
IconButton(onClick = {
|
||||||
if (showSearch) setShowSearch(false)
|
if (showSearch) setShowSearch(false)
|
||||||
else onClickBack()
|
else onClickBack()
|
||||||
}) {
|
}) {
|
||||||
Icon(
|
Icon(
|
||||||
painterResource(R.drawable.ic_arrow_back),
|
painterResource(R.drawable.ic_arrow_back),
|
||||||
stringResource(R.string.spoken_description_action_previous)
|
stringResource(R.string.spoken_description_action_previous)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions = {
|
actions = {
|
||||||
if (icon == null)
|
if (icon == null)
|
||||||
IconButton(onClick = { setShowSearch(!showSearch) }) { SearchIcon() }
|
IconButton(onClick = { setShowSearch(!showSearch) }) { SearchIcon() }
|
||||||
else
|
else
|
||||||
icon()
|
icon()
|
||||||
if (menu != null)
|
if (menu != null)
|
||||||
Box {
|
Box {
|
||||||
var showMenu by remember { mutableStateOf(false) }
|
var showMenu by remember { mutableStateOf(false) }
|
||||||
IconButton(
|
IconButton(
|
||||||
onClick = { showMenu = true }
|
onClick = { showMenu = true }
|
||||||
) { Icon(painterResource(R.drawable.ic_arrow_left), "menu", Modifier.rotate(-90f)) }
|
) { Icon(painterResource(R.drawable.ic_arrow_left), "menu", Modifier.rotate(-90f)) }
|
||||||
DropdownMenu(
|
DropdownMenu(
|
||||||
expanded = showMenu,
|
expanded = showMenu,
|
||||||
onDismissRequest = { showMenu = false }
|
onDismissRequest = { showMenu = false }
|
||||||
) {
|
) {
|
||||||
menu.forEach {
|
menu.forEach {
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
text = { Text(it.first) },
|
text = { Text(it.first) },
|
||||||
onClick = { showMenu = false; it.second() }
|
onClick = { showMenu = false; it.second() }
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
)
|
||||||
)
|
ExpandableSearchField(
|
||||||
ExpandableSearchField(
|
expanded = showSearch,
|
||||||
expanded = showSearch,
|
onDismiss = { setShowSearch(false) },
|
||||||
onDismiss = { setShowSearch(false) },
|
search = searchText,
|
||||||
search = searchText,
|
onSearchChange = { searchText = it },
|
||||||
onSearchChange = { searchText = it },
|
modifier = Modifier
|
||||||
modifier = Modifier
|
.fillMaxWidth()
|
||||||
.fillMaxWidth()
|
.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
colors = TextFieldDefaults.colors(
|
||||||
colors = TextFieldDefaults.colors(
|
focusedContainerColor = MaterialTheme.colorScheme.surface
|
||||||
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)
|
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.bodyLarge) {
|
||||||
Scaffold(
|
if (searchText.text.isBlank() && content != null) {
|
||||||
contentWindowInsets = WindowInsets.safeDrawing
|
Column {
|
||||||
.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom)
|
content()
|
||||||
) { innerPadding ->
|
}
|
||||||
LazyColumn(contentPadding = innerPadding) {
|
} else {
|
||||||
items(items) {
|
val items = filteredItems(searchText.text)
|
||||||
itemContent(it)
|
Scaffold(
|
||||||
|
contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Bottom)
|
||||||
|
) { innerPadding ->
|
||||||
|
LazyColumn(contentPadding = innerPadding) {
|
||||||
|
items(items) {
|
||||||
|
itemContent(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,9 +48,7 @@ fun MainSettingsScreen(
|
||||||
settings = emptyList(),
|
settings = emptyList(),
|
||||||
) {
|
) {
|
||||||
val enabledSubtypes = SubtypeSettings.getEnabledSubtypes(true)
|
val enabledSubtypes = SubtypeSettings.getEnabledSubtypes(true)
|
||||||
Scaffold(
|
Scaffold(contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Bottom)) { innerPadding ->
|
||||||
contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom)
|
|
||||||
) { innerPadding ->
|
|
||||||
Column(
|
Column(
|
||||||
Modifier.verticalScroll(rememberScrollState()).then(Modifier.padding(innerPadding))
|
Modifier.verticalScroll(rememberScrollState()).then(Modifier.padding(innerPadding))
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -146,7 +146,7 @@ fun SubtypeScreen(
|
||||||
filteredItems = { emptyList<String>() }
|
filteredItems = { emptyList<String>() }
|
||||||
) {
|
) {
|
||||||
Scaffold(
|
Scaffold(
|
||||||
contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom)
|
contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Bottom)
|
||||||
) { innerPadding ->
|
) { innerPadding ->
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.verticalScroll(scrollState).padding(horizontal = 12.dp)
|
modifier = Modifier.verticalScroll(scrollState).padding(horizontal = 12.dp)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue