Skip to content

Commit a1da130

Browse files
committed
device-specific position and width
depending on the device corner radius and notch width; keeping clear the camera/mic indicator;
1 parent c9c8e07 commit a1da130

File tree

4 files changed

+52
-8
lines changed

4 files changed

+52
-8
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.1)
2+
- FTLinearActivityIndicator (1.4)
33

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

1111
SPEC CHECKSUMS:
12-
FTLinearActivityIndicator: e044fb1ca7f9776a3058f64b5dfe02e1d56ba44b
12+
FTLinearActivityIndicator: 572f5f623e357181d94731e63a406db683ec177b
1313

1414
PODFILE CHECKSUM: d653595fcbe53f0d4160295f6c50f84621e4a209
1515

16-
COCOAPODS: 1.5.3
16+
COCOAPODS: 1.10.1

FTLinearActivityIndicator.podspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Pod::Spec.new do |s|
22
s.name = 'FTLinearActivityIndicator'
3-
s.version = '1.3.1'
3+
s.version = '1.4'
44
s.summary = 'Add the missing network activity indicator on iPhone X'
55

66
s.description = <<-DESC
77
iPhones with a notch such as X, XS, XR, 11 (Pro), 12 (mini, Pro) don't display the
88
network activity indicator anymore. This pod brings it back by placing an activity
9-
indicator in the upper left of the screen on top of the regular status bar items.
10-
Since a circular ndicator wouldn't fit, a rectangular "KITT scanner" like indicator
9+
indicator in the upper right of the screen on top of the regular status bar items.
10+
Since a circular indicator wouldn't fit, a rectangular "KITT scanner" like indicator
1111
with a gradient is shown. The indicator UI can be used standalone or as a "fix" for
1212
the iOS network activity indicator (using the existing API).
1313
DESC

FTLinearActivityIndicator/Classes/UIApplication+LinearNetworkActivityIndicator.swift

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extension UIApplication {
1212
@objc final public class func configureLinearNetworkActivityIndicatorIfNeeded() {
1313
#if !targetEnvironment(macCatalyst)
1414
if #available(iOS 11.0, *) {
15-
// detect iPhone X
15+
// detect notch
1616
if let window = shared.windows.first, window.safeAreaInsets.bottom > 0.0 {
1717
if UIDevice.current.userInterfaceIdiom != .pad {
1818
configureLinearNetworkActivityIndicator()
@@ -65,7 +65,30 @@ extension UIApplication {
6565
indicatorWindow?.windowLevel = UIWindow.Level.statusBar + 1
6666
indicatorWindow?.isUserInteractionEnabled = false
6767

68-
let indicator = FTLinearActivityIndicator(frame: CGRect(x: indicatorWindow!.frame.width - 74, y: 6, width: 44, height: 4))
68+
// notched iPhones differ in corner radius and right notch width
69+
// => lookup margin from right window edge, and width
70+
let layout: [String: (CGFloat, CGFloat)] = [
71+
"iPhone10,3": (74, 44), // iPhone X
72+
"iPhone10,6": (74, 44), // iPhone X
73+
"iPhone11,2": (74, 44), // Phone Xs
74+
"iPhone11,4": (74, 44), // iPhone Xs Max
75+
"iPhone11,6": (74, 44), // iPhone Xs Max
76+
"iPhone11,8": (70, 40), // iPhone XR
77+
"iPhone12,1": (70, 40), // iPhone 11
78+
"iPhone12,3": (60, 34), // iPhone 11 Pro
79+
"iPhone12,5": (74, 44), // iPhone 11 Pro Max
80+
"iPhone13,1": (60, 30), // iPhone 12 Mini
81+
"iPhone13,2": (72, 34), // iPhone 12
82+
"iPhone13,3": (72, 34), // iPhone 12 Pro
83+
"iPhone13,4": (80, 42), // iPhone 12 Pro Max
84+
]
85+
let modelName = UIDevice.current.ftModelName
86+
let config = layout[modelName] ?? (74, 44)
87+
88+
let x = indicatorWindow!.frame.width - config.0
89+
let width = config.1
90+
91+
let indicator = FTLinearActivityIndicator(frame: CGRect(x: x, y: 7, width: width, height: 4.5))
6992
indicator.isUserInteractionEnabled = false
7093
indicator.hidesWhenStopped = false
7194
indicator.startAnimating()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// UIDevice+Extension.swift
3+
// FTLinearActivityIndicator
4+
//
5+
// Created by Ortwin Gentz on 15.03.21.
6+
//
7+
8+
import Foundation
9+
10+
public extension UIDevice {
11+
var ftModelName: String {
12+
var systemInfo = utsname()
13+
uname(&systemInfo)
14+
let machineMirror = Mirror(reflecting: systemInfo.machine)
15+
let identifier = machineMirror.children.reduce("") { identifier, element in
16+
guard let value = element.value as? Int8, value != 0 else { return identifier }
17+
return identifier + String(UnicodeScalar(UInt8(value)))
18+
}
19+
return identifier
20+
}
21+
}

0 commit comments

Comments
 (0)