wip
This commit is contained in:
parent
bf7110f5e2
commit
ebe624605b
|
@ -212,6 +212,10 @@ private extension NewStatusViewController {
|
||||||
|
|
||||||
configuration.preferredAssetRepresentationMode = .current
|
configuration.preferredAssetRepresentationMode = .current
|
||||||
|
|
||||||
|
if !compositionViewModel.canAddNonImageAttachment {
|
||||||
|
configuration.filter = .images
|
||||||
|
}
|
||||||
|
|
||||||
let picker = PHPickerViewController(configuration: configuration)
|
let picker = PHPickerViewController(configuration: configuration)
|
||||||
|
|
||||||
picker.modalPresentationStyle = .overFullScreen
|
picker.modalPresentationStyle = .overFullScreen
|
||||||
|
@ -259,9 +263,15 @@ private extension NewStatusViewController {
|
||||||
|
|
||||||
picker.sourceType = .camera
|
picker.sourceType = .camera
|
||||||
picker.allowsEditing = true
|
picker.allowsEditing = true
|
||||||
picker.mediaTypes = [UTType.image.description, UTType.movie.description]
|
|
||||||
picker.modalPresentationStyle = .overFullScreen
|
picker.modalPresentationStyle = .overFullScreen
|
||||||
picker.delegate = self
|
picker.delegate = self
|
||||||
|
|
||||||
|
if compositionViewModel.canAddNonImageAttachment {
|
||||||
|
picker.mediaTypes = [UTType.image.description, UTType.movie.description]
|
||||||
|
} else {
|
||||||
|
picker.mediaTypes = [UTType.image.description]
|
||||||
|
}
|
||||||
|
|
||||||
present(picker, animated: true)
|
present(picker, animated: true)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,8 +12,10 @@ public final class CompositionViewModel: ObservableObject, Identifiable {
|
||||||
@Published public var contentWarning = ""
|
@Published public var contentWarning = ""
|
||||||
@Published public var displayContentWarning = false
|
@Published public var displayContentWarning = false
|
||||||
@Published public private(set) var attachmentViewModels = [CompositionAttachmentViewModel]()
|
@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 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>()
|
private var cancellables = Set<AnyCancellable>()
|
||||||
|
|
||||||
|
@ -25,6 +27,11 @@ public final class CompositionViewModel: ObservableObject, Identifiable {
|
||||||
textPresent || attachmentPresent
|
textPresent || attachmentPresent
|
||||||
}
|
}
|
||||||
.assign(to: &$isPostable)
|
.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()
|
.eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private extension CompositionViewModel {
|
||||||
|
static let maxAttachmentCount = 4
|
||||||
|
}
|
||||||
|
|
|
@ -60,10 +60,10 @@ private extension CompositionInputAccessoryView {
|
||||||
},
|
},
|
||||||
for: .touchUpInside)
|
for: .touchUpInside)
|
||||||
|
|
||||||
#if !IS_SHARE_EXTENSION
|
|
||||||
if AVCaptureDevice.authorizationStatus(for: .video) != .restricted {
|
|
||||||
let cameraButton = UIButton()
|
let cameraButton = UIButton()
|
||||||
|
|
||||||
|
#if !IS_SHARE_EXTENSION
|
||||||
|
if AVCaptureDevice.authorizationStatus(for: .video) != .restricted {
|
||||||
stackView.addArrangedSubview(cameraButton)
|
stackView.addArrangedSubview(cameraButton)
|
||||||
cameraButton.setImage(
|
cameraButton.setImage(
|
||||||
UIImage(
|
UIImage(
|
||||||
|
@ -121,6 +121,13 @@ private extension CompositionInputAccessoryView {
|
||||||
self.parentViewModel.insert(after: self.viewModel)
|
self.parentViewModel.insert(after: self.viewModel)
|
||||||
}, for: .touchUpInside)
|
}, for: .touchUpInside)
|
||||||
|
|
||||||
|
viewModel.$canAddAttachment
|
||||||
|
.sink {
|
||||||
|
mediaButton.isEnabled = $0
|
||||||
|
cameraButton.isEnabled = $0
|
||||||
|
}
|
||||||
|
.store(in: &cancellables)
|
||||||
|
|
||||||
viewModel.$isPostable
|
viewModel.$isPostable
|
||||||
.sink { [weak self] in self?.addButton.isEnabled = $0 }
|
.sink { [weak self] in self?.addButton.isEnabled = $0 }
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
|
|
Loading…
Reference in New Issue