mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Add custom proximity sensor screen dimming since it's broken on iPhone 14
This commit is contained in:
parent
824e887294
commit
275e1da4bb
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
@interface DeviceProximityManager : NSObject
|
@interface DeviceProximityManager : NSObject
|
||||||
|
|
||||||
|
@property (nonatomic, copy) void(^ _Nullable proximityChanged)(bool);
|
||||||
|
|
||||||
+ (DeviceProximityManager * _Nonnull)shared;
|
+ (DeviceProximityManager * _Nonnull)shared;
|
||||||
|
|
||||||
- (bool)currentValue;
|
- (bool)currentValue;
|
||||||
|
@ -46,6 +46,9 @@
|
|||||||
for (void (^f)(bool) in [strongSelf->_subscribers copyItems]) {
|
for (void (^f)(bool) in [strongSelf->_subscribers copyItems]) {
|
||||||
f(proximityState);
|
f(proximityState);
|
||||||
}
|
}
|
||||||
|
if (strongSelf.proximityChanged != nil) {
|
||||||
|
strongSelf.proximityChanged(proximityState);
|
||||||
|
}
|
||||||
} else if (!strongSelf->_proximityState && [strongSelf->_subscribers isEmpty]) {
|
} else if (!strongSelf->_proximityState && [strongSelf->_subscribers isEmpty]) {
|
||||||
[UIDevice currentDevice].proximityMonitoringEnabled = false;
|
[UIDevice currentDevice].proximityMonitoringEnabled = false;
|
||||||
}
|
}
|
||||||
@ -90,6 +93,9 @@
|
|||||||
for (void (^f)(bool) in [_subscribers copyItems]) {
|
for (void (^f)(bool) in [_subscribers copyItems]) {
|
||||||
f(_proximityState);
|
f(_proximityState);
|
||||||
}
|
}
|
||||||
|
if (self.proximityChanged != nil) {
|
||||||
|
self.proximityChanged(_proximityState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (_proximityState) {
|
if (_proximityState) {
|
||||||
@ -97,6 +103,9 @@
|
|||||||
for (void (^f)(bool) in [_subscribers copyItems]) {
|
for (void (^f)(bool) in [_subscribers copyItems]) {
|
||||||
f(_proximityState);
|
f(_proximityState);
|
||||||
}
|
}
|
||||||
|
if (self.proximityChanged != nil) {
|
||||||
|
self.proximityChanged(_proximityState);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
[UIDevice currentDevice].proximityMonitoringEnabled = false;
|
[UIDevice currentDevice].proximityMonitoringEnabled = false;
|
||||||
}
|
}
|
||||||
|
@ -241,6 +241,7 @@ public final class WindowKeyboardGestureRecognizerDelegate: NSObject, UIGestureR
|
|||||||
public class Window1 {
|
public class Window1 {
|
||||||
public let hostView: WindowHostView
|
public let hostView: WindowHostView
|
||||||
public let badgeView: UIImageView
|
public let badgeView: UIImageView
|
||||||
|
private let customProximityDimView: UIView
|
||||||
|
|
||||||
private var deviceMetrics: DeviceMetrics
|
private var deviceMetrics: DeviceMetrics
|
||||||
|
|
||||||
@ -257,8 +258,6 @@ public class Window1 {
|
|||||||
private var updatingLayout: UpdatingLayout?
|
private var updatingLayout: UpdatingLayout?
|
||||||
private var updatedContainerLayout: ContainerViewLayout?
|
private var updatedContainerLayout: ContainerViewLayout?
|
||||||
private var upperKeyboardInputPositionBound: CGFloat?
|
private var upperKeyboardInputPositionBound: CGFloat?
|
||||||
private var cachedWindowSubviewCount: Int = 0
|
|
||||||
private var cachedHasPreview: Bool = false
|
|
||||||
|
|
||||||
private let presentationContext: PresentationContext
|
private let presentationContext: PresentationContext
|
||||||
private let overlayPresentationContext: GlobalOverlayPresentationContext
|
private let overlayPresentationContext: GlobalOverlayPresentationContext
|
||||||
@ -271,9 +270,6 @@ public class Window1 {
|
|||||||
|
|
||||||
private var statusBarHidden = false
|
private var statusBarHidden = false
|
||||||
|
|
||||||
public var previewThemeAccentColor: UIColor = .blue
|
|
||||||
public var previewThemeDarkBlur: Bool = false
|
|
||||||
|
|
||||||
private var shouldNotAnimateLikelyKeyboardAutocorrectionSwitch: Bool = false
|
private var shouldNotAnimateLikelyKeyboardAutocorrectionSwitch: Bool = false
|
||||||
|
|
||||||
public private(set) var forceInCallStatusBarText: String? = nil
|
public private(set) var forceInCallStatusBarText: String? = nil
|
||||||
@ -333,6 +329,10 @@ public class Window1 {
|
|||||||
self.badgeView.image = UIImage(bundleImageName: "Components/AppBadge")
|
self.badgeView.image = UIImage(bundleImageName: "Components/AppBadge")
|
||||||
self.badgeView.isHidden = true
|
self.badgeView.isHidden = true
|
||||||
|
|
||||||
|
self.customProximityDimView = UIView()
|
||||||
|
self.customProximityDimView.backgroundColor = .black
|
||||||
|
self.customProximityDimView.isHidden = true
|
||||||
|
|
||||||
self.systemUserInterfaceStyle = hostView.systemUserInterfaceStyle
|
self.systemUserInterfaceStyle = hostView.systemUserInterfaceStyle
|
||||||
|
|
||||||
let boundsSize = self.hostView.eventView.bounds.size
|
let boundsSize = self.hostView.eventView.bounds.size
|
||||||
@ -652,6 +652,7 @@ public class Window1 {
|
|||||||
self.windowPanRecognizer = recognizer
|
self.windowPanRecognizer = recognizer
|
||||||
self.hostView.containerView.addGestureRecognizer(recognizer)
|
self.hostView.containerView.addGestureRecognizer(recognizer)
|
||||||
self.hostView.containerView.addSubview(self.badgeView)
|
self.hostView.containerView.addSubview(self.badgeView)
|
||||||
|
self.hostView.containerView.addSubview(self.customProximityDimView)
|
||||||
}
|
}
|
||||||
|
|
||||||
public required init(coder aDecoder: NSCoder) {
|
public required init(coder aDecoder: NSCoder) {
|
||||||
@ -685,6 +686,13 @@ public class Window1 {
|
|||||||
self.updateBadgeVisibility()
|
self.updateBadgeVisibility()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func setProximityDimHidden(_ hidden: Bool) {
|
||||||
|
guard hidden != self.customProximityDimView.isHidden else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
self.customProximityDimView.isHidden = hidden
|
||||||
|
}
|
||||||
|
|
||||||
private func updateBadgeVisibility() {
|
private func updateBadgeVisibility() {
|
||||||
let badgeIsHidden = !self.deviceMetrics.showAppBadge || self.forceBadgeHidden || self.windowLayout.size.width > self.windowLayout.size.height
|
let badgeIsHidden = !self.deviceMetrics.showAppBadge || self.forceBadgeHidden || self.windowLayout.size.width > self.windowLayout.size.height
|
||||||
if badgeIsHidden != self.badgeView.isHidden && !badgeIsHidden {
|
if badgeIsHidden != self.badgeView.isHidden && !badgeIsHidden {
|
||||||
@ -1141,6 +1149,8 @@ public class Window1 {
|
|||||||
self.updateBadgeVisibility()
|
self.updateBadgeVisibility()
|
||||||
self.badgeView.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((self.windowLayout.size.width - image.size.width) / 2.0), y: 5.0), size: image.size)
|
self.badgeView.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((self.windowLayout.size.width - image.size.width) / 2.0), y: 5.0), size: image.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.customProximityDimView.frame = CGRect(origin: .zero, size: self.windowLayout.size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ import UIKitRuntimeUtils
|
|||||||
import StoreKit
|
import StoreKit
|
||||||
import PhoneNumberFormat
|
import PhoneNumberFormat
|
||||||
import AuthorizationUI
|
import AuthorizationUI
|
||||||
|
import DeviceProximity
|
||||||
|
|
||||||
#if canImport(AppCenter)
|
#if canImport(AppCenter)
|
||||||
import AppCenter
|
import AppCenter
|
||||||
@ -1316,6 +1317,13 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
|
|||||||
self.runForegroundTasks()
|
self.runForegroundTasks()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DeviceProximityManager.shared().proximityChanged = { [weak self] value in
|
||||||
|
if let strongSelf = self {
|
||||||
|
strongSelf.mainWindow.setProximityDimHidden(!value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if UIApplication.shared.isStatusBarHidden {
|
if UIApplication.shared.isStatusBarHidden {
|
||||||
UIApplication.shared.internalSetStatusBarHidden(false, animation: .none)
|
UIApplication.shared.internalSetStatusBarHidden(false, animation: .none)
|
||||||
}
|
}
|
||||||
|
@ -165,9 +165,6 @@ final class AuthorizedApplicationContext {
|
|||||||
|
|
||||||
self.notificationController = NotificationContainerController(context: context)
|
self.notificationController = NotificationContainerController(context: context)
|
||||||
|
|
||||||
self.mainWindow.previewThemeAccentColor = presentationData.theme.rootController.navigationBar.accentTextColor
|
|
||||||
self.mainWindow.previewThemeDarkBlur = presentationData.theme.rootController.keyboardColor == .dark
|
|
||||||
|
|
||||||
self.rootController = TelegramRootController(context: context)
|
self.rootController = TelegramRootController(context: context)
|
||||||
|
|
||||||
self.rootController.globalOverlayControllersUpdated = { [weak self] in
|
self.rootController.globalOverlayControllersUpdated = { [weak self] in
|
||||||
@ -735,8 +732,6 @@ final class AuthorizedApplicationContext {
|
|||||||
|> deliverOnMainQueue).start(next: { [weak self] presentationData in
|
|> deliverOnMainQueue).start(next: { [weak self] presentationData in
|
||||||
if let strongSelf = self {
|
if let strongSelf = self {
|
||||||
if previousTheme.swap(presentationData.theme) !== presentationData.theme {
|
if previousTheme.swap(presentationData.theme) !== presentationData.theme {
|
||||||
strongSelf.mainWindow.previewThemeAccentColor = presentationData.theme.rootController.navigationBar.accentTextColor
|
|
||||||
strongSelf.mainWindow.previewThemeDarkBlur = presentationData.theme.rootController.keyboardColor == .dark
|
|
||||||
strongSelf.lockedCoveringView.updateTheme(presentationData.theme)
|
strongSelf.lockedCoveringView.updateTheme(presentationData.theme)
|
||||||
strongSelf.rootController.updateTheme(NavigationControllerTheme(presentationTheme: presentationData.theme))
|
strongSelf.rootController.updateTheme(NavigationControllerTheme(presentationTheme: presentationData.theme))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user