Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -177,6 +184,7 @@ public struct QuestionAndAnswerFeature {
case stopTalkButtonDidTapped
case refreshDidPulled

case focusedFieldDidChanged(FocusField?)
// ETC.
case binding(BindingAction<State>)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import ComposableArchitecture

public struct QuestionAndAnswerView: View {
@Perception.Bindable private var store: StoreOf<QuestionAndAnswerFeature>
@FocusState private var isTextFieldFocused: Bool
@FocusState private var focusedField: QuestionAndAnswerFeature.FocusField?

public init(store: StoreOf<QuestionAndAnswerFeature>) {
self.store = store
Expand All @@ -39,8 +39,8 @@ public struct QuestionAndAnswerView: View {
))
}
)
.focused($isTextFieldFocused)
.focused($focusedField, equals: .firstLetter)

QuestionPingPongView(
pingpongTitle: "두 번째 질문",
textFieldContent: $store.secondLetterTextFieldContent,
Expand All @@ -55,8 +55,8 @@ public struct QuestionAndAnswerView: View {
))
}
)
.focused($isTextFieldFocused)
.focused($focusedField, equals: .secondLetter)

QuestionPingPongView(
pingpongTitle: "세 번째 질문",
textFieldContent: $store.thirdLetterTextFieldContent,
Expand All @@ -71,8 +71,8 @@ public struct QuestionAndAnswerView: View {
))
}
)
.focused($isTextFieldFocused)
.focused($focusedField, equals: .thirdLetter)

PhotoSharePingPongView(
isActive: store.photoShareIsActive,
pingPongTitle: "사진 공개",
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ private extension LinesTextField {
if newValue.count >= textLimit {
text = String(text.prefix(textLimit))
}

if newValue.count == 0 {
textFieldState = .enabled
}
}
}
}
Expand Down