Skip to content

Commit

Permalink
Merge pull request #17 from RomanPodymov/refactoring
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
futuretap authored Feb 13, 2023
2 parents cbfdc7d + a257876 commit e978af7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 29 deletions.
6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- FTLinearActivityIndicator (1.4)
- FTLinearActivityIndicator (1.5)

DEPENDENCIES:
- FTLinearActivityIndicator (from `../`)
Expand All @@ -9,8 +9,8 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
FTLinearActivityIndicator: 572f5f623e357181d94731e63a406db683ec177b
FTLinearActivityIndicator: 6f0ea30dcaf5e6a285d2b0a069abaa195aa376db

PODFILE CHECKSUM: d653595fcbe53f0d4160295f6c50f84621e4a209

COCOAPODS: 1.10.1
COCOAPODS: 1.11.3
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,31 @@ extension UIApplication {

// notched iPhones differ in corner radius and right notch width
// => lookup margin from right window edge, and width
let layout: [String: (CGFloat, CGFloat)] = [
"iPhone10,3": (74, 44), // iPhone X
"iPhone10,6": (74, 44), // iPhone X
"iPhone11,2": (74, 44), // Phone Xs
"iPhone11,4": (74, 44), // iPhone Xs Max
"iPhone11,6": (74, 44), // iPhone Xs Max
"iPhone11,8": (70, 40), // iPhone XR
"iPhone12,1": (70, 40), // iPhone 11
"iPhone12,3": (60, 34), // iPhone 11 Pro
"iPhone12,5": (74, 44), // iPhone 11 Pro Max
"iPhone13,1": (60, 30), // iPhone 12 Mini
"iPhone13,2": (72, 34), // iPhone 12
"iPhone13,3": (72, 34), // iPhone 12 Pro
"iPhone13,4": (80, 42), // iPhone 12 Pro Max
"iPhone14,4": (60, 30), // iPhone 13 Mini
"iPhone14,5": (72, 34), // iPhone 13
"iPhone14,2": (72, 34), // iPhone 13 Pro
"iPhone14,3": (80, 42), // iPhone 13 Pro Max
"iPhone14,7": (72, 34), // iPhone 14
"iPhone14,8": (80, 42), // iPhone 14 Plus
"iPhone15,2": (72, 34), // iPhone 14 Pro
"iPhone15,3": (80, 42), // iPhone 14 Pro Max
let layout: [ModelName: (CGFloat, CGFloat)] = [
.iPhoneX1: (74, 44),
.iPhoneX2: (74, 44),
.iPhoneXs: (74, 44),
.iPhoneXsMax1: (74, 44),
.iPhoneXsMax2: (74, 44),
.iPhoneXR: (70, 40),
.iPhone11: (70, 40),
.iPhone11Pro: (60, 34),
.iPhone11ProMax: (74, 44),
.iPhone12Mini: (60, 30),
.iPhone12: (72, 34),
.iPhone12Pro: (72, 34),
.iPhone12ProMax: (80, 42),
.iPhone13Mini: (60, 30),
.iPhone13: (72, 34),
.iPhone13Pro: (72, 34),
.iPhone13ProMax: (80, 42),
.iPhone14: (72, 34),
.iPhone14Plus: (80, 42),
.iPhone14Pro: (72, 34),
.iPhone14ProMax: (80, 42),
]
let modelName = UIDevice.current.ftModelName
let config = layout[modelName] ?? (74, 44)
let config = modelName.flatMap { layout[$0] } ?? (74, 44)

let x = indicatorWindow!.frame.width - config.0
let width = config.1
Expand Down
33 changes: 30 additions & 3 deletions FTLinearActivityIndicator/Classes/UIDevice+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,33 @@

import UIKit

public enum ModelName: String {
case iPhoneX1 = "iPhone10,3"
case iPhoneX2 = "iPhone10,6"
case iPhoneXs = "iPhone11,2"
case iPhoneXsMax1 = "iPhone11,4"
case iPhoneXsMax2 = "iPhone11,6"
case iPhoneXR = "iPhone11,8"
case iPhone11 = "iPhone12,1"
case iPhone11Pro = "iPhone12,3"
case iPhone11ProMax = "iPhone12,5"
case iPhone12Mini = "iPhone13,1"
case iPhone12 = "iPhone13,2"
case iPhone12Pro = "iPhone13,3"
case iPhone12ProMax = "iPhone13,4"
case iPhone13Mini = "iPhone14,4"
case iPhone13 = "iPhone14,5"
case iPhone13Pro = "iPhone14,2"
case iPhone13ProMax = "iPhone14,3"
case iPhone14 = "iPhone14,7"
case iPhone14Plus = "iPhone14,8"
case iPhone14Pro = "iPhone15,2"
case iPhone14ProMax = "iPhone15,3"
}

public extension UIDevice {
var ftModelName: String {
var ftModelName: ModelName? {
let result: String
var systemInfo = utsname()
uname(&systemInfo)
let machineMirror = Mirror(reflecting: systemInfo.machine)
Expand All @@ -18,8 +43,10 @@ public extension UIDevice {
}
// When running in simulator, identifier will be one of "i386", "x86_64", "arm64" instead of what we want.
switch identifier {
case "i386", "x86_64", "arm64": return ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? identifier
default: return identifier
case "i386", "x86_64", "arm64": result = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? identifier
default: result = identifier
}

return .init(rawValue: result)
}
}

0 comments on commit e978af7

Please sign in to comment.