From 1f129494099b751b8395fd103f7e98ffdf2c2897 Mon Sep 17 00:00:00 2001 From: iiinaiii Date: Sun, 8 Sep 2024 13:44:03 +0900 Subject: [PATCH 1/3] #992 [add]Add Placeholder to SearchScreen and focus text field when launch screen --- .../component/SearchTextFieldAppBar.kt | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/component/SearchTextFieldAppBar.kt b/feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/component/SearchTextFieldAppBar.kt index 60e6f0b87..599ac81f0 100644 --- a/feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/component/SearchTextFieldAppBar.kt +++ b/feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/component/SearchTextFieldAppBar.kt @@ -1,5 +1,6 @@ package io.github.droidkaigi.confsched.sessions.component +import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.IntrinsicSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height @@ -14,15 +15,27 @@ import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.material3.TextFieldDefaults import androidx.compose.material3.TopAppBar import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +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.Color import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.platform.LocalSoftwareKeyboardController import androidx.compose.ui.platform.testTag +import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.input.ImeAction +import androidx.compose.ui.text.input.VisualTransformation +import conference_app_2024.feature.sessions.generated.resources.search import io.github.droidkaigi.confsched.designsystem.theme.KaigiTheme +import io.github.droidkaigi.confsched.sessions.SessionsRes +import org.jetbrains.compose.resources.stringResource import org.jetbrains.compose.ui.tooling.preview.Preview const val SearchTextFieldAppBarTextFieldTestTag = "SearchTextFieldAppBarTextField" @@ -37,7 +50,13 @@ fun SearchTextFieldAppBar( modifier: Modifier = Modifier, ) { val focusManager = LocalFocusManager.current + val focusRequester = remember { FocusRequester() } val keyboardController = LocalSoftwareKeyboardController.current + val interactionSource = remember { MutableInteractionSource() } + + LaunchedEffect(Unit) { + focusRequester.requestFocus() + } TopAppBar( title = { @@ -56,7 +75,32 @@ fun SearchTextFieldAppBar( focusManager.clearFocus() }, ), + decorationBox = { innerTextField -> + TextFieldDefaults.DecorationBox( + value = searchWord, + innerTextField = innerTextField, + enabled = true, + singleLine = true, + visualTransformation = VisualTransformation.None, + interactionSource = interactionSource, + colors = TextFieldDefaults.colors( + focusedContainerColor = Color.Transparent, + unfocusedContainerColor = Color.Transparent, + focusedIndicatorColor = Color.Transparent, + unfocusedIndicatorColor = Color.Transparent + ), + placeholder = { + Text( + text = stringResource(SessionsRes.string.search), + style = MaterialTheme.typography.bodyLarge.copy( + fontFamily = FontFamily.Default + ) + ) + } + ) + }, modifier = Modifier + .focusRequester(focusRequester) .fillMaxWidth() .height(IntrinsicSize.Max) .testTag(SearchTextFieldAppBarTextFieldTestTag), From 20a99e62fccc4de2f937dcebbf41fddb4f99e2b1 Mon Sep 17 00:00:00 2001 From: iiinaiii Date: Sun, 8 Sep 2024 13:50:34 +0900 Subject: [PATCH 2/3] #992 [fix]Fix code format --- .../confsched/sessions/component/SearchTextFieldAppBar.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/component/SearchTextFieldAppBar.kt b/feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/component/SearchTextFieldAppBar.kt index 599ac81f0..63a02355f 100644 --- a/feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/component/SearchTextFieldAppBar.kt +++ b/feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/component/SearchTextFieldAppBar.kt @@ -87,16 +87,16 @@ fun SearchTextFieldAppBar( focusedContainerColor = Color.Transparent, unfocusedContainerColor = Color.Transparent, focusedIndicatorColor = Color.Transparent, - unfocusedIndicatorColor = Color.Transparent + unfocusedIndicatorColor = Color.Transparent, ), placeholder = { Text( text = stringResource(SessionsRes.string.search), style = MaterialTheme.typography.bodyLarge.copy( - fontFamily = FontFamily.Default - ) + fontFamily = FontFamily.Default, + ), ) - } + }, ) }, modifier = Modifier From 3abf246a6ed3b9275b6ff88756646d31023f3e3a Mon Sep 17 00:00:00 2001 From: iiinaiii Date: Sun, 8 Sep 2024 17:22:22 +0900 Subject: [PATCH 3/3] [fix]Fix SearchScreen text field placeholder word --- .../src/commonMain/composeResources/values-ja/strings.xml | 1 + .../src/commonMain/composeResources/values/strings.xml | 1 + .../confsched/sessions/component/SearchTextFieldAppBar.kt | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/feature/sessions/src/commonMain/composeResources/values-ja/strings.xml b/feature/sessions/src/commonMain/composeResources/values-ja/strings.xml index eaad497f1..2ad61f050 100644 --- a/feature/sessions/src/commonMain/composeResources/values-ja/strings.xml +++ b/feature/sessions/src/commonMain/composeResources/values-ja/strings.xml @@ -15,6 +15,7 @@ ワークショップ 戻る 検索 + セッションを検索 言語選択 日本語 English diff --git a/feature/sessions/src/commonMain/composeResources/values/strings.xml b/feature/sessions/src/commonMain/composeResources/values/strings.xml index fa80c2e3a..38b48624d 100644 --- a/feature/sessions/src/commonMain/composeResources/values/strings.xml +++ b/feature/sessions/src/commonMain/composeResources/values/strings.xml @@ -15,6 +15,7 @@ Workshop Back Search + Search sessions Select Language 日本語 English diff --git a/feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/component/SearchTextFieldAppBar.kt b/feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/component/SearchTextFieldAppBar.kt index 63a02355f..d80455efb 100644 --- a/feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/component/SearchTextFieldAppBar.kt +++ b/feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/component/SearchTextFieldAppBar.kt @@ -32,7 +32,7 @@ import androidx.compose.ui.platform.testTag import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.VisualTransformation -import conference_app_2024.feature.sessions.generated.resources.search +import conference_app_2024.feature.sessions.generated.resources.search_sessions import io.github.droidkaigi.confsched.designsystem.theme.KaigiTheme import io.github.droidkaigi.confsched.sessions.SessionsRes import org.jetbrains.compose.resources.stringResource @@ -91,7 +91,7 @@ fun SearchTextFieldAppBar( ), placeholder = { Text( - text = stringResource(SessionsRes.string.search), + text = stringResource(SessionsRes.string.search_sessions), style = MaterialTheme.typography.bodyLarge.copy( fontFamily = FontFamily.Default, ),