diff --git a/Projects/Feature/BottleStorage/Interface/Sources/PingPongDetail/View/SubViews/QuestionAndAnswer/QuestionAndAnswerFeature.swift b/Projects/Feature/BottleStorage/Interface/Sources/PingPongDetail/View/SubViews/QuestionAndAnswer/QuestionAndAnswerFeature.swift index a03ed829..0f982c5f 100644 --- a/Projects/Feature/BottleStorage/Interface/Sources/PingPongDetail/View/SubViews/QuestionAndAnswer/QuestionAndAnswerFeature.swift +++ b/Projects/Feature/BottleStorage/Interface/Sources/PingPongDetail/View/SubViews/QuestionAndAnswer/QuestionAndAnswerFeature.swift @@ -24,6 +24,22 @@ extension QuestionAndAnswerFeature { state.configurePingPong(pingPong) return .none + case let .focusedFieldDidChanged(field): + guard let previousFocusedField = state.focusedField else { + state.focusedField = field + return .none + } + + if (previousFocusedField == .firstLetter && state.firstLetterTextFieldContent.count >= 50) || + (previousFocusedField == .secondLetter && state.secondLetterTextFieldContent.count >= 50) || + (previousFocusedField == .thirdLetter && state.thirdLetterTextFieldContent.count >= 50) { + state.textFieldState = .active + } else { + state.textFieldState = .enabled + } + + return .none + case let .texFieldDidFocused(isFocused): state.textFieldState = isFocused ? .focused : .active return .none diff --git a/Projects/Feature/BottleStorage/Interface/Sources/PingPongDetail/View/SubViews/QuestionAndAnswer/QuestionAndAnswerFeatureInterface.swift b/Projects/Feature/BottleStorage/Interface/Sources/PingPongDetail/View/SubViews/QuestionAndAnswer/QuestionAndAnswerFeatureInterface.swift index 770ba42a..f04ba697 100644 --- a/Projects/Feature/BottleStorage/Interface/Sources/PingPongDetail/View/SubViews/QuestionAndAnswer/QuestionAndAnswerFeatureInterface.swift +++ b/Projects/Feature/BottleStorage/Interface/Sources/PingPongDetail/View/SubViews/QuestionAndAnswer/QuestionAndAnswerFeatureInterface.swift @@ -20,6 +20,12 @@ public struct QuestionAndAnswerFeature { self.reducer = reducer } + public enum FocusField: Hashable { + case firstLetter + case secondLetter + case thirdLetter + } + @ObservableState public struct State: Equatable { let bottleID: Int @@ -82,7 +88,8 @@ public struct QuestionAndAnswerFeature { var thirdLetterTextFieldContent: String var textFieldState: TextFieldState - + var focusedField: FocusField? = nil + // 사진 선택 var photoShareIsActive: Bool { guard let photoStatus = pingPong?.photo.photoStatus @@ -177,6 +184,7 @@ public struct QuestionAndAnswerFeature { case stopTalkButtonDidTapped case refreshDidPulled + case focusedFieldDidChanged(FocusField?) // ETC. case binding(BindingAction) diff --git a/Projects/Feature/BottleStorage/Interface/Sources/PingPongDetail/View/SubViews/QuestionAndAnswer/QuestionAndAnswerView.swift b/Projects/Feature/BottleStorage/Interface/Sources/PingPongDetail/View/SubViews/QuestionAndAnswer/QuestionAndAnswerView.swift index 24270272..23b2f9a1 100644 --- a/Projects/Feature/BottleStorage/Interface/Sources/PingPongDetail/View/SubViews/QuestionAndAnswer/QuestionAndAnswerView.swift +++ b/Projects/Feature/BottleStorage/Interface/Sources/PingPongDetail/View/SubViews/QuestionAndAnswer/QuestionAndAnswerView.swift @@ -14,7 +14,7 @@ import ComposableArchitecture public struct QuestionAndAnswerView: View { @Perception.Bindable private var store: StoreOf - @FocusState private var isTextFieldFocused: Bool + @FocusState private var focusedField: QuestionAndAnswerFeature.FocusField? public init(store: StoreOf) { self.store = store @@ -39,8 +39,8 @@ public struct QuestionAndAnswerView: View { )) } ) - .focused($isTextFieldFocused) - + .focused($focusedField, equals: .firstLetter) + QuestionPingPongView( pingpongTitle: "두 번째 질문", textFieldContent: $store.secondLetterTextFieldContent, @@ -55,8 +55,8 @@ public struct QuestionAndAnswerView: View { )) } ) - .focused($isTextFieldFocused) - + .focused($focusedField, equals: .secondLetter) + QuestionPingPongView( pingpongTitle: "세 번째 질문", textFieldContent: $store.thirdLetterTextFieldContent, @@ -71,8 +71,8 @@ public struct QuestionAndAnswerView: View { )) } ) - .focused($isTextFieldFocused) - + .focused($focusedField, equals: .thirdLetter) + PhotoSharePingPongView( isActive: store.photoShareIsActive, pingPongTitle: "사진 공개", @@ -117,11 +117,8 @@ public struct QuestionAndAnswerView: View { } .padding(.md) .frame(maxWidth: .infinity) - .onChange(of: isTextFieldFocused) { isFocused in - store.send(.texFieldDidFocused(isFocused: isFocused)) - } - .onChange(of: store.textFieldState) { textFieldState in - isTextFieldFocused = textFieldState == .active || textFieldState == .enabled ? false : true + .onChange(of: focusedField) { field in + store.send(.focusedFieldDidChanged(field)) } } .refreshable { diff --git a/Projects/Shared/DesignSystem/Sources/Components/TextField/LinesTextField/LinesTextField.swift b/Projects/Shared/DesignSystem/Sources/Components/TextField/LinesTextField/LinesTextField.swift index a8dd57db..ea971cb9 100644 --- a/Projects/Shared/DesignSystem/Sources/Components/TextField/LinesTextField/LinesTextField.swift +++ b/Projects/Shared/DesignSystem/Sources/Components/TextField/LinesTextField/LinesTextField.swift @@ -109,6 +109,10 @@ private extension LinesTextField { if newValue.count >= textLimit { text = String(text.prefix(textLimit)) } + + if newValue.count == 0 { + textFieldState = .enabled + } } } }