Remove old EmojiTextField code
This commit is contained in:
parent
1d81510899
commit
56a408355d
@ -16,15 +16,9 @@ struct ContentWarningTextField: View {
|
||||
text: $draft.contentWarning,
|
||||
placeholder: "Write your warning here",
|
||||
maxLength: nil,
|
||||
// TODO: completely replace this with FocusState
|
||||
becomeFirstResponder: .constant(false),
|
||||
focusNextView: Binding(get: {
|
||||
false
|
||||
}, set: {
|
||||
if $0 {
|
||||
focusedField = .body
|
||||
}
|
||||
})
|
||||
focusNextView: {
|
||||
focusedField = .body
|
||||
}
|
||||
)
|
||||
.focused($focusedField, equals: .contentWarning)
|
||||
.modifier(FocusedInputModifier())
|
||||
|
@ -17,14 +17,12 @@ struct EmojiTextField: UIViewRepresentable {
|
||||
@Binding var text: String
|
||||
let placeholder: String
|
||||
let maxLength: Int?
|
||||
let becomeFirstResponder: Binding<Bool>?
|
||||
let focusNextView: Binding<Bool>?
|
||||
let focusNextView: (() -> Void)?
|
||||
|
||||
init(text: Binding<String>, placeholder: String, maxLength: Int?, becomeFirstResponder: Binding<Bool>? = nil, focusNextView: Binding<Bool>? = nil) {
|
||||
init(text: Binding<String>, placeholder: String, maxLength: Int?, focusNextView: (() -> Void)? = nil) {
|
||||
self._text = text
|
||||
self.placeholder = placeholder
|
||||
self.maxLength = maxLength
|
||||
self.becomeFirstResponder = becomeFirstResponder
|
||||
self.focusNextView = focusNextView
|
||||
}
|
||||
|
||||
@ -66,13 +64,6 @@ struct EmojiTextField: UIViewRepresentable {
|
||||
#if !os(visionOS)
|
||||
uiView.backgroundColor = colorScheme == .dark ? UIColor(fillColor) : .secondarySystemBackground
|
||||
#endif
|
||||
|
||||
if becomeFirstResponder?.wrappedValue == true {
|
||||
DispatchQueue.main.async {
|
||||
uiView.becomeFirstResponder()
|
||||
becomeFirstResponder!.wrappedValue = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func makeCoordinator() -> Coordinator {
|
||||
@ -85,7 +76,7 @@ struct EmojiTextField: UIViewRepresentable {
|
||||
|
||||
class Coordinator: NSObject, UITextFieldDelegate, ComposeInput {
|
||||
var text: Binding<String>
|
||||
var focusNextView: Binding<Bool>?
|
||||
var focusNextView: (() -> Void)?
|
||||
var maxLength: Int?
|
||||
|
||||
@Published var autocompleteState: AutocompleteState?
|
||||
@ -93,7 +84,7 @@ struct EmojiTextField: UIViewRepresentable {
|
||||
|
||||
weak var textField: UITextField?
|
||||
|
||||
init(text: Binding<String>, focusNextView: Binding<Bool>?, maxLength: Int? = nil) {
|
||||
init(text: Binding<String>, focusNextView: (() -> Void)?, maxLength: Int? = nil) {
|
||||
self.text = text
|
||||
self.focusNextView = focusNextView
|
||||
self.maxLength = maxLength
|
||||
@ -104,7 +95,7 @@ struct EmojiTextField: UIViewRepresentable {
|
||||
}
|
||||
|
||||
@objc func returnKeyPressed() {
|
||||
focusNextView?.wrappedValue = true
|
||||
focusNextView?()
|
||||
}
|
||||
|
||||
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
|
||||
|
@ -125,7 +125,7 @@ private struct PollOptionEditor: View {
|
||||
.accessibilityLabel("Remove option")
|
||||
.disabled(poll.options.count == 1)
|
||||
|
||||
EmojiTextField(text: $option.text, placeholder: placeholder, maxLength: instanceFeatures.maxPollOptionChars)
|
||||
EmojiTextField(text: $option.text, placeholder: placeholder, maxLength: instanceFeatures.maxPollOptionChars, focusNextView: self.focusNextOption)
|
||||
.focused($focusedField, equals: .pollOption(option.id))
|
||||
}
|
||||
}
|
||||
@ -145,6 +145,14 @@ private struct PollOptionEditor: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func focusNextOption() {
|
||||
let index = poll.options.index(of: option)
|
||||
if index != NSNotFound && index + 1 < poll.options.count {
|
||||
let nextOption = poll.options.object(at: index + 1) as! PollOption
|
||||
focusedField = .pollOption(nextOption.objectID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct PollOptionButtonStyle: ButtonStyle {
|
||||
|
Loading…
x
Reference in New Issue
Block a user