@@ -9,6 +9,7 @@ import SwiftUI
9
9
10
10
struct InfoStepView : View {
11
11
@ObservedObject private var store : RegisterStore
12
+ @FocusState private var isPlaceTextFieldFocused : Bool
12
13
13
14
init ( store: RegisterStore ) {
14
15
self . store = store
@@ -27,14 +28,15 @@ struct InfoStepView: View {
27
28
store. dispatch ( . didTapBackground( . start) )
28
29
hideKeyboard ( )
29
30
}
30
- . toastView ( toast: Binding ( get: {
31
- store. state. toast
32
- } , set: { newValue in
33
- store. dispatch ( . updateToast( newValue) )
34
- } ) )
31
+ . toastView ( toast: Binding (
32
+ get: { store. state. toast } ,
33
+ set: { newValue in
34
+ store. dispatch ( . updateToast( newValue) )
35
+ }
36
+ ) )
35
37
. task {
36
38
store. dispatch ( . getCategories)
37
- }
39
+ }
38
40
}
39
41
}
40
42
@@ -85,6 +87,7 @@ extension InfoStepView {
85
87
) {
86
88
store. dispatch ( . didTapButtonIcon( . place) )
87
89
}
90
+ . focused ( $isPlaceTextFieldFocused)
88
91
. onSubmit {
89
92
store. dispatch ( . didTapkeyboardEnter)
90
93
}
@@ -114,7 +117,7 @@ extension InfoStepView {
114
117
ChipsContainerView (
115
118
selectedItem: Binding ( get: {
116
119
store. state. selectedCategory
117
- } , set: { newValue in
120
+ } , set: { newValue in
118
121
store. dispatch ( . updateSelectedCategoryChip( newValue) )
119
122
} ) ,
120
123
items: store. state. categorys
@@ -150,7 +153,7 @@ extension InfoStepView {
150
153
plusButton
151
154
}
152
155
}
153
- }
156
+ }
154
157
}
155
158
156
159
private var dropDownView : some View {
@@ -197,34 +200,75 @@ extension InfoStepView {
197
200
}
198
201
199
202
private var nextButton : some View {
200
- SpoonyButton (
201
- style: . primary,
202
- size: . xlarge,
203
- title: " 다음 " ,
204
- disabled: Binding (
205
- get: {
206
- store. state. isDisableStartButton
207
- } , set: { newValue in
208
- store. dispatch ( . updateButtonState( newValue, . start) )
203
+ ScrollViewReader { proxy in
204
+ VStack {
205
+ SpoonyButton (
206
+ style: . primary,
207
+ size: . xlarge,
208
+ title: " 다음 " ,
209
+ disabled: Binding (
210
+ get: {
211
+ store. state. isDisableStartButton
212
+ } , set: { newValue in
213
+ store. dispatch ( . updateButtonState( newValue, . start) )
214
+ }
215
+ )
216
+ ) {
217
+ store. dispatch ( . didTapNextButton( . start) )
209
218
}
210
- )
211
- ) {
212
- store. dispatch ( . didTapNextButton( . start) )
213
- }
214
- . padding ( . bottom, 20 )
215
- . padding ( . top, 61 )
216
- . overlay ( alignment: . top) {
217
- ToolTipView ( )
218
- . padding ( . top, 5 )
219
- . opacity ( store. state. isToolTipPresented ? 1 : 0 )
220
- . task {
221
- do {
222
- try await Task . sleep ( for: . seconds( 3 ) )
223
- store. dispatch ( . updateToolTipState)
224
- } catch {
225
-
219
+ . padding ( . bottom, 20 )
220
+ . padding ( . top, 61 )
221
+ }
222
+ . onAppear {
223
+ NotificationCenter . default. addObserver (
224
+ forName: UIResponder . keyboardWillShowNotification,
225
+ object: nil ,
226
+ queue: . main
227
+ ) { notification in
228
+ if let frame = notification. userInfo ? [ UIResponder . keyboardFrameEndUserInfoKey] as? CGRect {
229
+ withAnimation ( . smooth) {
230
+ if !isPlaceTextFieldFocused {
231
+ store. dispatch ( . updateKeyboardHeight( frame. height) )
232
+ }
233
+ }
226
234
}
227
235
}
236
+
237
+ NotificationCenter . default. addObserver (
238
+ forName: UIResponder . keyboardWillHideNotification,
239
+ object: nil ,
240
+ queue: . main
241
+ ) { _ in
242
+ withAnimation ( . smooth) {
243
+ store. dispatch ( . updateKeyboardHeight( 0 ) )
244
+ }
245
+ }
246
+ }
247
+ . id ( " nextButton " )
248
+ . padding ( . bottom, store. state. keyboardHeight)
249
+ . ignoresSafeArea ( . keyboard)
250
+ . onChange ( of: store. state. keyboardHeight) { _, newValue in
251
+ if newValue != 0 {
252
+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + 0.1 ) {
253
+ withAnimation {
254
+ proxy. scrollTo ( " nextButton " , anchor: . bottom)
255
+ }
256
+ }
257
+ }
258
+ }
259
+ . overlay ( alignment: . top) {
260
+ ToolTipView ( )
261
+ . padding ( . top, 5 )
262
+ . opacity ( store. state. isToolTipPresented ? 1 : 0 )
263
+ . task {
264
+ do {
265
+ try await Task . sleep ( for: . seconds( 3 ) )
266
+ store. dispatch ( . updateToolTipState)
267
+ } catch {
268
+
269
+ }
270
+ }
271
+ }
228
272
}
229
273
}
230
274
}
0 commit comments