@@ -29,74 +29,99 @@ struct TargetDdaySettingView: View {
2929 @Binding var month : String
3030 @Binding var day : String
3131 @Binding var warningMessage : String
32+ @State private var keyboardHeight : CGFloat = 0
33+
3234 var body : some View {
33- ScrollView ( . vertical, showsIndicators: false ) {
34- VStack {
35- Spacer ( )
36- . frame ( height: 50 . adjustedH)
37-
38- HStack ( spacing: 0 ) {
39- VStack ( alignment: . leading, spacing: 0 ) {
40- TypographyText ( " 회복을 계획할 때 고려해야 할 " , style: . title1_sb_18, color: . gray1000)
41- . frame ( height: 27 . adjustedH)
42- TypographyText ( " 중요한 일정이 있나요? " , style: . title1_sb_18, color: . gray1000)
43- . frame ( height: 27 . adjustedH)
35+ ScrollViewReader { proxy in
36+ ScrollView ( . vertical, showsIndicators: false ) {
37+ VStack {
38+ Spacer ( )
39+ . frame ( height: 50 . adjustedH)
40+
41+ HStack ( spacing: 0 ) {
42+ VStack ( alignment: . leading, spacing: 0 ) {
43+ TypographyText ( " 회복을 계획할 때 고려해야 할 " , style: . title1_sb_18, color: . gray1000)
44+ . frame ( height: 27 . adjustedH)
45+ TypographyText ( " 중요한 일정이 있나요? " , style: . title1_sb_18, color: . gray1000)
46+ . frame ( height: 27 . adjustedH)
47+ }
48+ Spacer ( )
4449 }
4550 Spacer ( )
46- }
47- Spacer ( )
48- . frame ( height : 40 . adjustedH )
49-
50- HStack ( spacing : 12 . adjustedW ) {
51- ForEach ( DdayState . allCases , id : \ . self ) { state in
52- SelectionChip (
53- title : state . title ,
54- isSelected : Binding (
55- get : {
56- dDayState == state
57- } ,
58- set : { isSelected in
59- guard isSelected else {
60- return
51+ . frame ( height : 40 . adjustedH )
52+
53+ HStack ( spacing : 12 . adjustedW ) {
54+ ForEach ( DdayState . allCases , id : \ . self ) { state in
55+ SelectionChip (
56+ title : state . title ,
57+ isSelected : Binding (
58+ get : {
59+ dDayState == state
60+ } ,
61+ set : { isSelected in
62+ guard isSelected else {
63+ return
64+ }
65+ dDayState = state
6166 }
62- dDayState = state
63- }
67+ )
6468 )
65- )
69+ }
6670 }
67- }
68-
69- Spacer ( )
70- . frame ( height : 56 . adjustedH )
71-
72- if let state = dDayState {
73- HStack ( spacing: 0 ) {
74- VStack ( alignment : . leading , spacing : 0 ) {
75- switch state {
76- case . yes :
77- TypographyText ( " 언제까지 회복이 완료되면 좋을까요? " , style : . title1_sb_18 , color : . gray1000 )
78- . frame ( height : 27 . adjustedH )
79- case . no :
80- TypographyText ( " 대략적인 회복 목표일을 정해볼까요? " , style : . title1_sb_18 , color : . gray1000 )
81- . frame ( height : 27 . adjustedH )
71+
72+ Spacer ( )
73+ . frame ( height : 56 . adjustedH )
74+
75+ if let state = dDayState {
76+ HStack ( spacing : 0 ) {
77+ VStack ( alignment : . leading , spacing: 0 ) {
78+ switch state {
79+ case . yes :
80+ TypographyText ( " 언제까지 회복이 완료되면 좋을까요? " , style : . title1_sb_18 , color : . gray1000 )
81+ . frame ( height : 27 . adjustedH )
82+ case . no :
83+ TypographyText ( " 대략적인 회복 목표일을 정해볼까요? " , style : . title1_sb_18 , color : . gray1000 )
84+ . frame ( height : 27 . adjustedH )
85+ }
8286 }
87+ Spacer ( )
88+
8389 }
90+
8491 Spacer ( )
92+ . frame ( height: 24 . adjustedH)
93+
94+ DateTextBox ( year: $year, month: $month, day: $day)
95+ . id ( " inputField " )
96+ . padding ( . bottom, 12 . adjustedH)
97+ TreatmentWarningMessgeView ( text: warningMessage)
8598
99+ Spacer ( )
100+ . frame ( height: keyboardHeight)
86101 }
87102
88- Spacer ( )
89- . frame ( height: 24 . adjustedH)
90-
91- DateTextBox ( year: $year, month: $month, day: $day)
92- . padding ( . bottom, 12 . adjustedH)
93- TreatmentWarningMessgeView ( text: warningMessage)
94- Spacer ( )
103+ }
104+
105+ . padding ( . horizontal, 34 . adjustedW)
106+ }
107+ . onReceive ( NotificationCenter . default. publisher ( for: UIResponder . keyboardWillShowNotification) ) { notification in
108+ if let keyboardFrame = notification. userInfo ? [ UIResponder . keyboardFrameEndUserInfoKey] as? CGRect {
109+ keyboardHeight = keyboardFrame. height
110+ }
111+ }
112+ . onReceive ( NotificationCenter . default. publisher ( for: UIResponder . keyboardWillHideNotification) ) { _ in
113+ withAnimation ( . easeOut( duration: 0.25 ) ) {
114+ keyboardHeight = 0
115+ }
116+ }
117+ . onChange ( of: keyboardHeight) { _, newValue in
118+ if newValue > 0 {
119+ withAnimation ( . easeOut( duration: 0.25 ) ) {
120+ proxy. scrollTo ( " inputField " , anchor: . center)
121+ }
95122 }
96123 }
97- . padding ( . horizontal, 34 . adjustedW)
98124 }
99- . scrollDismissesKeyboard ( . interactively)
100125 }
101126}
102127
0 commit comments