From e82081460ae90112cf49f45a5577f1e2f7037240 Mon Sep 17 00:00:00 2001 From: Felix Mau Date: Wed, 7 Sep 2022 22:44:18 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20::=20Fixed=20incorrect=20lay?= =?UTF-8?q?out=20of=20`NotchGradientLoadingBar`=20when=20using=20"iPhone?= =?UTF-8?q?=2012=20Mini"=20or=20"iPhone=2013=20Mini"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...hGradientLoadingBarViewModelTestCase.swift | 96 +++++-------------- .../NotchGradientLoadingBarController.swift | 29 ++++-- .../NotchGradientLoadingBarViewModel.swift | 40 +++++++- 3 files changed, 80 insertions(+), 85 deletions(-) diff --git a/Example/ExampleTests/NotchGradientLoadingBar/NotchGradientLoadingBarViewModelTestCase.swift b/Example/ExampleTests/NotchGradientLoadingBar/NotchGradientLoadingBarViewModelTestCase.swift index 171bf28..be0ce5e 100644 --- a/Example/ExampleTests/NotchGradientLoadingBar/NotchGradientLoadingBarViewModelTestCase.swift +++ b/Example/ExampleTests/NotchGradientLoadingBar/NotchGradientLoadingBarViewModelTestCase.swift @@ -12,86 +12,34 @@ import XCTest final class NotchGradientLoadingBarViewModelTestCase: XCTestCase { - func test_initializer_shouldSetSafeAreaDevice_toIPhoneX() { + func test_initializer_shouldSetCorrectSafeAreaDevice() { // Given - let deviceIdentifiers = ["iPhone10,3", "iPhone10,6", "iPhone11,2", "iPhone11,4", "iPhone11,6"] - deviceIdentifiers.forEach { deviceIdentifier in + let identifiersToSafeAreaDeviceMap: [String: NotchGradientLoadingBarViewModel.SafeAreaDevice] = [ + "iPhone10,3": .iPhoneX, + "iPhone10,6": .iPhoneX, + "iPhone11,2": .iPhoneXS, + "iPhone11,4": .iPhoneXSMax, + "iPhone11,6": .iPhoneXSMax, + "iPhone11,8": .iPhoneXR, + "iPhone12,1": .iPhone11, + "iPhone12,3": .iPhone11Pro, + "iPhone12,5": .iPhone11ProMax, + "iPhone13,1": .iPhone12Mini, + "iPhone13,2": .iPhone12, + "iPhone13,3": .iPhone12Pro, + "iPhone13,4": .iPhone12ProMax, + "iPhone14,4": .iPhone13Mini, + "iPhone14,5": .iPhone13, + "iPhone14,2": .iPhone13Pro, + "iPhone14,3": .iPhone13ProMax, + ] + identifiersToSafeAreaDeviceMap.forEach { deviceIdentifier, safeAreaDevice in // When let viewModel = NotchGradientLoadingBarViewModel(deviceIdentifier: deviceIdentifier) // Then - XCTAssertEqual(viewModel.safeAreaDevice, .iPhoneX) - } - } - - func test_initializer_shouldSetSafeAreaDevice_toIPhoneXR() { - // Given - let deviceIdentifier = "iPhone11,8" - - // When - let viewModel = NotchGradientLoadingBarViewModel(deviceIdentifier: deviceIdentifier) - - // Then - XCTAssertEqual(viewModel.safeAreaDevice, .iPhoneXR) - } - - func test_initializer_shouldSetSafeAreaDevice_toIPhone11() { - // Given - let deviceIdentifier = "iPhone12,1" - - // When - let viewModel = NotchGradientLoadingBarViewModel(deviceIdentifier: deviceIdentifier) - - // Then - XCTAssertEqual(viewModel.safeAreaDevice, .iPhone11) - } - - func test_initializer_shouldSetSafeAreaDevice_toIPhone11Pro() { - // Given - let deviceIdentifier = "iPhone12,3" - - // When - let viewModel = NotchGradientLoadingBarViewModel(deviceIdentifier: deviceIdentifier) - - // Then - XCTAssertEqual(viewModel.safeAreaDevice, .iPhone11Pro) - } - - func test_initializer_shouldSetSafeAreaDevice_toIPhone11ProMax() { - // Given - let deviceIdentifier = "iPhone12,5" - - // When - let viewModel = NotchGradientLoadingBarViewModel(deviceIdentifier: deviceIdentifier) - - // Then - XCTAssertEqual(viewModel.safeAreaDevice, .iPhone11ProMax) - } - - func test_initializer_shouldSetSafeAreaDevice_toIPhone12() { - // Given - let deviceIdentifiers = ["iPhone13,1", "iPhone13,2", "iPhone13,3", "iPhone13,4"] - deviceIdentifiers.forEach { deviceIdentifier in - - // When - let viewModel = NotchGradientLoadingBarViewModel(deviceIdentifier: deviceIdentifier) - - // Then - XCTAssertEqual(viewModel.safeAreaDevice, .iPhone12) - } - } - - func test_initializer_shouldSetSafeAreaDevice_toIPhone13() { - // Given - let deviceIdentifiers = ["iPhone14,4", "iPhone14,5", "iPhone14,2", "iPhone14,3"] - deviceIdentifiers.forEach { deviceIdentifier in - - // When - let viewModel = NotchGradientLoadingBarViewModel(deviceIdentifier: deviceIdentifier) - - // Then - XCTAssertEqual(viewModel.safeAreaDevice, .iPhone13) + XCTAssertEqual(viewModel.safeAreaDevice, safeAreaDevice) } } diff --git a/GradientLoadingBar/Feature/NotchGradientLoadingBar/NotchGradientLoadingBarController.swift b/GradientLoadingBar/Feature/NotchGradientLoadingBar/NotchGradientLoadingBarController.swift index 70f8f1c..fa9cc7f 100644 --- a/GradientLoadingBar/Feature/NotchGradientLoadingBar/NotchGradientLoadingBarController.swift +++ b/GradientLoadingBar/Feature/NotchGradientLoadingBar/NotchGradientLoadingBarController.swift @@ -212,33 +212,48 @@ private extension NotchConfig { case .unknown: return nil - case .iPhoneX: - /// The default configuration for the iPhone X and 11. + case .iPhoneX, .iPhoneXS, .iPhoneXSMax: + /// The default configuration for the iPhone X. /// Values are based on . - self.init(notchWidth: 208, + self.init(notchWidth: 209, largeCircleRadius: 22.5, largeCircleVerticalOffset: -4.75, - transform: CGAffineTransform(translationX: 0.33, y: 0)) + transform: safeAreaDevice == .iPhoneXSMax ? .identity : CGAffineTransform(translationX: 0.33, y: 0)) case .iPhoneXR, .iPhone11: - self.init(notchWidth: 230.5, + self.init(notchWidth: 230, largeCircleRadius: 24, largeCircleVerticalOffset: -3.5, transform: .identity) + // The "iPhone 11 Pro" and "iPhone 11 Pro Max" have a smaller notch than the "iPhone 11". case .iPhone11Pro, .iPhone11ProMax: self.init(notchWidth: 209, largeCircleRadius: 21, largeCircleVerticalOffset: -3.5, + transform: safeAreaDevice == .iPhone11ProMax ? .identity : CGAffineTransform(translationX: 0.33, y: 0)) + + // The "iPhone 12 Mini" has a larger notch than the "iPhone 12". + case .iPhone12Mini: + self.init(notchWidth: 226, + largeCircleRadius: 24, + largeCircleVerticalOffset: -2, transform: .identity) - case .iPhone12: + case .iPhone12, .iPhone12Pro, .iPhone12ProMax: self.init(notchWidth: 209.5, largeCircleRadius: 21, largeCircleVerticalOffset: -1.75, transform: .identity) - case .iPhone13: + // The "iPhone 13 Mini" has a larger notch than the "iPhone 13". + case .iPhone13Mini: + self.init(notchWidth: 174.75, + largeCircleRadius: 24.5, + largeCircleVerticalOffset: 0.5, + transform: .identity) + + case .iPhone13, .iPhone13Pro, .iPhone13ProMax: // The iPhone 13 specific configuration: ‟iPhone 13 notch is 20% smaller in width, but it is also a little taller in height‟. // Source: . self.init(notchWidth: 161, diff --git a/GradientLoadingBar/Feature/NotchGradientLoadingBar/NotchGradientLoadingBarViewModel.swift b/GradientLoadingBar/Feature/NotchGradientLoadingBar/NotchGradientLoadingBarViewModel.swift index c1bd3cd..269ee68 100644 --- a/GradientLoadingBar/Feature/NotchGradientLoadingBar/NotchGradientLoadingBarViewModel.swift +++ b/GradientLoadingBar/Feature/NotchGradientLoadingBar/NotchGradientLoadingBarViewModel.swift @@ -15,13 +15,20 @@ final class NotchGradientLoadingBarViewModel { enum SafeAreaDevice { case unknown case iPhoneX + case iPhoneXS + case iPhoneXSMax case iPhoneXR case iPhone11 - // The "iPhone 11 Pro" and "iPhone 11 Pro Max" have a smaller notch than the "iPhone 11". case iPhone11Pro case iPhone11ProMax + case iPhone12Mini case iPhone12 + case iPhone12Pro + case iPhone12ProMax + case iPhone13Mini case iPhone13 + case iPhone13Pro + case iPhone13ProMax } // MARK: - Public properties @@ -44,10 +51,17 @@ private extension NotchGradientLoadingBarViewModel.SafeAreaDevice { /// /// - Note: This is taken from init(deviceIdentifier: String) { + // swiftlint:disable:previous cyclomatic_complexity switch deviceIdentifier { - case "iPhone10,3", "iPhone10,6", "iPhone11,2", "iPhone11,4", "iPhone11,6": + case "iPhone10,3", "iPhone10,6": self = .iPhoneX + case "iPhone11,2": + self = .iPhoneXS + + case "iPhone11,4", "iPhone11,6": + self = .iPhoneXSMax + case "iPhone11,8": self = .iPhoneXR @@ -60,12 +74,30 @@ private extension NotchGradientLoadingBarViewModel.SafeAreaDevice { case "iPhone12,5": self = .iPhone11ProMax - case "iPhone13,1", "iPhone13,2", "iPhone13,3", "iPhone13,4": + case "iPhone13,1": + self = .iPhone12Mini + + case "iPhone13,2": self = .iPhone12 - case "iPhone14,4", "iPhone14,5", "iPhone14,2", "iPhone14,3": + case "iPhone13,3": + self = .iPhone12Pro + + case "iPhone13,4": + self = .iPhone12ProMax + + case "iPhone14,4": + self = .iPhone13Mini + + case "iPhone14,5": self = .iPhone13 + case "iPhone14,2": + self = .iPhone13Pro + + case "iPhone14,3": + self = .iPhone13ProMax + default: self = .unknown } From fcb33e68f75e9945b1588f946605cdbeaaa444ef Mon Sep 17 00:00:00 2001 From: Felix Mau Date: Thu, 8 Sep 2022 12:23:55 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=96=20::=20Bump=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 13 ++++++++++--- Example/Podfile.lock | 4 ++-- .../Local Podspecs/GradientLoadingBar.podspec.json | 4 ++-- Example/Pods/Manifest.lock | 4 ++-- .../GradientLoadingBar-Info.plist | 2 +- GradientLoadingBar.podspec | 2 +- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2a1837..4cefdbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ## [Unreleased] +## [2.3.2] - 2022-08-09 +### Changed + - Improved Bézier Path of `NotchGradientLoadingBar` + - Adapt logic of `UIKit` variant for calculating and animating the gradient to `SwiftUI` variant. This should not make any difference visually, but will be easier to maintain. +### Fixed + - Fixed incorrect layout on `NotchGradientLoadingBar` when using "iPhone 12 Mini" or "iPhone 13 Mini" ## [2.3.1] - 2022-10-05 ### Fixed - - Fixed incorrect layout on `NotchGradientLoadingBar` when using "iPhone 11 Pro" and "iPhone 11 Pro Max" ([#029]) + - Fixed incorrect layout on `NotchGradientLoadingBar` when using "iPhone 11 Pro" or "iPhone 11 Pro Max" ([#029]) [#029]: https://github.com/fxm90/GradientLoadingBar/issues/29 @@ -178,8 +184,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a - Initial release -[Unreleased]: https://github.com/fxm90/GradientLoadingBar/compare/2.3.1...main -[2.3.0]: https://github.com/fxm90/GradientLoadingBar/compare/2.3.0...2.3.1 +[Unreleased]: https://github.com/fxm90/GradientLoadingBar/compare/2.3.2...main +[2.3.2]: https://github.com/fxm90/GradientLoadingBar/compare/2.3.1...2.3.2 +[2.3.1]: https://github.com/fxm90/GradientLoadingBar/compare/2.3.0...2.3.1 [2.3.0]: https://github.com/fxm90/GradientLoadingBar/compare/2.2.5...2.3.0 [2.2.5]: https://github.com/fxm90/GradientLoadingBar/compare/2.2.4...2.2.5 [2.2.4]: https://github.com/fxm90/GradientLoadingBar/compare/2.2.3...2.2.4 diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 4e70000..5efd847 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - GradientLoadingBar (2.3.1): + - GradientLoadingBar (2.3.2): - LightweightObservable (~> 2.1) - LightweightObservable (2.2.1) - SnapshotTesting (1.9.0) @@ -33,7 +33,7 @@ CHECKOUT OPTIONS: :git: https://github.com/fxm90/SwiftConfigurationFiles.git SPEC CHECKSUMS: - GradientLoadingBar: 86d26001466ce8ad44262d9b83fb9cdf6d60623c + GradientLoadingBar: 0fb63c35e73bb8c56689e9ffd7a46e754fea8a15 LightweightObservable: 64d0f623a4eec857e2680476380a08f3117a1a92 SnapshotTesting: 6141c48b6aa76ead61431ca665c14ab9a066c53b SwiftConfigurationFiles: 1cf2228a911ebed9f42f8dec077bb634f04ca6c8 diff --git a/Example/Pods/Local Podspecs/GradientLoadingBar.podspec.json b/Example/Pods/Local Podspecs/GradientLoadingBar.podspec.json index 9b7398b..744a6ff 100644 --- a/Example/Pods/Local Podspecs/GradientLoadingBar.podspec.json +++ b/Example/Pods/Local Podspecs/GradientLoadingBar.podspec.json @@ -1,6 +1,6 @@ { "name": "GradientLoadingBar", - "version": "2.3.1", + "version": "2.3.2", "summary": "A customizable animated gradient loading bar.", "description": "A customizable animated gradient loading bar.\nInspired by https://codepen.io/marcobiedermann/pen/LExXWW", "homepage": "https://github.com/fxm90/GradientLoadingBar", @@ -14,7 +14,7 @@ }, "source": { "git": "https://github.com/fxm90/GradientLoadingBar.git", - "tag": "2.3.1" + "tag": "2.3.2" }, "swift_versions": "5.5", "platforms": { diff --git a/Example/Pods/Manifest.lock b/Example/Pods/Manifest.lock index 4e70000..5efd847 100644 --- a/Example/Pods/Manifest.lock +++ b/Example/Pods/Manifest.lock @@ -1,5 +1,5 @@ PODS: - - GradientLoadingBar (2.3.1): + - GradientLoadingBar (2.3.2): - LightweightObservable (~> 2.1) - LightweightObservable (2.2.1) - SnapshotTesting (1.9.0) @@ -33,7 +33,7 @@ CHECKOUT OPTIONS: :git: https://github.com/fxm90/SwiftConfigurationFiles.git SPEC CHECKSUMS: - GradientLoadingBar: 86d26001466ce8ad44262d9b83fb9cdf6d60623c + GradientLoadingBar: 0fb63c35e73bb8c56689e9ffd7a46e754fea8a15 LightweightObservable: 64d0f623a4eec857e2680476380a08f3117a1a92 SnapshotTesting: 6141c48b6aa76ead61431ca665c14ab9a066c53b SwiftConfigurationFiles: 1cf2228a911ebed9f42f8dec077bb634f04ca6c8 diff --git a/Example/Pods/Target Support Files/GradientLoadingBar/GradientLoadingBar-Info.plist b/Example/Pods/Target Support Files/GradientLoadingBar/GradientLoadingBar-Info.plist index a7b58ed..ecb8f03 100644 --- a/Example/Pods/Target Support Files/GradientLoadingBar/GradientLoadingBar-Info.plist +++ b/Example/Pods/Target Support Files/GradientLoadingBar/GradientLoadingBar-Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 2.3.1 + 2.3.2 CFBundleSignature ???? CFBundleVersion diff --git a/GradientLoadingBar.podspec b/GradientLoadingBar.podspec index d5589ae..faa0f27 100644 --- a/GradientLoadingBar.podspec +++ b/GradientLoadingBar.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'GradientLoadingBar' - s.version = '2.3.1' + s.version = '2.3.2' s.summary = 'A customizable animated gradient loading bar.' # This description is used to generate tags and improve search results.