Skip to content

Commit 689b8ad

Browse files
committed
feat: add presentation style
1 parent 541e3ae commit 689b8ad

4 files changed

Lines changed: 34 additions & 18 deletions

File tree

Sources/IONCameraLib/Interfaces/IONCAMRPickerBehaviour.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ final class IONCAMRPickerBehaviour: NSObject, IONCAMRPickerDelegate {
2121
pickerController.cameraDevice = mediaOptions.cameraDevice
2222
pickerController.videoQuality = .typeHigh
2323
pickerController.delegate = self
24+
pickerController.modalPresentationStyle = mediaOptions.presentationStyle.uiModalPresentationStyle
2425
handler(pickerController)
2526
}
2627
}

Sources/IONCameraLib/Models/IONCAMRMediaOptions.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ public class IONCAMRMediaOptions: IONCAMREditMediaTypeOptionsDelegate, IONCAMRSa
88
let direction: IONCAMRDirection
99
/// Indicates if an edit step should be added to the Take Picture or Choose from Gallery.
1010
var allowEdit: Bool
11+
/// Presentation style to use when showing the camera interface. Default is `.fullScreen`.
12+
var presentationStyle: IONCAMRPresentationStyle = .fullScreen
1113

1214
init(mediaType: IONCAMRMediaType, saveToGallery: Bool, returnMetadata: Bool, direction: IONCAMRDirection, allowEdit: Bool) {
1315
self.mediaType = mediaType
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import UIKit
2+
3+
public enum IONCAMRPresentationStyle : String, Codable {
4+
case fullScreen
5+
case popover
6+
7+
var uiModalPresentationStyle: UIModalPresentationStyle {
8+
switch self {
9+
case .fullScreen:
10+
return .fullScreen
11+
case .popover:
12+
return .popover
13+
}
14+
}
15+
}

Sources/IONCameraLib/Models/IONCAMRTakePhotoOptions.swift

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class IONCAMRTakePhotoOptions: IONCAMRMediaOptions, Decodable {
1414
let encodingType: IONCAMREncodingType
1515

1616
private enum CodingKeys: String, CodingKey {
17-
case quality, width, height, correctOrientation, encodingType, saveToGallery, cameraDirection, allowEdit, includeMetadata
17+
case quality, width, height, correctOrientation, encodingType, saveToGallery, cameraDirection, allowEdit, includeMetadata, presentationStyle
1818
}
1919

2020
required public convenience init(from decoder: Decoder) throws {
@@ -26,30 +26,20 @@ public class IONCAMRTakePhotoOptions: IONCAMRMediaOptions, Decodable {
2626

2727
let quality = try container.decodeIfPresent(Int.self, forKey: .quality) ?? 90
2828
if quality < 0 || quality > 100 { throw throwError(field: "quality") }
29-
3029
var size: IONCAMRSize? = nil
3130
let width = try container.decodeIfPresent(Int.self, forKey: .width)
3231
let height = try container.decodeIfPresent(Int.self, forKey: .height)
3332
if let width = width, let height = height {
3433
size = try IONCAMRSize(width: width, height: height)
3534
}
36-
3735
let correctOrientation = try container.decodeIfPresent(Bool.self, forKey: .correctOrientation) ?? false
38-
guard
39-
let encodingType = IONCAMREncodingType(rawValue: try container.decodeIfPresent(Int.self, forKey: .encodingType) ?? 0)
40-
else {
41-
throw throwError(field: "encodingType")
42-
}
43-
36+
let encodingType = try container.decodeIfPresent(IONCAMREncodingType.self, forKey: .encodingType) ?? .jpeg
4437
let saveToGallery = try container.decodeIfPresent(Bool.self, forKey: .saveToGallery) ?? false
45-
guard
46-
let cameraDirection = IONCAMRDirection(rawValue: try container.decodeIfPresent(String.self, forKey: .cameraDirection) ?? IONCAMRDirection.back.rawValue)
47-
else {
48-
throw throwError(field: "cameraDirection")
49-
}
50-
38+
let cameraDirection = try container.decodeIfPresent(IONCAMRDirection.self, forKey: .cameraDirection) ?? .back
5139
let allowEdit = try container.decodeIfPresent(Bool.self, forKey: .allowEdit) ?? false
5240
let includeMetadata = try container.decodeIfPresent(Bool.self, forKey: .includeMetadata) ?? false
41+
let presentationStyle = try container.decodeIfPresent(IONCAMRPresentationStyle.self, forKey: .presentationStyle) ?? .fullScreen
42+
5343
try self.init(
5444
quality: quality,
5545
size: size,
@@ -58,7 +48,8 @@ public class IONCAMRTakePhotoOptions: IONCAMRMediaOptions, Decodable {
5848
saveToGallery: saveToGallery,
5949
cameraDirection: cameraDirection,
6050
allowEdit: allowEdit,
61-
returnMetadata: includeMetadata
51+
returnMetadata: includeMetadata,
52+
presentationStyle: presentationStyle
6253
)
6354
}
6455

@@ -70,7 +61,8 @@ public class IONCAMRTakePhotoOptions: IONCAMRMediaOptions, Decodable {
7061
saveToGallery: Bool,
7162
cameraDirection: IONCAMRDirection,
7263
allowEdit: Bool,
73-
returnMetadata: Bool
64+
returnMetadata: Bool,
65+
presentationStyle: IONCAMRPresentationStyle = .fullScreen
7466
) throws {
7567
func throwError(field: String) -> IONCAMRTakePhotoOptionsError {
7668
IONCAMRTakePhotoOptionsError.invalid(field: field)
@@ -85,8 +77,14 @@ public class IONCAMRTakePhotoOptions: IONCAMRMediaOptions, Decodable {
8577
self.size = size
8678
self.correctOrientation = correctOrientation
8779
self.encodingType = encodingType
80+
self.presentationStyle = presentationStyle
8881
super.init(
89-
mediaType: .picture, saveToGallery: saveToGallery, returnMetadata: returnMetadata, direction: cameraDirection, allowEdit: allowEdit
82+
mediaType: .picture,
83+
saveToGallery: saveToGallery,
84+
returnMetadata: returnMetadata,
85+
direction: cameraDirection,
86+
allowEdit: allowEdit,
87+
presentationStyle: presentationStyle
9088
)
9189
}
9290
}

0 commit comments

Comments
 (0)