Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOB-256 Request textfield focus when search is tapped. #2

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -142,7 +145,7 @@ object DydxMarketSearchView : DydxComponent {
state: ViewState,
) {
val shape = RoundedCornerShape(50)

val focusRequester = remember { FocusRequester() }
Row(
modifier = modifier.fillMaxWidth()
.padding(start = ThemeShapes.HorizontalPadding)
Expand All @@ -156,6 +159,7 @@ object DydxMarketSearchView : DydxComponent {
.padding(horizontal = 16.dp, vertical = 8.dp),
) {
PlatformTextInput(
focusRequester = focusRequester,
placeHolder = state.localizer.localize("APP.GENERAL.SEARCH"),
textStyle = TextStyle.dydxDefault
.themeFont(
Expand All @@ -166,5 +170,9 @@ object DydxMarketSearchView : DydxComponent {
}
HeaderViewCloseBotton(closeAction = state.closeAction)
}

LaunchedEffect(Unit) {
focusRequester.requestFocus()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DydxTradingNetworkViewModel @Inject constructor(
localizer: LocalizerProtocol,
abacusStateManager: AbacusStateManagerProtocol
): String? {
val value = abacusStateManager.currentEnvironmentId.value
val value = abacusStateManager.currentEnvironmentId.value ?: return null
return abacusStateManager.availableEnvironments.first { it.type == value }.localizedString(localizer = localizer)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.VisualTransformation
Expand All @@ -33,6 +35,7 @@ import exchange.dydx.platformui.designSystem.theme.themeFont
@Composable
fun PlatformTextInput(
modifier: Modifier = Modifier,
focusRequester: FocusRequester = remember { FocusRequester() },
label: @Composable (() -> Unit)? = null,
value: String? = null,
textStyle: TextStyle =
Expand Down Expand Up @@ -61,7 +64,7 @@ fun PlatformTextInput(
val displayValue = if (isFocused) currentValue.value ?: "" else value ?: ""

BasicTextField(
modifier = Modifier,
modifier = Modifier.focusRequester(focusRequester = focusRequester),
value = displayValue,
onValueChange = {
currentValue.value = it
Expand Down
Loading