Skip to content

Commit f1ce067

Browse files
committed
Implements SafariViewController
1 parent e320a19 commit f1ce067

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

WooCommerce/Classes/Authentication/Prologue/LoginPrologueViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ extension LoginPrologueViewController {
110110
/// Opens SafariViewController at the specified URL.
111111
///
112112
func displaySafariViewController(at url: URL) {
113-
let safariViewController = SFSafariViewController(url: url)
113+
let safariViewController = SafariViewController(url: url)
114114
safariViewController.modalPresentationStyle = .pageSheet
115115
present(safariViewController, animated: true, completion: nil)
116116
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import Foundation
2+
import SafariServices
3+
4+
5+
/// WooCommerce SafariViewController: Allows us to control the StatusBar Style
6+
///
7+
class SafariViewController: SFSafariViewController {
8+
9+
/// Preserves the StatusBar Style present, prior to when this ViewController gets displayed.
10+
///
11+
private var previousStatusBarStyle: UIStatusBarStyle?
12+
13+
/// StatusBarStyle to be applied
14+
///
15+
var statusBarStyle: UIStatusBarStyle = .default
16+
17+
18+
// MARK: - Overridden Methods
19+
20+
override open func viewWillAppear(_ animated: Bool) {
21+
super.viewWillAppear(animated)
22+
23+
previousStatusBarStyle = UIApplication.shared.statusBarStyle
24+
UIApplication.shared.statusBarStyle = statusBarStyle
25+
}
26+
27+
override open func viewWillDisappear(_ animated: Bool) {
28+
super.viewWillDisappear(animated)
29+
30+
UIApplication.shared.statusBarStyle = previousStatusBarStyle ?? .lightContent
31+
}
32+
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
B5A8F8A920B84D3F00D211DE /* ApiCredentials.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A8F8A720B84D3F00D211DE /* ApiCredentials.swift */; };
4545
B5A8F8AD20B88D9900D211DE /* LoginPrologueViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A8F8AC20B88D9900D211DE /* LoginPrologueViewController.swift */; };
4646
B5A8F8AF20B88DCC00D211DE /* LoginPrologueViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5A8F8AE20B88DCC00D211DE /* LoginPrologueViewController.xib */; };
47+
B5BE368E20BED80B00BE0A8C /* SafariViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5BE368D20BED80B00BE0A8C /* SafariViewController.swift */; };
4748
B5D1AFB420BC445A00DB0E8C /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B5D1AFB320BC445900DB0E8C /* Images.xcassets */; };
4849
B5D1AFB820BC510200DB0E8C /* UIImage+Woo.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5D1AFB720BC510200DB0E8C /* UIImage+Woo.swift */; };
4950
B5D1AFBA20BC515600DB0E8C /* UIColor+Woo.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5D1AFB920BC515600DB0E8C /* UIColor+Woo.swift */; };
@@ -151,6 +152,7 @@
151152
B5A8F8A820B84D3F00D211DE /* InfoPlist.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = InfoPlist.h; path = DerivedSources/InfoPlist.h; sourceTree = SOURCE_ROOT; };
152153
B5A8F8AC20B88D9900D211DE /* LoginPrologueViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginPrologueViewController.swift; sourceTree = "<group>"; };
153154
B5A8F8AE20B88DCC00D211DE /* LoginPrologueViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LoginPrologueViewController.xib; sourceTree = "<group>"; };
155+
B5BE368D20BED80B00BE0A8C /* SafariViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafariViewController.swift; sourceTree = "<group>"; };
154156
B5D1AFB320BC445900DB0E8C /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
155157
B5D1AFB720BC510200DB0E8C /* UIImage+Woo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+Woo.swift"; sourceTree = "<group>"; };
156158
B5D1AFB920BC515600DB0E8C /* UIColor+Woo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Woo.swift"; sourceTree = "<group>"; };
@@ -266,6 +268,7 @@
266268
isa = PBXGroup;
267269
children = (
268270
B55D4C2620B717C000D7A50F /* UserAgent.swift */,
271+
B5BE368D20BED80B00BE0A8C /* SafariViewController.swift */,
269272
);
270273
path = Tools;
271274
sourceTree = "<group>";
@@ -717,6 +720,7 @@
717720
CE1CCB402056F21C000EE3AC /* Style.swift in Sources */,
718721
B50911322049E27A007D25DC /* SettingsViewController.swift in Sources */,
719722
B55D4C0620B6027200D7A50F /* AuthenticationManager.swift in Sources */,
723+
B5BE368E20BED80B00BE0A8C /* SafariViewController.swift in Sources */,
720724
CE855364209BA6A700938BDC /* ShowHideSectionFooter.swift in Sources */,
721725
B56DB3CA2049BFAA00D4AA8E /* AppDelegate.swift in Sources */,
722726
CE1F512B206985DF00C6C810 /* PaddedLabel.swift in Sources */,

0 commit comments

Comments
 (0)