Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lipmeco committed Jul 25, 2023
1 parent a196a16 commit 0b89a0f
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 76 deletions.
8 changes: 2 additions & 6 deletions submodules/AccountContext/Sources/DeviceContactData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,10 @@ public final class DeviceContactExtendedData: Equatable {

public extension DeviceContactExtendedData {
convenience init?(vcard: Data) {
if #available(iOSApplicationExtension 9.0, iOS 9.0, *) {
guard let contact = (try? CNContactVCardSerialization.contacts(with: vcard))?.first else {
return nil
}
self.init(contact: contact)
} else {
guard let contact = (try? CNContactVCardSerialization.contacts(with: vcard))?.first else {
return nil
}
self.init(contact: contact)
}

@available(iOSApplicationExtension 9.0, iOS 9.0, *)
Expand Down
4 changes: 1 addition & 3 deletions submodules/AdUI/Sources/AdInfoScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ public final class AdInfoScreen: ViewController {
self.scrollNode.view.scrollsToTop = true
self.scrollNode.view.delaysContentTouches = false
self.scrollNode.view.canCancelContentTouches = true
if #available(iOS 11.0, *) {
self.scrollNode.view.contentInsetAdjustmentBehavior = .never
}
self.scrollNode.view.contentInsetAdjustmentBehavior = .never

var openUrl: ((String) -> Void)?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,10 @@ final class BotCheckoutWebInteractionControllerNode: ViewControllerTracingNode,
configuration.userContentController = userController

webView = WKWebView(frame: CGRect(), configuration: configuration)
if #available(iOSApplicationExtension 9.0, iOS 9.0, *) {
webView.allowsLinkPreview = false
}
webView.allowsLinkPreview = false
case .externalVerification:
webView = WKWebView()
if #available(iOSApplicationExtension 9.0, iOS 9.0, *) {
webView.allowsLinkPreview = false
}
webView.allowsLinkPreview = false
webView.navigationDelegate = self
}
if #available(iOSApplicationExtension 11.0, iOS 11.0, *) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,7 @@ public final class ReactionListContextMenuContent: ContextControllerItemsContent
self.scrollNode.view.delaysContentTouches = false
self.scrollNode.view.showsVerticalScrollIndicator = false
self.scrollNode.view.showsHorizontalScrollIndicator = false
if #available(iOS 11.0, *) {
self.scrollNode.view.contentInsetAdjustmentBehavior = .never
}
self.scrollNode.view.contentInsetAdjustmentBehavior = .never
self.scrollNode.view.disablesInteractiveTransitionGestureRecognizer = true

self.itemNodes = reactions.map { reaction, count in
Expand Down Expand Up @@ -795,9 +793,7 @@ public final class ReactionListContextMenuContent: ContextControllerItemsContent
self.scrollNode.canCancelAllTouchesInViews = true
self.scrollNode.view.delaysContentTouches = false
self.scrollNode.view.showsVerticalScrollIndicator = false
if #available(iOS 11.0, *) {
self.scrollNode.view.contentInsetAdjustmentBehavior = .never
}
self.scrollNode.view.contentInsetAdjustmentBehavior = .never
self.scrollNode.clipsToBounds = false

super.init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ public final class DeviceLocationManager: NSObject {
self.manager.activityType = .other
self.manager.pausesLocationUpdatesAutomatically = false
self.manager.headingFilter = 2.0
if #available(iOS 11.0, *) {
self.manager.showsBackgroundLocationIndicator = true
}
self.manager.showsBackgroundLocationIndicator = true
}

public func push(mode: DeviceLocationMode, updated: @escaping (CLLocation, Double?) -> Void) -> Disposable {
Expand Down
14 changes: 4 additions & 10 deletions submodules/Display/Source/CAAnimationUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,8 @@ public extension CALayer {

func springAnimation(from: AnyObject, to: AnyObject, keyPath: String, duration: Double, delay: Double = 0.0, initialVelocity: CGFloat = 0.0, damping: CGFloat = 88.0, removeOnCompletion: Bool = true, additive: Bool = false) -> CABasicAnimation {
let animation: CABasicAnimation
if #available(iOS 9.0, *) {
animation = makeSpringBounceAnimation(keyPath, initialVelocity, damping)
} else {
animation = makeSpringAnimation(keyPath)
}
animation = makeSpringBounceAnimation(keyPath, initialVelocity, damping)

animation.fromValue = from
animation.toValue = to
animation.isRemovedOnCompletion = removeOnCompletion
Expand All @@ -302,11 +299,8 @@ public extension CALayer {

func animateSpring(from: AnyObject, to: AnyObject, keyPath: String, duration: Double, delay: Double = 0.0, initialVelocity: CGFloat = 0.0, damping: CGFloat = 88.0, removeOnCompletion: Bool = true, additive: Bool = false, completion: ((Bool) -> Void)? = nil) {
let animation: CABasicAnimation
if #available(iOS 9.0, *) {
animation = makeSpringBounceAnimation(keyPath, initialVelocity, damping)
} else {
animation = makeSpringAnimation(keyPath)
}
animation = makeSpringBounceAnimation(keyPath, initialVelocity, damping)

animation.fromValue = from
animation.toValue = to
animation.isRemovedOnCompletion = removeOnCompletion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ final class InstantPageWebEmbedNode: ASDisplayNode, InstantPageNode {

let webView = WKWebView(frame: CGRect(origin: CGPoint(), size: frame.size), configuration: configuration)
webView.allowsBackForwardNavigationGestures = false
if #available(iOSApplicationExtension 9.0, iOS 9.0, *) {
webView.allowsLinkPreview = false
}
webView.allowsLinkPreview = false
if #available(iOSApplicationExtension 11.0, iOS 11.0, *) {
webView.scrollView.contentInsetAdjustmentBehavior = .never
}
Expand Down
4 changes: 1 addition & 3 deletions submodules/TelegramUI/Sources/StoreDownloadedMedia.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,7 @@ private final class DownloadedMediaStoreContext {
}

let options = PHFetchOptions()
if #available(iOSApplicationExtension 9.0, iOS 9.0, *) {
options.fetchLimit = 11
}
options.fetchLimit = 11

options.predicate = NSPredicate(format: "creationDate == %@", creationDate as CVarArg)
var alreadyStored = false
Expand Down
4 changes: 1 addition & 3 deletions submodules/TooltipUI/Sources/TooltipScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -751,9 +751,7 @@ private final class TooltipScreenNode: ViewControllerTracingNode {
}

var eventIsPresses = false
if #available(iOSApplicationExtension 9.0, iOS 9.0, *) {
eventIsPresses = event.type == .presses
}
eventIsPresses = event.type == .presses
if event.type == .touches || eventIsPresses {
if let actionButtonNode = self.actionButtonNode, let result = actionButtonNode.hitTest(self.convert(point, to: actionButtonNode), with: event) {
return result
Expand Down
10 changes: 4 additions & 6 deletions submodules/TranslateUI/Sources/TranslateScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -673,12 +673,10 @@ public class TranslateScreen: ViewController {
self.containerView.layer.cornerRadius = 10.0
}

if #available(iOS 11.0, *) {
if layout.safeInsets.bottom.isZero {
self.containerView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
} else {
self.containerView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner, .layerMinXMaxYCorner, .layerMaxXMaxYCorner]
}
if layout.safeInsets.bottom.isZero {
self.containerView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
} else {
self.containerView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner, .layerMinXMaxYCorner, .layerMaxXMaxYCorner]
}

if isLandscape {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,7 @@ public func watchCommunicationManager(context: Signal<WatchCommunicationManagerC
return Signal { subscriber in
let queue = Queue()
queue.async {
if #available(iOSApplicationExtension 9.0, *) {
subscriber.putNext(WatchCommunicationManager(queue: queue, context: context, allowBackgroundTimeExtension: allowBackgroundTimeExtension))
} else {
subscriber.putNext(nil)
}
subscriber.putNext(WatchCommunicationManager(queue: queue, context: context, allowBackgroundTimeExtension: allowBackgroundTimeExtension))
subscriber.putCompletion()
}
return EmptyDisposable
Expand Down
36 changes: 14 additions & 22 deletions submodules/WebUI/Sources/WebAppWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,15 @@ final class WebAppWebView: WKWebView {

configuration.allowsInlineMediaPlayback = true
configuration.allowsPictureInPictureMediaPlayback = false
if #available(iOSApplicationExtension 10.0, iOS 10.0, *) {
configuration.mediaTypesRequiringUserActionForPlayback = .all
} else {
configuration.mediaPlaybackRequiresUserAction = true
}
configuration.mediaTypesRequiringUserActionForPlayback = .all

super.init(frame: CGRect(), configuration: configuration)

self.disablesInteractiveKeyboardGestureRecognizer = true

self.isOpaque = false
self.backgroundColor = .clear
if #available(iOSApplicationExtension 9.0, iOS 9.0, *) {
self.allowsLinkPreview = false
}
self.allowsLinkPreview = false
if #available(iOSApplicationExtension 11.0, iOS 11.0, *) {
self.scrollView.contentInsetAdjustmentBehavior = .never
}
Expand All @@ -103,20 +97,18 @@ final class WebAppWebView: WKWebView {
override func didMoveToSuperview() {
super.didMoveToSuperview()

if #available(iOS 11.0, *) {
let webScrollView = self.subviews.compactMap { $0 as? UIScrollView }.first
Queue.mainQueue().after(0.1, {
let contentView = webScrollView?.subviews.first(where: { $0.interactions.count > 1 })
guard let dragInteraction = (contentView?.interactions.compactMap { $0 as? UIDragInteraction }.first) else {
return
}
contentView?.removeInteraction(dragInteraction)
})

NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil)
}
let webScrollView = self.subviews.compactMap { $0 as? UIScrollView }.first
Queue.mainQueue().after(0.1, {
let contentView = webScrollView?.subviews.first(where: { $0.interactions.count > 1 })
guard let dragInteraction = (contentView?.interactions.compactMap { $0 as? UIDragInteraction }.first) else {
return
}
contentView?.removeInteraction(dragInteraction)
})

NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil)
}

func sendEvent(name: String, data: String?) {
Expand Down

0 comments on commit 0b89a0f

Please sign in to comment.