From ab98bc2da651990e13359b7104e66acefdbf3dd0 Mon Sep 17 00:00:00 2001 From: Yan Cheng Cheok Date: Wed, 30 Jun 2021 01:45:33 +0800 Subject: [PATCH 1/3] Allow user to turn off blur effect by using nil. Allow user to turn off blur effect by using nil. --- Example/DemoViewController.swift | 9 +++++++++ SDCAlertView UI Tests/SDCAlertView_UI_Tests.swift | 4 ++-- Source/AlertVisualStyle.swift | 14 +++++++++----- Source/Views/ActionSheetCancelActionView.swift | 2 +- Source/Views/ActionSheetPrimaryView.swift | 8 +++++--- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Example/DemoViewController.swift b/Example/DemoViewController.swift index 27c4de0b..0748f74e 100644 --- a/Example/DemoViewController.swift +++ b/Example/DemoViewController.swift @@ -26,6 +26,15 @@ final class DemoViewController: UITableViewController { let style = AlertControllerStyle(rawValue: self.styleControl.selectedSegmentIndex)! let alert = AlertController(title: title, message: message, preferredStyle: style) + let visualStyle = AlertVisualStyle(alertStyle: style) + visualStyle.blurEffect = nil + if #available(iOS 13.0, *) { + visualStyle.backgroundColor = UIColor.red + } else { + // Fallback on earlier versions + } + alert.visualStyle = visualStyle + let textFields = Int(self.textFieldCountTextField.content ?? "0")! for _ in 0.. XCUIElement { - return XCUIApplication().collectionViews.children(matching: .cell).element(boundBy: index) + return XCUIApplication().collectionViews.children(matching: .cell).element(boundBy: Int(index)) } private func buttonWithIdentifier(_ identifier: String) -> XCUIElement { @@ -37,7 +37,7 @@ class SDCAlertView_UI_Tests: XCTestCase { @discardableResult private func showAlertAtIndex(_ index: UInt) -> XCUIApplication { let app = XCUIApplication() - app.tables.children(matching: .cell).element(boundBy: index).tap() + app.tables.children(matching: .cell).element(boundBy: Int(index)).tap() return app } diff --git a/Source/AlertVisualStyle.swift b/Source/AlertVisualStyle.swift index 0e8e401f..3967a2b9 100644 --- a/Source/AlertVisualStyle.swift +++ b/Source/AlertVisualStyle.swift @@ -134,7 +134,14 @@ open class AlertVisualStyle: NSObject { } }() - var blurEffect: UIBlurEffect { + /// The standard blur effect + @objc + public var blurEffect: UIBlurEffect? = AlertVisualStyle.standardBlurEffect() + + /// The style of the alert. + private let alertStyle: AlertControllerStyle + + private static func standardBlurEffect() -> UIBlurEffect { if #available(iOS 13, *) { return UIBlurEffect(style: .systemMaterial) } else if #available(iOS 10, *) { @@ -143,10 +150,7 @@ open class AlertVisualStyle: NSObject { return UIBlurEffect(style: .extraLight) } } - - /// The style of the alert. - private let alertStyle: AlertControllerStyle - + @objc public init(alertStyle: AlertControllerStyle) { self.alertStyle = alertStyle diff --git a/Source/Views/ActionSheetCancelActionView.swift b/Source/Views/ActionSheetCancelActionView.swift index b21b5897..04fed9b7 100644 --- a/Source/Views/ActionSheetCancelActionView.swift +++ b/Source/Views/ActionSheetCancelActionView.swift @@ -45,7 +45,7 @@ final class ActionSheetCancelActionView: UIView { } } - private func addBlurBackground(effect: UIBlurEffect) { + private func addBlurBackground(effect: UIBlurEffect?) { self.blurBackground.effect = effect self.blurBackground.translatesAutoresizingMaskIntoConstraints = false self.addSubview(self.blurBackground) diff --git a/Source/Views/ActionSheetPrimaryView.swift b/Source/Views/ActionSheetPrimaryView.swift index 34ec1457..f7b98eca 100644 --- a/Source/Views/ActionSheetPrimaryView.swift +++ b/Source/Views/ActionSheetPrimaryView.swift @@ -63,7 +63,7 @@ final class ActionSheetPrimaryView: UIView { self.layer.masksToBounds = true } - private func buildBackgroundBlur(effect: UIVisualEffect) -> UIVisualEffectView { + private func buildBackgroundBlur(effect: UIVisualEffect?) -> UIVisualEffectView { let backgroundBlur = UIVisualEffectView(effect: effect) backgroundBlur.translatesAutoresizingMaskIntoConstraints = false self.addSubview(backgroundBlur) @@ -71,11 +71,13 @@ final class ActionSheetPrimaryView: UIView { return backgroundBlur } - private func buildLabelVibrancy(effect: UIBlurEffect) -> UIVisualEffectView { + private func buildLabelVibrancy(effect: UIBlurEffect?) -> UIVisualEffectView { let vibrancy = UIVisualEffectView(effect: effect) vibrancy.translatesAutoresizingMaskIntoConstraints = false if #available(iOS 13, *) { - vibrancy.effect = UIVibrancyEffect(blurEffect: effect, style: .secondaryLabel) + if let effect = effect { + vibrancy.effect = UIVibrancyEffect(blurEffect: effect, style: .secondaryLabel) + } } return vibrancy From 9a128013f1953424974fba5341ec1c396fbbffd1 Mon Sep 17 00:00:00 2001 From: Yan Cheng Cheok Date: Wed, 30 Jun 2021 01:55:29 +0800 Subject: [PATCH 2/3] Revert to master copy Revert to master copy. --- Example/DemoViewController.swift | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Example/DemoViewController.swift b/Example/DemoViewController.swift index 0748f74e..27c4de0b 100644 --- a/Example/DemoViewController.swift +++ b/Example/DemoViewController.swift @@ -26,15 +26,6 @@ final class DemoViewController: UITableViewController { let style = AlertControllerStyle(rawValue: self.styleControl.selectedSegmentIndex)! let alert = AlertController(title: title, message: message, preferredStyle: style) - let visualStyle = AlertVisualStyle(alertStyle: style) - visualStyle.blurEffect = nil - if #available(iOS 13.0, *) { - visualStyle.backgroundColor = UIColor.red - } else { - // Fallback on earlier versions - } - alert.visualStyle = visualStyle - let textFields = Int(self.textFieldCountTextField.content ?? "0")! for _ in 0.. Date: Wed, 30 Jun 2021 01:56:25 +0800 Subject: [PATCH 3/3] Revert to master copy Revert to master copy. --- SDCAlertView UI Tests/SDCAlertView_UI_Tests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SDCAlertView UI Tests/SDCAlertView_UI_Tests.swift b/SDCAlertView UI Tests/SDCAlertView_UI_Tests.swift index ae23d473..f4961892 100644 --- a/SDCAlertView UI Tests/SDCAlertView_UI_Tests.swift +++ b/SDCAlertView UI Tests/SDCAlertView_UI_Tests.swift @@ -23,7 +23,7 @@ class SDCAlertView_UI_Tests: XCTestCase { } private func buttonAtIndex(_ index: UInt) -> XCUIElement { - return XCUIApplication().collectionViews.children(matching: .cell).element(boundBy: Int(index)) + return XCUIApplication().collectionViews.children(matching: .cell).element(boundBy: index) } private func buttonWithIdentifier(_ identifier: String) -> XCUIElement { @@ -37,7 +37,7 @@ class SDCAlertView_UI_Tests: XCTestCase { @discardableResult private func showAlertAtIndex(_ index: UInt) -> XCUIApplication { let app = XCUIApplication() - app.tables.children(matching: .cell).element(boundBy: Int(index)).tap() + app.tables.children(matching: .cell).element(boundBy: index).tap() return app }