Skip to content

Commit e978af7

Browse files
authored
Merge pull request #17 from RomanPodymov/refactoring
Refactoring
2 parents cbfdc7d + a257876 commit e978af7

File tree

3 files changed

+56
-29
lines changed

3 files changed

+56
-29
lines changed

Example/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- FTLinearActivityIndicator (1.4)
2+
- FTLinearActivityIndicator (1.5)
33

44
DEPENDENCIES:
55
- FTLinearActivityIndicator (from `../`)
@@ -9,8 +9,8 @@ EXTERNAL SOURCES:
99
:path: "../"
1010

1111
SPEC CHECKSUMS:
12-
FTLinearActivityIndicator: 572f5f623e357181d94731e63a406db683ec177b
12+
FTLinearActivityIndicator: 6f0ea30dcaf5e6a285d2b0a069abaa195aa376db
1313

1414
PODFILE CHECKSUM: d653595fcbe53f0d4160295f6c50f84621e4a209
1515

16-
COCOAPODS: 1.10.1
16+
COCOAPODS: 1.11.3

FTLinearActivityIndicator/Classes/UIApplication+LinearNetworkActivityIndicator.swift

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -69,31 +69,31 @@ extension UIApplication {
6969

7070
// notched iPhones differ in corner radius and right notch width
7171
// => lookup margin from right window edge, and width
72-
let layout: [String: (CGFloat, CGFloat)] = [
73-
"iPhone10,3": (74, 44), // iPhone X
74-
"iPhone10,6": (74, 44), // iPhone X
75-
"iPhone11,2": (74, 44), // Phone Xs
76-
"iPhone11,4": (74, 44), // iPhone Xs Max
77-
"iPhone11,6": (74, 44), // iPhone Xs Max
78-
"iPhone11,8": (70, 40), // iPhone XR
79-
"iPhone12,1": (70, 40), // iPhone 11
80-
"iPhone12,3": (60, 34), // iPhone 11 Pro
81-
"iPhone12,5": (74, 44), // iPhone 11 Pro Max
82-
"iPhone13,1": (60, 30), // iPhone 12 Mini
83-
"iPhone13,2": (72, 34), // iPhone 12
84-
"iPhone13,3": (72, 34), // iPhone 12 Pro
85-
"iPhone13,4": (80, 42), // iPhone 12 Pro Max
86-
"iPhone14,4": (60, 30), // iPhone 13 Mini
87-
"iPhone14,5": (72, 34), // iPhone 13
88-
"iPhone14,2": (72, 34), // iPhone 13 Pro
89-
"iPhone14,3": (80, 42), // iPhone 13 Pro Max
90-
"iPhone14,7": (72, 34), // iPhone 14
91-
"iPhone14,8": (80, 42), // iPhone 14 Plus
92-
"iPhone15,2": (72, 34), // iPhone 14 Pro
93-
"iPhone15,3": (80, 42), // iPhone 14 Pro Max
72+
let layout: [ModelName: (CGFloat, CGFloat)] = [
73+
.iPhoneX1: (74, 44),
74+
.iPhoneX2: (74, 44),
75+
.iPhoneXs: (74, 44),
76+
.iPhoneXsMax1: (74, 44),
77+
.iPhoneXsMax2: (74, 44),
78+
.iPhoneXR: (70, 40),
79+
.iPhone11: (70, 40),
80+
.iPhone11Pro: (60, 34),
81+
.iPhone11ProMax: (74, 44),
82+
.iPhone12Mini: (60, 30),
83+
.iPhone12: (72, 34),
84+
.iPhone12Pro: (72, 34),
85+
.iPhone12ProMax: (80, 42),
86+
.iPhone13Mini: (60, 30),
87+
.iPhone13: (72, 34),
88+
.iPhone13Pro: (72, 34),
89+
.iPhone13ProMax: (80, 42),
90+
.iPhone14: (72, 34),
91+
.iPhone14Plus: (80, 42),
92+
.iPhone14Pro: (72, 34),
93+
.iPhone14ProMax: (80, 42),
9494
]
9595
let modelName = UIDevice.current.ftModelName
96-
let config = layout[modelName] ?? (74, 44)
96+
let config = modelName.flatMap { layout[$0] } ?? (74, 44)
9797

9898
let x = indicatorWindow!.frame.width - config.0
9999
let width = config.1

FTLinearActivityIndicator/Classes/UIDevice+Extension.swift

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,33 @@
77

88
import UIKit
99

10+
public enum ModelName: String {
11+
case iPhoneX1 = "iPhone10,3"
12+
case iPhoneX2 = "iPhone10,6"
13+
case iPhoneXs = "iPhone11,2"
14+
case iPhoneXsMax1 = "iPhone11,4"
15+
case iPhoneXsMax2 = "iPhone11,6"
16+
case iPhoneXR = "iPhone11,8"
17+
case iPhone11 = "iPhone12,1"
18+
case iPhone11Pro = "iPhone12,3"
19+
case iPhone11ProMax = "iPhone12,5"
20+
case iPhone12Mini = "iPhone13,1"
21+
case iPhone12 = "iPhone13,2"
22+
case iPhone12Pro = "iPhone13,3"
23+
case iPhone12ProMax = "iPhone13,4"
24+
case iPhone13Mini = "iPhone14,4"
25+
case iPhone13 = "iPhone14,5"
26+
case iPhone13Pro = "iPhone14,2"
27+
case iPhone13ProMax = "iPhone14,3"
28+
case iPhone14 = "iPhone14,7"
29+
case iPhone14Plus = "iPhone14,8"
30+
case iPhone14Pro = "iPhone15,2"
31+
case iPhone14ProMax = "iPhone15,3"
32+
}
33+
1034
public extension UIDevice {
11-
var ftModelName: String {
35+
var ftModelName: ModelName? {
36+
let result: String
1237
var systemInfo = utsname()
1338
uname(&systemInfo)
1439
let machineMirror = Mirror(reflecting: systemInfo.machine)
@@ -18,8 +43,10 @@ public extension UIDevice {
1843
}
1944
// When running in simulator, identifier will be one of "i386", "x86_64", "arm64" instead of what we want.
2045
switch identifier {
21-
case "i386", "x86_64", "arm64": return ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? identifier
22-
default: return identifier
46+
case "i386", "x86_64", "arm64": result = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? identifier
47+
default: result = identifier
2348
}
49+
50+
return .init(rawValue: result)
2451
}
2552
}

0 commit comments

Comments
 (0)