From e7efc9f1bf789461694049cf9281e1d9663983ec Mon Sep 17 00:00:00 2001 From: Vincent Neo <23420208+vincentneo@users.noreply.github.com> Date: Thu, 14 Sep 2023 11:46:21 +0800 Subject: [PATCH] Seperate dynamic island check, from hasNotch --- Sources/DeviceModel.swift | 14 +++++++++++++- Tests/DeviceModelTests.swift | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Sources/DeviceModel.swift b/Sources/DeviceModel.swift index 7951a47..c9b5682 100644 --- a/Sources/DeviceModel.swift +++ b/Sources/DeviceModel.swift @@ -246,7 +246,19 @@ extension DeviceModel { return true case .iPhone13mini, .iPhone13, .iPhone13Pro, .iPhone13ProMax: return true - case .iPhone14, .iPhone14Plus, .iPhone14Pro, .iPhone14ProMax: + case .iPhone14, .iPhone14Plus: + return true + + default: + return false + } + } + + public var hasDynamicIsland: Bool { + switch self { + case .iPhone14Pro, .iPhone14ProMax: + return true + case .iPhone15, .iPhone15Plus, .iPhone15Pro, .iPhone15ProMax: return true default: diff --git a/Tests/DeviceModelTests.swift b/Tests/DeviceModelTests.swift index dc0eb21..8c8d7d8 100644 --- a/Tests/DeviceModelTests.swift +++ b/Tests/DeviceModelTests.swift @@ -492,11 +492,23 @@ class DeviceModelTests: XCTestCase { .iPhone11, .iPhone11Pro, .iPhone11ProMax, .iPhone12, .iPhone12Pro, .iPhone12ProMax, .iPhone12mini, .iPhone13, .iPhone13mini, .iPhone13Pro, .iPhone13ProMax, - .iPhone14, .iPhone14Plus, .iPhone14Pro, .iPhone14ProMax] + .iPhone14, .iPhone14Plus] let noNotchModels: [DeviceModel] = DeviceModel.allCases.filter( { !notchModels.contains($0) }) notchModels.forEach { XCTAssertTrue($0.hasNotch) } noNotchModels.forEach { XCTAssertFalse($0.hasNotch) } } + + // MARK: Dynamic Island Test + + func testHasDynamicIsland() { + let withModels: [DeviceModel] = [.iPhone14Pro, .iPhone14ProMax, + .iPhone15, .iPhone15Plus, .iPhone15Pro, .iPhone15ProMax] + + let withoutModels: [DeviceModel] = DeviceModel.allCases.filter( { !withModels.contains($0) }) + + withModels.forEach { XCTAssertTrue($0.hasDynamicIsland) } + withoutModels.forEach { XCTAssertFalse($0.hasDynamicIsland) } + } }