Skip to content

Commit

Permalink
this can be removed
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjl-mux committed Jun 3, 2024
1 parent c5819ac commit 0b1af3a
Showing 1 changed file with 0 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,95 +217,6 @@ fileprivate struct EmptyView: View {
}
}

fileprivate struct UploadCTA: View {
@EnvironmentObject var uploadCreationModel: UploadCreationModel
@State var inPickFlow = false // True when picking photos or resolving the related permission prompt, or when first launching the screen

private var pickerConfig: PHPickerConfiguration = {
let mediaFilter = PHPickerFilter.any(of: [.videos])
var photoPickerConfig = PHPickerConfiguration(photoLibrary: .shared())
photoPickerConfig.filter = mediaFilter
photoPickerConfig.preferredAssetRepresentationMode = .current
photoPickerConfig.selectionLimit = 1
if #available(iOS 15.0, *) {
photoPickerConfig.selection = .default
}
return photoPickerConfig
}()

var body: some View {
Button { [self] in
switch uploadCreationModel.photosAuthStatus {
case .can_auth(_): do {
inPickFlow = true
uploadCreationModel.requestPhotosAccess()
}
case .authorized(_): do {
inPickFlow = true
}
case .cant_auth(_): do {
NSLog("!! This app cannot ask for or gain Photos access permissions for some reason. We don't expect to see this on a real device unless 'NSPhotoLibraryAddUsageDescription' is gone from the app plist")
}
}
} label : {
BigUploadCTALabel()
}
.contentShape(Rectangle())
.disabled(shouldDisableButton())
.sheet(
isPresented: Binding<Bool>(
get: { self.shouldShowPhotoPicker() },
set: { value, _ in inPickFlow = value && isAuthorizedForPhotos() }
),
content: { ImagePicker(
pickerConfiguration: self.pickerConfig,
delegate: { (images: [PHPickerResult]) in
// Only 0 or 1 images can be selected
if let firstVideo = images.first {
inPickFlow = false
uploadCreationModel.tryToPrepare(from: firstVideo)
}
}
)}
)
.task {
inPickFlow = true
if case .can_auth(_) = uploadCreationModel.photosAuthStatus {
uploadCreationModel.requestPhotosAccess()
}
}
}

private func shouldShowPhotoPicker() -> Bool {
if isAuthorizedForPhotos() {
return inPickFlow
} else {
return false
}
}

private func shouldDisableButton() -> Bool {
if isAuthorizedForPhotos() {
return false
} else {
return inPickFlow
}
}

private func isAuthorizedForPhotos() -> Bool {
switch uploadCreationModel.photosAuthStatus {
case .authorized(_): return true
default: return false
}
}

let actionOnMediaAvailable: (PHAsset, URL) -> Void

init(_ actionOnMediaAvailable: @escaping (PHAsset, URL) -> Void = {_,_ in }) {
self.actionOnMediaAvailable = actionOnMediaAvailable
}
}

struct ContentContainer_Previews: PreviewProvider {
static var previews: some View {
ScreenContentView()
Expand Down

0 comments on commit 0b1af3a

Please sign in to comment.