@@ -4,17 +4,18 @@ import android.widget.Toast
44import androidx.compose.foundation.layout.Arrangement
55import androidx.compose.foundation.layout.Column
66import androidx.compose.foundation.layout.Row
7+ import androidx.compose.foundation.layout.height
78import androidx.compose.foundation.layout.padding
89import androidx.compose.foundation.text.KeyboardActions
910import androidx.compose.foundation.text.KeyboardOptions
1011import androidx.compose.material.icons.Icons
1112import androidx.compose.material.icons.outlined.Clear
1213import androidx.compose.material.icons.outlined.Search
1314import androidx.compose.material3.ExperimentalMaterial3Api
15+ import androidx.compose.material3.LargeTopAppBar
1416import androidx.compose.material3.OutlinedTextField
1517import androidx.compose.material3.Scaffold
16- import androidx.compose.material3.Text
17- import androidx.compose.material3.TopAppBar
18+ import androidx.compose.material3.TopAppBarDefaults
1819import androidx.compose.runtime.Composable
1920import androidx.compose.runtime.LaunchedEffect
2021import androidx.compose.runtime.collectAsState
@@ -26,14 +27,15 @@ import androidx.compose.ui.Alignment
2627import androidx.compose.ui.Modifier
2728import androidx.compose.ui.focus.focusRequester
2829import androidx.compose.ui.geometry.Offset
30+ import androidx.compose.ui.input.nestedscroll.nestedScroll
2931import androidx.compose.ui.platform.LocalFocusManager
30- import androidx.compose.ui.res.stringResource
32+ import androidx.compose.ui.text.TextStyle
3133import androidx.compose.ui.text.input.ImeAction
3234import androidx.compose.ui.text.input.KeyboardType
3335import androidx.compose.ui.unit.dp
36+ import androidx.compose.ui.unit.sp
3437import androidx.lifecycle.viewmodel.compose.viewModel
3538import com.paulcoding.hviewer.MainApp.Companion.appContext
36- import com.paulcoding.hviewer.R
3739import com.paulcoding.hviewer.helper.BasePaginationHelper
3840import com.paulcoding.hviewer.model.PostItem
3941import com.paulcoding.hviewer.model.Tag
@@ -70,6 +72,7 @@ fun SearchPage(
7072 val focusRequester = remember { androidx.compose.ui.focus.FocusRequester () }
7173 val focusManager = LocalFocusManager .current
7274 var tabsIconPosition by remember { mutableStateOf(Offset .Zero ) }
75+ val scrollBehavior = TopAppBarDefaults .exitUntilCollapsedScrollBehavior()
7376
7477 fun submit () {
7578 viewModel.setQueryAndSearch(query)
@@ -81,48 +84,57 @@ fun SearchPage(
8184 focusRequester.requestFocus()
8285 }
8386
84- Scaffold (topBar = {
85- TopAppBar (title = { Text (stringResource(R .string.search)) }, navigationIcon = {
86- HBackIcon { goBack() }
87- },
88- actions = {
89- if (uiState.postItems.isNotEmpty())
90- HPageProgress (uiState.postsPage, uiState.postsTotalPage)
91- TabsIcon (
92- size = tabs.size,
93- onGloballyPositioned = { tabsIconPosition = it },
94- onClick = navToTabs
95- )
96- })
97- }) { paddings ->
98- Column (modifier = Modifier .padding(paddings)) {
99- Row (
100- modifier = Modifier .padding(horizontal = 16 .dp, vertical = 12 .dp),
101- horizontalArrangement = Arrangement .spacedBy(8 .dp),
102- verticalAlignment = Alignment .CenterVertically
103- ) {
104- OutlinedTextField (
105- query,
106- onValueChange = { query = it },
107- label = { Text (" Search" ) },
108- keyboardOptions = KeyboardOptions (
109- keyboardType = KeyboardType .Text ,
110- imeAction = ImeAction .Go
111- ),
112- keyboardActions = KeyboardActions (onGo = { submit() }),
113- modifier = Modifier
114- .focusRequester(focusRequester)
115- .weight(1f ),
116- trailingIcon = {
117- if (query.isNotEmpty())
118- HIcon (Icons .Outlined .Clear ) {
119- query = " "
120- focusRequester.requestFocus()
87+ Scaffold (
88+ modifier = Modifier .nestedScroll(scrollBehavior.nestedScrollConnection),
89+ topBar = {
90+ LargeTopAppBar (
91+ navigationIcon = {
92+ HBackIcon { goBack() }
93+ },
94+ actions = {
95+ if (uiState.postItems.isNotEmpty())
96+ HPageProgress (uiState.postsPage, uiState.postsTotalPage)
97+ TabsIcon (
98+ size = tabs.size,
99+ onGloballyPositioned = { tabsIconPosition = it },
100+ onClick = navToTabs
101+ )
102+ },
103+ title = {
104+ Row (
105+ horizontalArrangement = Arrangement .spacedBy(8 .dp),
106+ verticalAlignment = Alignment .CenterVertically
107+ ) {
108+ OutlinedTextField (
109+ query,
110+ textStyle = TextStyle (fontSize = 14 .sp),
111+ onValueChange = { query = it },
112+ singleLine = true ,
113+ keyboardOptions = KeyboardOptions (
114+ keyboardType = KeyboardType .Text ,
115+ imeAction = ImeAction .Go
116+ ),
117+ keyboardActions = KeyboardActions (onGo = { submit() }),
118+ modifier = Modifier
119+ .focusRequester(focusRequester)
120+ .weight(1f )
121+ .height(52 .dp),
122+ trailingIcon = {
123+ if (query.isNotEmpty())
124+ HIcon (Icons .Outlined .Clear ) {
125+ query = " "
126+ focusRequester.requestFocus()
127+ }
121128 }
129+ )
130+ HIcon (Icons .Outlined .Search ) { submit() }
122131 }
123- )
124- HIcon (Icons .Outlined .Search ) { submit() }
125- }
132+ },
133+ scrollBehavior = scrollBehavior
134+ )
135+ }) { paddings ->
136+ Column (modifier = Modifier .padding(paddings)) {
137+
126138 SearchPageContent (
127139 appViewModel = appViewModel,
128140 endPos = tabsIconPosition,
0 commit comments