Skip to content

Commit

Permalink
MOB-256 Request textfield focus when search is tapped. (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang authored Feb 27, 2024
1 parent 6c10458 commit 0add51f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
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

0 comments on commit 0add51f

Please sign in to comment.