Skip to content

Commit 088d922

Browse files
authored
[#610] SearchView가 뜰 때 키보드 포커싱이 되지 않는 현상을 해결한다 (#645)
* fix: SearchView 자동 포커스 타이밍 복원 * fix: SearchView 포커스 요청을 Feature로 이동 * fix: SearchView 포커스 지연 처리 명확화
1 parent d993611 commit 088d922

4 files changed

Lines changed: 26 additions & 1 deletion

File tree

Application/DevLogPresentation/Sources/Search/SearchFeature.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct SearchFeature {
6464
}
6565

6666
enum Action: BindableAction, Equatable {
67+
case onAppear
6768
case alert(PresentationAction<Never>)
6869
case binding(BindingAction<State>)
6970
case addRecentQuery(String)
@@ -102,6 +103,14 @@ struct SearchFeature {
102103
BindingReducer()
103104
Reduce { state, action in
104105
switch action {
106+
case .onAppear:
107+
return .run { send in
108+
// `.searchable` 바인딩이 화면에 붙은 뒤 포커스를 요청하도록 main queue 다음 턴으로 넘긴다.
109+
await withCheckedContinuation { continuation in
110+
DispatchQueue.main.async { continuation.resume() }
111+
}
112+
await send(.binding(.set(\.isSearching, true)))
113+
}
105114
case .alert:
106115
break
107116
case .binding(\.isSearching):

Application/DevLogPresentation/Sources/Search/SearchView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct SearchView: View {
4141
}
4242
}
4343
}
44-
.onAppear { store.send(.binding(.set(\.isSearching, true))) }
44+
.onAppear { store.send(.onAppear) }
4545
.onChange(of: store.isSearching) { _, isSearching in
4646
if !isSearching {
4747
dismiss()

Application/DevLogPresentation/Tests/Search/SearchFeatureTestDoubles.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ struct SearchStoreTestAdapter {
8282
}
8383
}
8484

85+
func onAppear() async {
86+
await store.send(.onAppear)
87+
await store.receive(.binding(.set(\.isSearching, true))) {
88+
$0.isSearching = true
89+
}
90+
}
91+
8592
func setShowAllTodos(_ value: Bool) async {
8693
await store.send(.setShowAllTodos(value)) {
8794
$0.showAllTodos = value

Application/DevLogPresentation/Tests/Search/SearchFeatureTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ struct SearchFeatureTests {
2121
#expect(adapter.recentQueries == ["swift", "tca"])
2222
}
2323

24+
@Test("onAppear는 검색 상태를 활성화한다")
25+
func onAppear는_검색_상태를_활성화한다() async {
26+
let adapter = SearchStoreTestAdapter()
27+
28+
await adapter.onAppear()
29+
30+
#expect(adapter.isSearching)
31+
}
32+
2433
@Test("addRecentQuery는 공백을 제거하고 중복 제거 후 앞에 추가한다")
2534
func addRecentQuery는_공백을_제거하고_중복_제거_후_앞에_추가한다() async {
2635
let updateSpy = SearchUpdateRecentQueriesUseCaseSpy()

0 commit comments

Comments
 (0)