mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-02 00:17:02 +00:00
Fix badge overlap, fixes #45
This commit is contained in:
parent
fce69ba1cf
commit
2f4076d85f
@ -1,9 +1,84 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
import DeviceModel
|
||||
|
||||
extension Window1 {
|
||||
func sgAppBadgeOffset(_ defaultOffset: CGFloat) -> CGFloat {
|
||||
var additionalOffset: CGFloat = 0.0
|
||||
additionalOffset += 30.0
|
||||
return defaultOffset + additionalOffset
|
||||
|
||||
let DEVICE_MODELS_WITH_APP_BADGE_SUPPORT: [DeviceModel] = [
|
||||
.iPhoneX,
|
||||
.iPhoneXS,
|
||||
.iPhoneXSMax,
|
||||
.iPhoneXR,
|
||||
.iPhone11,
|
||||
.iPhone11Pro,
|
||||
.iPhone11ProMax,
|
||||
.iPhone12,
|
||||
.iPhone12Mini,
|
||||
.iPhone12Pro,
|
||||
.iPhone12ProMax,
|
||||
.iPhone13,
|
||||
.iPhone13Mini,
|
||||
.iPhone13Pro,
|
||||
.iPhone13ProMax,
|
||||
.iPhone14,
|
||||
.iPhone14Plus,
|
||||
.iPhone14Pro,
|
||||
.iPhone14ProMax,
|
||||
.iPhone15,
|
||||
.iPhone15Plus,
|
||||
.iPhone15Pro,
|
||||
.iPhone15ProMax,
|
||||
.iPhone16,
|
||||
.iPhone16Plus,
|
||||
.iPhone16Pro,
|
||||
.iPhone16ProMax,
|
||||
.iPhone16e
|
||||
]
|
||||
|
||||
extension DeviceMetrics {
|
||||
|
||||
func sgAppBadgeOffset() -> CGFloat {
|
||||
let currentDevice = DeviceModel.current
|
||||
var defaultOffset: CGFloat = 0.0
|
||||
// https://www.ios-resolution.com/
|
||||
// Similar height + Scale
|
||||
switch currentDevice {
|
||||
case .iPhoneX, .iPhoneXS, .iPhone11Pro, .iPhone12Mini, .iPhone13Mini:
|
||||
defaultOffset = 2.0
|
||||
case .iPhone11, .iPhoneXR:
|
||||
defaultOffset = 6.0
|
||||
case .iPhone11ProMax, .iPhoneXSMax:
|
||||
defaultOffset = 4.0
|
||||
case .iPhone12, .iPhone12Pro, .iPhone13, .iPhone13Pro, .iPhone14, .iPhone16e:
|
||||
defaultOffset = 4.0
|
||||
case .iPhone12ProMax, .iPhone13ProMax, .iPhone14Plus:
|
||||
defaultOffset = 6.0
|
||||
case .iPhone14Pro, .iPhone15, .iPhone15Pro, .iPhone16:
|
||||
defaultOffset = 18.0
|
||||
case .iPhone14ProMax, .iPhone15Plus, .iPhone15ProMax, .iPhone16Plus:
|
||||
defaultOffset = 19.0
|
||||
case .iPhone16Pro:
|
||||
defaultOffset = 21.0
|
||||
case .iPhone16ProMax:
|
||||
defaultOffset = 22.0
|
||||
default:
|
||||
defaultOffset = 0.0 // Any device in 2025+ should be like iPhone 14 Pro or better
|
||||
}
|
||||
let offset: CGFloat = floorToScreenPixels(defaultOffset * self.sgScaleFactor)
|
||||
#if DEBUG
|
||||
print("deviceMetrics \(self). deviceModel: \(currentDevice). sgIsDisplayZoomed: \(self.sgIsDisplayZoomed). sgScaleFactor: \(self.sgScaleFactor) defaultOffset: \(defaultOffset), offset: \(offset)")
|
||||
#endif
|
||||
return offset
|
||||
}
|
||||
|
||||
var sgIsDisplayZoomed: Bool {
|
||||
UIScreen.main.scale < UIScreen.main.nativeScale
|
||||
}
|
||||
|
||||
var sgScaleFactor: CGFloat {
|
||||
UIScreen.main.scale / UIScreen.main.nativeScale
|
||||
}
|
||||
|
||||
var sgShowAppBadge: Bool {
|
||||
return DEVICE_MODELS_WITH_APP_BADGE_SUPPORT.contains(DeviceModel.current) // MARK: Swiftgram
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,10 @@ sgsrc = [
|
||||
"//Swiftgram/SGAppBadgeOffset:SGAppBadgeOffset"
|
||||
]
|
||||
|
||||
sgdeps = [
|
||||
"//submodules/Utils/DeviceModel"
|
||||
]
|
||||
|
||||
swift_library(
|
||||
name = "Display",
|
||||
module_name = "Display",
|
||||
@ -13,7 +17,7 @@ swift_library(
|
||||
copts = [
|
||||
"-warnings-as-errors",
|
||||
],
|
||||
deps = [
|
||||
deps = sgdeps + [
|
||||
"//submodules/ObjCRuntimeUtils:ObjCRuntimeUtils",
|
||||
"//submodules/UIKitRuntimeUtils:UIKitRuntimeUtils",
|
||||
"//submodules/AppBundle:AppBundle",
|
||||
|
@ -382,10 +382,6 @@ public enum DeviceMetrics: CaseIterable, Equatable {
|
||||
}
|
||||
|
||||
public var showAppBadge: Bool {
|
||||
if case .iPhoneX = self {
|
||||
return false
|
||||
}
|
||||
// MARK: Swiftgram
|
||||
return self.hasTopNotch || self.hasDynamicIsland
|
||||
return self.sgShowAppBadge
|
||||
}
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ public class Window1 {
|
||||
public let hostView: WindowHostView
|
||||
public let badgeView: UIImageView
|
||||
|
||||
private var deviceMetrics: DeviceMetrics
|
||||
private(set) var deviceMetrics: DeviceMetrics
|
||||
|
||||
public let statusBarHost: StatusBarHost?
|
||||
private let keyboardManager: KeyboardManager?
|
||||
@ -1219,7 +1219,7 @@ public class Window1 {
|
||||
|
||||
if let image = self.badgeView.image {
|
||||
self.updateBadgeVisibility()
|
||||
self.badgeView.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((self.windowLayout.size.width - image.size.width) / 2.0), y: self.sgAppBadgeOffset(5.0)), size: image.size)
|
||||
self.badgeView.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((self.windowLayout.size.width - image.size.width) / 2.0), y: self.deviceMetrics.sgAppBadgeOffset()), size: image.size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,10 @@ swift_library(
|
||||
"-warnings-as-errors",
|
||||
],
|
||||
deps = [
|
||||
"//submodules/SSignalKit/SwiftSignalKit",
|
||||
"//submodules/LegacyComponents",
|
||||
"//submodules/AccountContext",
|
||||
# MARK: Swiftgram
|
||||
# "//submodules/SSignalKit/SwiftSignalKit",
|
||||
# "//submodules/LegacyComponents",
|
||||
# "//submodules/AccountContext",
|
||||
],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
|
@ -52,7 +52,8 @@ public enum DeviceModel: CaseIterable, Equatable {
|
||||
.iPhone16,
|
||||
.iPhone16Plus,
|
||||
.iPhone16Pro,
|
||||
.iPhone16ProMax
|
||||
.iPhone16ProMax,
|
||||
.iPhone16e
|
||||
]
|
||||
}
|
||||
|
||||
@ -373,6 +374,10 @@ public enum DeviceModel: CaseIterable, Equatable {
|
||||
public static let current = DeviceModel()
|
||||
|
||||
private init() {
|
||||
// MARK: Swiftgram
|
||||
#if targetEnvironment(simulator)
|
||||
let modelCode = ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"]
|
||||
#else
|
||||
var systemInfo = utsname()
|
||||
uname(&systemInfo)
|
||||
let modelCode = withUnsafePointer(to: &systemInfo.machine) {
|
||||
@ -380,6 +385,7 @@ public enum DeviceModel: CaseIterable, Equatable {
|
||||
ptr in String.init(validatingUTF8: ptr)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
var result: DeviceModel?
|
||||
if let modelCode {
|
||||
for model in DeviceModel.allCases {
|
||||
|
Loading…
x
Reference in New Issue
Block a user