Files
SideStore/AltStore/Components/NavigationBar.swift

102 lines
2.9 KiB
Swift
Raw Normal View History

//
// NavigationBar.swift
// AltStore
//
// Created by Riley Testut on 7/15/19.
// Copyright © 2019 Riley Testut. All rights reserved.
//
import UIKit
import Roxas
2024-12-07 17:45:09 +05:30
class NavigationBarAppearance: UINavigationBarAppearance
{
// We sometimes need to ignore user interaction so
// we can tap items underneath the navigation bar.
var ignoresUserInteraction: Bool = false
override func copy(with zone: NSZone? = nil) -> Any
{
let copy = super.copy(with: zone) as! NavigationBarAppearance
copy.ignoresUserInteraction = self.ignoresUserInteraction
return copy
}
}
class NavigationBar: UINavigationBar
{
2019-09-05 15:37:58 -07:00
@IBInspectable var automaticallyAdjustsItemPositions: Bool = true
override init(frame: CGRect)
{
super.init(frame: frame)
self.initialize()
}
required init?(coder aDecoder: NSCoder)
{
super.init(coder: aDecoder)
self.initialize()
}
private func initialize()
{
2023-03-02 16:53:36 -06:00
let standardAppearance = UINavigationBarAppearance()
standardAppearance.configureWithDefaultBackground()
standardAppearance.shadowColor = nil
let edgeAppearance = UINavigationBarAppearance()
edgeAppearance.configureWithOpaqueBackground()
edgeAppearance.backgroundColor = self.barTintColor
edgeAppearance.shadowColor = nil
if let tintColor = self.barTintColor
2019-09-05 11:59:10 -07:00
{
2023-03-02 16:53:36 -06:00
let textAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
2019-10-24 13:04:30 -07:00
2023-03-02 16:53:36 -06:00
standardAppearance.backgroundColor = tintColor
standardAppearance.titleTextAttributes = textAttributes
standardAppearance.largeTitleTextAttributes = textAttributes
2019-09-05 11:59:10 -07:00
2023-03-02 16:53:36 -06:00
edgeAppearance.titleTextAttributes = textAttributes
edgeAppearance.largeTitleTextAttributes = textAttributes
2019-09-05 11:59:10 -07:00
}
else
{
2023-03-02 16:53:36 -06:00
standardAppearance.backgroundColor = nil
2019-09-05 11:59:10 -07:00
}
2023-03-02 16:53:36 -06:00
self.scrollEdgeAppearance = edgeAppearance
self.standardAppearance = standardAppearance
}
override func layoutSubviews()
{
super.layoutSubviews()
2019-09-05 15:37:58 -07:00
if self.automaticallyAdjustsItemPositions
{
2019-09-05 15:37:58 -07:00
// We can't easily shift just the back button up, so we shift the entire content view slightly.
for contentView in self.subviews
{
guard NSStringFromClass(type(of: contentView)).contains("ContentView") else { continue }
contentView.center.y -= 2
}
}
}
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView?
{
if let appearance = self.topItem?.standardAppearance as? NavigationBarAppearance, appearance.ignoresUserInteraction
{
// Ignore touches.
return nil
}
return super.hitTest(point, with: event)
}
}