mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
4.4 KiB
Swift
133 lines
4.4 KiB
Swift
7 years ago
|
//
|
||
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import Foundation
|
||
|
import UIKit
|
||
|
|
||
|
@objc
|
||
7 years ago
|
class OWSNavigationBar: UINavigationBar {
|
||
7 years ago
|
|
||
|
// TODO - get a more precise value
|
||
|
// TODO - test with other heights, e.g. w/ hotspot, w/ call in other app
|
||
|
let navbarHeight: CGFloat = 44
|
||
7 years ago
|
let callBannerHeight: CGFloat = 40
|
||
7 years ago
|
|
||
|
override init(frame: CGRect) {
|
||
|
super.init(frame: frame)
|
||
|
|
||
7 years ago
|
self.isTranslucent = false
|
||
|
|
||
7 years ago
|
// TODO better place to observe?
|
||
|
NotificationCenter.default.addObserver(forName: .OWSWindowManagerCallDidChange, object: nil, queue: nil) { _ in
|
||
|
Logger.debug("\(self.logTag) in \(#function) OWSWindowManagerCallDidChange")
|
||
|
|
||
|
self.callDidChange()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private func callDidChange() {
|
||
7 years ago
|
// if OWSWindowManager.shared().hasCall() {
|
||
|
// self.bounds.origin.y = -20
|
||
|
// } else {
|
||
|
// self.bounds.origin.y = 0
|
||
|
// }
|
||
7 years ago
|
if #available(iOS 11, *) {
|
||
|
self.layoutSubviews()
|
||
7 years ago
|
} else {
|
||
7 years ago
|
self.sizeToFit()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
required init?(coder aDecoder: NSCoder) {
|
||
|
fatalError("init(coder:) has not been implemented")
|
||
|
}
|
||
|
|
||
|
override func sizeThatFits(_ size: CGSize) -> CGSize {
|
||
|
// pre iOS11, sizeThatFits is repeatedly called to size the navbar, which is pretty straight forward
|
||
|
// as of iOS11, this is not true and we have to do things in layoutSubviews.
|
||
|
// FIXME: pre-iOS11, though the size is right, there's a glitch on the titleView while push/popping items.
|
||
7 years ago
|
|
||
|
// MJK safe to hardcode? Do we even need this approach anymore?
|
||
|
let statusBarHeight: CGFloat = 20
|
||
7 years ago
|
let result: CGSize = {
|
||
|
if OWSWindowManager.shared().hasCall() {
|
||
|
// status bar height gets re-added
|
||
7 years ago
|
return CGSize(width: CurrentAppContext().mainWindow!.bounds.width, height: navbarHeight - statusBarHeight)
|
||
7 years ago
|
} else {
|
||
|
return super.sizeThatFits(size)
|
||
|
}
|
||
|
}()
|
||
|
|
||
|
Logger.debug("\(self.logTag) in \(#function): \(result)")
|
||
|
|
||
|
return result
|
||
|
}
|
||
|
|
||
7 years ago
|
// override var center: CGPoint {
|
||
|
// get {
|
||
|
// Logger.debug("\(self.logTag) in \(#function)")
|
||
|
// return super.center
|
||
|
// }
|
||
|
// set {
|
||
|
// Logger.debug("\(self.logTag) in \(#function)")
|
||
|
// if OWSWindowManager.shared().hasCall() {
|
||
|
// var translated = newValue
|
||
|
//// translated.y -= 20
|
||
|
// super.center = translated
|
||
|
// } else {
|
||
|
// super.center = newValue
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
|
||
7 years ago
|
// seems unused.
|
||
|
// override var intrinsicContentSize: CGSize {
|
||
|
// return CGSize(width: UIScreen.main.bounds.width, height: navbarHeight)
|
||
|
// return CGSize(width: UIScreen.main.bounds.width, height: 20)
|
||
|
// }
|
||
|
|
||
|
// override var bounds: CGRect {
|
||
|
// get {
|
||
|
// return super.bounds
|
||
|
// }
|
||
|
// set {
|
||
|
// super.bounds = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: ios11NavbarHeight)
|
||
|
// }
|
||
|
// }
|
||
|
//
|
||
|
// override var frame: CGRect {
|
||
|
// get {
|
||
|
// return super.frame
|
||
|
// }
|
||
|
// set {
|
||
|
// super.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: ios11NavbarHeight)
|
||
|
// }
|
||
|
// }
|
||
|
|
||
7 years ago
|
override func layoutSubviews() {
|
||
|
Logger.debug("\(self.logTag) in \(#function)")
|
||
|
|
||
|
guard #available(iOS 11.0, *), OWSWindowManager.shared().hasCall() else {
|
||
|
super.layoutSubviews()
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// let rect = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: self.navbarHeightWithoutStatusBar)
|
||
|
// self.frame = CGRect(x: 0, y: 20, width: UI Screen.main.bounds.width, height: ios11NavbarHeight)
|
||
7 years ago
|
self.frame = CGRect(x: 0, y: callBannerHeight, width: UIScreen.main.bounds.width, height: navbarHeight)
|
||
7 years ago
|
self.bounds = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: navbarHeight)
|
||
|
|
||
|
super.layoutSubviews()
|
||
|
|
||
|
for subview in self.subviews {
|
||
|
let stringFromClass = NSStringFromClass(subview.classForCoder)
|
||
|
if stringFromClass.contains("BarBackground") {
|
||
7 years ago
|
subview.frame = self.bounds//.offsetBy(dx: 0, dy: 20)
|
||
7 years ago
|
} else if stringFromClass.contains("BarContentView") {
|
||
7 years ago
|
subview.frame = self.bounds//.offsetBy(dx: 0, dy: 20)
|
||
7 years ago
|
}
|
||
7 years ago
|
}
|
||
|
}
|
||
|
}
|