Use a LazyColumn, in case we get more results in the future.

This commit is contained in:
Benoit Marty 2023-06-09 18:30:44 +02:00
parent 18f32e51b4
commit 6b1809ed3b

View file

@ -19,7 +19,6 @@
package io.element.android.features.login.impl.screens.searchaccountprovider package io.element.android.features.login.impl.screens.searchaccountprovider
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.consumeWindowInsets import androidx.compose.foundation.layout.consumeWindowInsets
@ -28,9 +27,10 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.imePadding import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Search import androidx.compose.material.icons.filled.Search
@ -98,70 +98,72 @@ fun SearchAccountProviderView(
.padding(padding) .padding(padding)
.consumeWindowInsets(padding) .consumeWindowInsets(padding)
) { ) {
Column( LazyColumn(modifier = Modifier.fillMaxWidth(), state = rememberLazyListState()) {
modifier = Modifier item {
.verticalScroll(state = rememberScrollState()) IconTitleSubtitleMolecule(
) { modifier = Modifier.padding(top = 16.dp, bottom = 40.dp, start = 16.dp, end = 16.dp),
IconTitleSubtitleMolecule( iconImageVector = Icons.Filled.Search,
modifier = Modifier.padding(top = 16.dp, bottom = 40.dp, start = 16.dp, end = 16.dp), title = stringResource(id = R.string.screen_account_provider_form_title),
iconImageVector = Icons.Filled.Search, subTitle = stringResource(id = R.string.screen_account_provider_form_subtitle),
title = stringResource(id = R.string.screen_account_provider_form_title), )
subTitle = stringResource(id = R.string.screen_account_provider_form_subtitle), }
) item {
// TextInput
var userInputState by textFieldState(stateValue = state.userInput)
// TextInput OutlinedTextField(
var userInputState by textFieldState(stateValue = state.userInput) value = userInputState,
// readOnly = isLoading,
OutlinedTextField( modifier = Modifier
value = userInputState, .fillMaxWidth()
// readOnly = isLoading, .padding(start = 16.dp, end = 16.dp, bottom = 30.dp)
modifier = Modifier .testTag(TestTags.changeServerServer),
.fillMaxWidth() onValueChange = {
.padding(start = 16.dp, end = 16.dp, bottom = 30.dp) userInputState = it
.testTag(TestTags.changeServerServer), eventSink(SearchAccountProviderEvents.UserInput(it))
onValueChange = { },
userInputState = it keyboardOptions = KeyboardOptions(
eventSink(SearchAccountProviderEvents.UserInput(it)) keyboardType = KeyboardType.Uri,
}, imeAction = ImeAction.Done,
keyboardOptions = KeyboardOptions( ),
keyboardType = KeyboardType.Uri, singleLine = true,
imeAction = ImeAction.Done, trailingIcon = if (userInputState.isNotEmpty()) {
), {
singleLine = true, IconButton(onClick = {
trailingIcon = if (userInputState.isNotEmpty()) { userInputState = ""
{ eventSink(SearchAccountProviderEvents.UserInput(""))
IconButton(onClick = { }) {
userInputState = "" Icon(
eventSink(SearchAccountProviderEvents.UserInput("")) imageVector = Icons.Filled.Close,
}) { contentDescription = stringResource(StringR.string.action_clear)
Icon( )
imageVector = Icons.Filled.Close, }
contentDescription = stringResource(StringR.string.action_clear)
)
} }
} else null,
supportingText = {
Text(text = stringResource(id = R.string.screen_account_provider_form_notice), color = MaterialTheme.colorScheme.secondary)
} }
} else null, )
supportingText = { }
Text(text = stringResource(id = R.string.screen_account_provider_form_notice), color = MaterialTheme.colorScheme.secondary)
}
)
when (state.userInputResult) { when (state.userInputResult) {
is Async.Failure -> { is Async.Failure -> {
// Ignore errors (let the user type more chars) // Ignore errors (let the user type more chars)
} }
is Async.Loading -> { is Async.Loading -> {
Box( item {
modifier = Modifier Box(
.fillMaxSize() modifier = Modifier
) { .fillMaxSize()
CircularProgressIndicator( ) {
modifier = Modifier.align(Alignment.Center) CircularProgressIndicator(
) modifier = Modifier.align(Alignment.Center)
)
}
} }
} }
is Async.Success -> { is Async.Success -> {
state.userInputResult.state.forEach { homeserverData -> items(state.userInputResult.state) { homeserverData ->
val item = homeserverData.toAccountProvider() val item = homeserverData.toAccountProvider()
AccountProviderView( AccountProviderView(
item = item, item = item,
@ -173,7 +175,9 @@ fun SearchAccountProviderView(
} }
Async.Uninitialized -> Unit Async.Uninitialized -> Unit
} }
Spacer(Modifier.height(32.dp)) item {
Spacer(Modifier.height(32.dp))
}
} }
ChangeServerView( ChangeServerView(
state = state.changeServerState, state = state.changeServerState,