parent
081ef16e5e
commit
71a57e9859
|
@ -16,6 +16,7 @@ protocol ComposeUIStateDelegate: AnyObject {
|
||||||
func presentAssetPickerSheet()
|
func presentAssetPickerSheet()
|
||||||
func presentComposeDrawing()
|
func presentComposeDrawing()
|
||||||
func selectDraft(_ draft: Draft)
|
func selectDraft(_ draft: Draft)
|
||||||
|
func paste(itemProviders: [NSItemProvider])
|
||||||
}
|
}
|
||||||
|
|
||||||
class ComposeUIState: ObservableObject {
|
class ComposeUIState: ObservableObject {
|
||||||
|
|
|
@ -72,8 +72,24 @@ struct ComposeView: View {
|
||||||
return attachmentIds.contains { uiState.attachmentsMissingDescriptions.contains($0) }
|
return attachmentIds.contains { uiState.attachmentsMissingDescriptions.contains($0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var validAttachmentCombination: Bool {
|
||||||
|
if !mastodonController.instanceFeatures.mastodonAttachmentRestrictions {
|
||||||
|
return true
|
||||||
|
} else if draft.attachments.contains(where: { $0.data.type == .video }) && draft.attachments.count > 1 {
|
||||||
|
return false
|
||||||
|
} else if draft.attachments.count > 4 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
private var postButtonEnabled: Bool {
|
private var postButtonEnabled: Bool {
|
||||||
draft.hasContent && charactersRemaining >= 0 && !isPosting && !requiresAttachmentDescriptions && (draft.poll == nil || draft.poll!.options.allSatisfy { !$0.text.isEmpty })
|
draft.hasContent
|
||||||
|
&& charactersRemaining >= 0
|
||||||
|
&& !isPosting
|
||||||
|
&& !requiresAttachmentDescriptions
|
||||||
|
&& validAttachmentCombination
|
||||||
|
&& (draft.poll == nil || draft.poll!.options.allSatisfy { !$0.text.isEmpty })
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
|
|
@ -83,7 +83,7 @@ struct MainComposeWrappedTextView: UIViewRepresentable {
|
||||||
@Environment(\.isEnabled) var isEnabled: Bool
|
@Environment(\.isEnabled) var isEnabled: Bool
|
||||||
|
|
||||||
func makeUIView(context: Context) -> UITextView {
|
func makeUIView(context: Context) -> UITextView {
|
||||||
let textView = WrappedTextView()
|
let textView = WrappedTextView(uiState: uiState)
|
||||||
textView.delegate = context.coordinator
|
textView.delegate = context.coordinator
|
||||||
textView.isEditable = true
|
textView.isEditable = true
|
||||||
textView.backgroundColor = .clear
|
textView.backgroundColor = .clear
|
||||||
|
@ -128,6 +128,16 @@ struct MainComposeWrappedTextView: UIViewRepresentable {
|
||||||
|
|
||||||
class WrappedTextView: UITextView {
|
class WrappedTextView: UITextView {
|
||||||
private let formattingActions = [#selector(toggleBoldface(_:)), #selector(toggleItalics(_:))]
|
private let formattingActions = [#selector(toggleBoldface(_:)), #selector(toggleItalics(_:))]
|
||||||
|
unowned var uiState: ComposeUIState
|
||||||
|
|
||||||
|
init(uiState: ComposeUIState) {
|
||||||
|
self.uiState = uiState
|
||||||
|
super.init(frame: .zero, textContainer: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder: NSCoder) {
|
||||||
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
}
|
||||||
|
|
||||||
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
|
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
|
||||||
if formattingActions.contains(action) {
|
if formattingActions.contains(action) {
|
||||||
|
@ -154,6 +164,14 @@ struct MainComposeWrappedTextView: UIViewRepresentable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func paste(_ sender: Any?) {
|
||||||
|
if UIPasteboard.general.contains(pasteboardTypes: CompositionAttachment.readableTypeIdentifiersForItemProvider) {
|
||||||
|
uiState.delegate?.paste(itemProviders: UIPasteboard.general.itemProviders)
|
||||||
|
} else {
|
||||||
|
super.paste(sender)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Coordinator: NSObject, UITextViewDelegate, ComposeInput, ComposeTextViewCaretScrolling {
|
class Coordinator: NSObject, UITextViewDelegate, ComposeInput, ComposeTextViewCaretScrolling {
|
||||||
|
|
Loading…
Reference in New Issue