forked from arthurhammer/FrameGrabber
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewControllerFactory.swift
More file actions
100 lines (76 loc) · 3.64 KB
/
ViewControllerFactory.swift
File metadata and controls
100 lines (76 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import UIKit
import UniformTypeIdentifiers
import Utility
/// Static factory for view controllers.
@MainActor struct ViewControllerFactory {
static func makeAuthorization(withSuccessHandler success: @escaping () -> ()) -> AuthorizationController {
let storyboard = UIStoryboard(name: "Authorization", bundle: nil)
guard let controller = storyboard.instantiateInitialViewController() as? AuthorizationController else {
fatalError("Could not instantiate controller.")
}
controller.didAuthorizeHandler = success
controller.modalPresentationStyle = .formSheet
controller.isModalInPresentation = true
return controller
}
static func makeEditor(
with source: VideoSource,
previewImage: UIImage?,
delegate: EditorViewControllerDelegate?
) -> EditorViewController {
let storyboard = UIStoryboard(name: "Editor", bundle: nil)
let videoController = VideoController(source: source, previewImage: previewImage)
guard let controller = storyboard.instantiateInitialViewController(creator: {
EditorViewController(videoController: videoController, delegate: delegate, coder: $0)
}) else { fatalError("Could not instantiate controller.") }
return controller
}
static func makeAbout(withDelegate delegate: AboutViewControllerDelegate?) -> UIViewController {
let storyboard = UIStoryboard(name: "About", bundle: nil)
guard let navigationController = storyboard.instantiateInitialViewController() as? UINavigationController,
let controller = navigationController.topViewController as? AboutViewController
else {
fatalError("Could not instantiate controller.")
}
controller.delegate = delegate
return navigationController
}
static func makePurchase() -> UIViewController {
let storyboard = UIStoryboard(name: "Purchase", bundle: nil)
guard let controller = storyboard.instantiateInitialViewController() as? PurchaseViewController else {
fatalError("Could not instantiate controller.")
}
controller.configureCompactSheetPresentation()
return controller
}
static func makeFilePicker(withDelegate delegate: UIDocumentPickerDelegate?) -> UIDocumentPickerViewController {
let picker = UIDocumentPickerViewController(
forOpeningContentTypes: [.movie],
asCopy: true
)
picker.shouldShowFileExtensions = true
picker.delegate = delegate
return picker
}
/// A picker configured to record videos if the device can record videos, otherwise `nil`.
///
/// If the preferred camera is not available, falls back to `.rear`.
static func makeCamera(
with preferredCamera: UIImagePickerController.CameraDevice,
delegate: UIImagePickerController.Delegate? = nil
) -> UIImagePickerController? {
guard UIImagePickerController.canRecordVideos else { return nil }
let camera = UIImagePickerController.isCameraDeviceAvailable(preferredCamera)
? preferredCamera
: .rear
let picker = UIImagePickerController()
picker.delegate = delegate
picker.mediaTypes = [UTType.movie.identifier]
picker.sourceType = .camera
picker.cameraCaptureMode = .video
picker.cameraDevice = camera
picker.videoQuality = .typeHigh
picker.modalPresentationStyle = .fullScreen
return picker
}
}