Skip to content

Commit

Permalink
style: 検索時にキーボードを自動で閉じるよう変更 (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
kokoichi206 committed Dec 5, 2022
1 parent 0ce94aa commit 8ce3a90
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextRange
Expand Down Expand Up @@ -53,6 +54,8 @@ fun MainView(
}
}

val focusManager = LocalFocusManager.current

Box(
modifier = Modifier
.fillMaxSize()
Expand All @@ -72,6 +75,8 @@ fun MainView(
viewModel.searchResults(it)
updateLastSearchDate()
viewModel.setShowRecent(true)
// 検索実行時にキーボードを閉じる
focusManager.clearFocus()
}
)

Expand All @@ -96,6 +101,8 @@ fun MainView(
)
// 検索まで行う
viewModel.searchResults(it)
// 検索実行時にキーボードを閉じる
focusManager.clearFocus()
},
onItemReflectClick = {
// 検索バーに表示するだけ
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.TextFieldValue
Expand Down Expand Up @@ -67,6 +68,8 @@ fun UserViewMain(
}
}

val focusManager = LocalFocusManager.current

Box(
modifier = Modifier
.fillMaxSize()
Expand All @@ -83,6 +86,8 @@ fun UserViewMain(
},
onSearch = {
onSearch(it)
// 検索実行時にキーボードを閉じる
focusManager.clearFocus()
}
)

Expand Down

0 comments on commit 8ce3a90

Please sign in to comment.