feat(fantalk): 쓰기 입력 제한을 적용한다
This commit is contained in:
@@ -25,12 +25,27 @@ struct CreatorChannelFanTalkWriteView: View {
|
||||
VStack(spacing: 0) {
|
||||
navigationBar
|
||||
|
||||
TextEditor(text: $viewModel.content)
|
||||
TextEditor(text: Binding(
|
||||
get: { viewModel.content },
|
||||
set: { newValue in
|
||||
viewModel.content = String(newValue.prefix(viewModel.maxContentCount))
|
||||
}
|
||||
))
|
||||
.appFont(size: 16, weight: .regular)
|
||||
.foregroundColor(Color.white)
|
||||
.foregroundColor(viewModel.isContentOverLimit ? Color.red400 : Color.white)
|
||||
.accentColor(Color.soda400)
|
||||
.scrollContentBackground(.hidden)
|
||||
.background(Color.black)
|
||||
.overlay(alignment: .topLeading) {
|
||||
if viewModel.content.isEmpty {
|
||||
Text(I18n.CreatorChannelFanTalk.writePlaceholder)
|
||||
.appFont(size: 16, weight: .regular)
|
||||
.foregroundColor(Color.gray500)
|
||||
.padding(.horizontal, SodaSpacing.s4)
|
||||
.padding(.vertical, SodaSpacing.s8)
|
||||
.allowsHitTesting(false)
|
||||
}
|
||||
}
|
||||
.focused($isFocused)
|
||||
.padding(.horizontal, SodaSpacing.s14)
|
||||
.padding(.top, SodaSpacing.s20)
|
||||
@@ -56,7 +71,6 @@ struct CreatorChannelFanTalkWriteView: View {
|
||||
Text(I18n.Common.cancel)
|
||||
.appFont(size: 16, weight: .regular)
|
||||
.foregroundColor(Color.white)
|
||||
.frame(width: 64, height: 56, alignment: .leading)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
|
||||
@@ -85,8 +99,8 @@ struct CreatorChannelFanTalkWriteView: View {
|
||||
|
||||
Text("\(viewModel.content.count)")
|
||||
.appFont(size: 16, weight: .medium)
|
||||
.foregroundColor(Color.white)
|
||||
Text("/\(viewModel.maxContentCount)자")
|
||||
.foregroundColor(viewModel.isContentOverLimit ? Color.red400 : Color.white)
|
||||
Text("/\(viewModel.maxContentCount)")
|
||||
.appFont(size: 16, weight: .medium)
|
||||
.foregroundColor(Color.gray500)
|
||||
}
|
||||
|
||||
@@ -29,7 +29,15 @@ final class CreatorChannelFanTalkWriteViewModel: ObservableObject {
|
||||
|
||||
let maxContentCount = 500
|
||||
|
||||
var isContentOverLimit: Bool {
|
||||
content.count > maxContentCount
|
||||
}
|
||||
|
||||
var canSend: Bool {
|
||||
hasContent && isContentOverLimit == false
|
||||
}
|
||||
|
||||
private var hasContent: Bool {
|
||||
content.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == false
|
||||
}
|
||||
|
||||
@@ -40,7 +48,7 @@ final class CreatorChannelFanTalkWriteViewModel: ObservableObject {
|
||||
}
|
||||
|
||||
func handleCancel() -> Bool {
|
||||
guard canSend else { return true }
|
||||
guard hasContent else { return true }
|
||||
|
||||
shouldShowExitModal = true
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user