Skip to content

Commit 8b8f302

Browse files
Merge pull request #4 from wordpress-mobile/issue/fix_project_for_ios_12
Fix crash in iOS 12
2 parents 49ce652 + 01e7653 commit 8b8f302

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

MediaEditor.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@
570570
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
571571
GCC_WARN_UNUSED_FUNCTION = YES;
572572
GCC_WARN_UNUSED_VARIABLE = YES;
573-
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
573+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
574574
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
575575
MTL_FAST_MATH = YES;
576576
ONLY_ACTIVE_ARCH = YES;
@@ -627,7 +627,7 @@
627627
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
628628
GCC_WARN_UNUSED_FUNCTION = YES;
629629
GCC_WARN_UNUSED_VARIABLE = YES;
630-
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
630+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
631631
MTL_ENABLE_DEBUG_INFO = NO;
632632
MTL_FAST_MATH = YES;
633633
SDKROOT = iphoneos;

Sources/MediaEditor.swift

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ open class MediaEditor: UINavigationController {
7373
///
7474
public init(_ image: UIImage) {
7575
self.images = [0: image]
76-
super.init(rootViewController: hub)
76+
super.init(nibName: nil, bundle: nil)
77+
viewControllers = [hub]
7778
setup()
7879
}
7980

@@ -84,7 +85,8 @@ open class MediaEditor: UINavigationController {
8485
///
8586
public init(_ images: [UIImage]) {
8687
self.images = images.enumerated().reduce(into: [:]) { $0[$1.offset] = $1.element }
87-
super.init(rootViewController: hub)
88+
super.init(nibName: nil, bundle: nil)
89+
viewControllers = [hub]
8890
setup()
8991
}
9092

@@ -96,7 +98,8 @@ open class MediaEditor: UINavigationController {
9698
///
9799
public init(_ asyncImage: AsyncImage) {
98100
self.asyncImages.append(asyncImage)
99-
super.init(rootViewController: hub)
101+
super.init(nibName: nil, bundle: nil)
102+
viewControllers = [hub]
100103
setup()
101104
}
102105

@@ -108,24 +111,17 @@ open class MediaEditor: UINavigationController {
108111
///
109112
public init(_ asyncImages: [AsyncImage]) {
110113
self.asyncImages = asyncImages
111-
super.init(rootViewController: hub)
114+
super.init(nibName: nil, bundle: nil)
115+
viewControllers = [hub]
112116
setup()
113117
}
114118

115119
required public init?(coder aDecoder: NSCoder) {
116120
super.init(coder: aDecoder)
117121
}
118122

119-
public override func viewDidLoad() {
120-
super.viewDidLoad()
121-
122-
isEditingPlainUIImages = images.count > 0
123-
124-
hub.delegate = self
125-
126-
modalTransitionStyle = .crossDissolve
127-
modalPresentationStyle = .fullScreen
128-
navigationBar.isHidden = true
123+
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
124+
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
129125
}
130126

131127
public override func viewWillDisappear(_ animated: Bool) {
@@ -140,12 +136,21 @@ open class MediaEditor: UINavigationController {
140136
}
141137

142138
private func setup() {
139+
setupModalStyle()
143140
setupHub()
144141
setupForAsync()
145142
presentIfSingleImageAndCapability()
146143
}
147144

145+
private func setupModalStyle() {
146+
modalTransitionStyle = .crossDissolve
147+
modalPresentationStyle = .fullScreen
148+
navigationBar.isHidden = true
149+
}
150+
148151
private func setupHub() {
152+
hub.delegate = self
153+
149154
hub.onCancel = { [weak self] in
150155
self?.cancel()
151156
}
@@ -166,6 +171,8 @@ open class MediaEditor: UINavigationController {
166171
}
167172

168173
private func setupForAsync() {
174+
isEditingPlainUIImages = images.count > 0
175+
169176
asyncImages.enumerated().forEach { offset, asyncImage in
170177
if let thumb = asyncImage.thumb {
171178
thumbnailAvailable(thumb, offset: offset)

Tests/MediaEditorTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ class MediaEditorTests: XCTestCase {
214214
let thumbImage = UIImage(color: .black)
215215
let mediaEditor = MediaEditor(asyncImage)
216216
UIApplication.shared.topWindow?.addSubview(mediaEditor.view)
217+
mediaEditor.view.layoutIfNeeded()
217218

218219
asyncImage.simulate(fullImageHasBeenDownloaded: fullImage)
219220
asyncImage.simulate(thumbHasBeenDownloaded: thumbImage)

0 commit comments

Comments
 (0)