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