mirror of
https://github.com/metabolist/metatext.git
synced 2024-12-24 14:30:28 +00:00
wip
This commit is contained in:
parent
bf7110f5e2
commit
ebe624605b
3 changed files with 32 additions and 4 deletions
|
@ -212,6 +212,10 @@ private extension NewStatusViewController {
|
|||
|
||||
configuration.preferredAssetRepresentationMode = .current
|
||||
|
||||
if !compositionViewModel.canAddNonImageAttachment {
|
||||
configuration.filter = .images
|
||||
}
|
||||
|
||||
let picker = PHPickerViewController(configuration: configuration)
|
||||
|
||||
picker.modalPresentationStyle = .overFullScreen
|
||||
|
@ -259,9 +263,15 @@ private extension NewStatusViewController {
|
|||
|
||||
picker.sourceType = .camera
|
||||
picker.allowsEditing = true
|
||||
picker.mediaTypes = [UTType.image.description, UTType.movie.description]
|
||||
picker.modalPresentationStyle = .overFullScreen
|
||||
picker.delegate = self
|
||||
|
||||
if compositionViewModel.canAddNonImageAttachment {
|
||||
picker.mediaTypes = [UTType.image.description, UTType.movie.description]
|
||||
} else {
|
||||
picker.mediaTypes = [UTType.image.description]
|
||||
}
|
||||
|
||||
present(picker, animated: true)
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -12,8 +12,10 @@ public final class CompositionViewModel: ObservableObject, Identifiable {
|
|||
@Published public var contentWarning = ""
|
||||
@Published public var displayContentWarning = false
|
||||
@Published public private(set) var attachmentViewModels = [CompositionAttachmentViewModel]()
|
||||
@Published public private(set) var isPostable = false
|
||||
@Published public private(set) var attachmentUpload: AttachmentUpload?
|
||||
@Published public private(set) var isPostable = false
|
||||
@Published public private(set) var canAddAttachment = true
|
||||
@Published public private(set) var canAddNonImageAttachment = true
|
||||
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
|
@ -25,6 +27,11 @@ public final class CompositionViewModel: ObservableObject, Identifiable {
|
|||
textPresent || attachmentPresent
|
||||
}
|
||||
.assign(to: &$isPostable)
|
||||
$attachmentViewModels
|
||||
.combineLatest($attachmentUpload)
|
||||
.map { $0.count < Self.maxAttachmentCount && $1 == nil }
|
||||
.assign(to: &$canAddAttachment)
|
||||
$attachmentViewModels.map(\.isEmpty).assign(to: &$canAddNonImageAttachment)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,3 +82,7 @@ extension CompositionViewModel {
|
|||
.eraseToAnyPublisher()
|
||||
}
|
||||
}
|
||||
|
||||
private extension CompositionViewModel {
|
||||
static let maxAttachmentCount = 4
|
||||
}
|
||||
|
|
|
@ -60,10 +60,10 @@ private extension CompositionInputAccessoryView {
|
|||
},
|
||||
for: .touchUpInside)
|
||||
|
||||
let cameraButton = UIButton()
|
||||
|
||||
#if !IS_SHARE_EXTENSION
|
||||
if AVCaptureDevice.authorizationStatus(for: .video) != .restricted {
|
||||
let cameraButton = UIButton()
|
||||
|
||||
stackView.addArrangedSubview(cameraButton)
|
||||
cameraButton.setImage(
|
||||
UIImage(
|
||||
|
@ -121,6 +121,13 @@ private extension CompositionInputAccessoryView {
|
|||
self.parentViewModel.insert(after: self.viewModel)
|
||||
}, for: .touchUpInside)
|
||||
|
||||
viewModel.$canAddAttachment
|
||||
.sink {
|
||||
mediaButton.isEnabled = $0
|
||||
cameraButton.isEnabled = $0
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
viewModel.$isPostable
|
||||
.sink { [weak self] in self?.addButton.isEnabled = $0 }
|
||||
.store(in: &cancellables)
|
||||
|
|
Loading…
Reference in a new issue