From 620b8b15492cb7dce08b323be4c1c32c7ae5ad04 Mon Sep 17 00:00:00 2001 From: jaskaran Date: Wed, 19 Mar 2025 15:22:36 +0530 Subject: [PATCH] Feat: Language fragment to jetpack compose screen - screen refinement - removed redundant code --- .../kiwix/kiwixmobile/language/LanguageScreen.kt | 15 +-------------- .../language/composables/AppBarTextField.kt | 15 ++------------- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/language/LanguageScreen.kt b/app/src/main/java/org/kiwix/kiwixmobile/language/LanguageScreen.kt index 3caf93403..2860360ab 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/language/LanguageScreen.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/language/LanguageScreen.kt @@ -25,8 +25,6 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.rememberLazyListState -import androidx.compose.foundation.text.KeyboardActions -import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.filled.Check @@ -37,7 +35,6 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Modifier @@ -47,7 +44,6 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.lifecycle.MutableLiveData -import kotlinx.coroutines.launch import org.kiwix.kiwixmobile.core.R import org.kiwix.kiwixmobile.core.ui.components.KiwixAppBar import org.kiwix.kiwixmobile.core.ui.components.NavigationIcon @@ -82,12 +78,6 @@ fun LanguageScreen( var isSearchActive by remember { mutableStateOf(false) } var updateListState by remember { mutableStateOf(false) } val listState: LazyListState = rememberLazyListState() - val coroutineScope = rememberCoroutineScope() - val scrollToTop = { - coroutineScope.launch { - listState.scrollToItem(0) - } - } KiwixTheme { Scaffold( @@ -110,7 +100,6 @@ fun LanguageScreen( filterText(searchText) } else { onNavigationClick() - scrollToTop() } } ) @@ -165,9 +154,7 @@ fun LanguageScreen( filterText(it) }, testTag = SEARCH_FIELD_TESTING_TAG, - hint = stringResource(R.string.search_label), - keyboardOptions = KeyboardOptions.Default, - keyboardActions = KeyboardActions.Default + hint = stringResource(R.string.search_label) ) } } else { diff --git a/app/src/main/java/org/kiwix/kiwixmobile/language/composables/AppBarTextField.kt b/app/src/main/java/org/kiwix/kiwixmobile/language/composables/AppBarTextField.kt index 1ae29826d..71b1994a3 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/language/composables/AppBarTextField.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/language/composables/AppBarTextField.kt @@ -23,8 +23,6 @@ import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.text.BasicTextField -import androidx.compose.foundation.text.KeyboardActions -import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.selection.LocalTextSelectionColors import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.LocalTextStyle @@ -45,8 +43,6 @@ import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.platform.testTag -import androidx.compose.ui.semantics.contentDescription -import androidx.compose.ui.semantics.semantics import androidx.compose.ui.text.TextRange import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.text.input.VisualTransformation @@ -59,9 +55,7 @@ fun AppBarTextField( value: String, hint: String, testTag: String, - onValueChange: (String) -> Unit, - keyboardOptions: KeyboardOptions = KeyboardOptions.Default, - keyboardActions: KeyboardActions = KeyboardActions.Default, + onValueChange: (String) -> Unit ) { val interactionSource = remember(::MutableInteractionSource) val textStyle = LocalTextStyle.current @@ -100,10 +94,7 @@ fun AppBarTextField( interactionSource = interactionSource, colors = colors ) - .focusRequester(focusRequester) - .semantics { - contentDescription = "searchField" - }, + .focusRequester(focusRequester), value = textFieldValue, onValueChange = { textFieldValue = it @@ -111,8 +102,6 @@ fun AppBarTextField( }, textStyle = textStyle.copy(color = Color.White), cursorBrush = SolidColor(MaterialTheme.colorScheme.primary), - keyboardOptions = keyboardOptions, - keyboardActions = keyboardActions, interactionSource = interactionSource, singleLine = true, decorationBox = { innerTextField ->