Skip to content

Instantly share code, notes, and snippets.

@amadeu01
Created March 20, 2020 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amadeu01/9dbd56d4a373d7fd2fce65120efdef06 to your computer and use it in GitHub Desktop.
Save amadeu01/9dbd56d4a373d7fd2fce65120efdef06 to your computer and use it in GitHub Desktop.
import SwiftUI
import UIKit
class CustomLargeTitleNavigationBar: UINavigationBar {
private lazy var view: UIView = {
let view = UIView()
view.backgroundColor = .red
view.translatesAutoresizingMaskIntoConstraints = false
view.widthAnchor.constraint(equalToConstant: 200).isActive = true
view.heightAnchor.constraint(equalToConstant: 44).isActive = true
return view
}()
override func didMoveToSuperview() {
super.didMoveToSuperview()
print(subviews)
}
override func layoutSubviews() {
super.layoutSubviews()
for subview in subviews {
print("subviews", subview.description)
if let largeTitleLabel = subview.subviews.first(where: { $0 is UILabel }) as? UILabel {
print("😍")
let largeTitleView = subview
if !largeTitleView.subviews.contains(view) {
largeTitleView.addSubview(view)
view.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true
view.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true
}
break
}
}
}
}
struct CustomNavigationController: UIViewControllerRepresentable {
var controllers: [UIViewController]
func makeUIViewController(context: Context) -> UINavigationController {
let navController = UINavigationController(
navigationBarClass: CustomLargeTitleNavigationBar.self,
toolbarClass: nil
)
// let navController = UINavigationController()
navController.navigationBar.prefersLargeTitles = true
navController.viewControllers = controllers
/// Do something here later ?
return navController
}
func updateUIViewController(_ navController: UINavigationController, context: Context) {
navController.setViewControllers(controllers, animated: true)
}
}
struct HostViewController<Content: View>: View {
var viewControllers: [UIHostingController<Content>]
init(@ViewBuilder content: () -> Content) {
let vc = UIHostingController(rootView: content())
vc.title = "Hosting"
self.viewControllers = [vc]
}
var body: some View {
CustomNavigationController(controllers: viewControllers)
}
}
struct ContentView: View {
let emojiList = [
"🎨 - :art: - Improving structure / format of the code.",
"⚑️ - :zap: - Improving performance.",
"πŸ”₯ - :fire: - Removing code or files.",
"πŸ› - :bug: - Fixing a bug.",
"πŸš‘ - :ambulance: - Critical hotfix.",
"✨ - :sparkles: - Introducing new features.",
"πŸ“ - :pencil: - Writing docs.",
"πŸš€ - :rocket: - Deploying stuff.",
"πŸ’„ - :lipstick: - Updating the UI and style files.",
"πŸŽ‰ - :tada: - Initial commit.",
"βœ… - :white_check_mark: - Updating tests.",
"πŸ”’ - :lock: - Fixing security issues.",
"🍎 - :apple: - Fixing something on macOS.",
"🐧 - :penguin: - Fixing something on Linux.",
"🏁 - :checkered_flag: - Fixing something on Windows.",
"πŸ€– - :robot: - Fixing something on Android.",
"🍏 - :green_apple: - Fixing something on iOS.",
"πŸ”– - :bookmark: - Releasing / Version tags.",
"🚨 - :rotating_light: - Removing linter warnings.",
"🚧 - :construction: - Work in progress.",
"πŸ’š - :green_heart: - Fixing CI Build.",
"⬇️ - :arrow_down: - Downgrading dependencies.",
"⬆️ - :arrow_up: - Upgrading dependencies.",
"πŸ“Œ - :pushpin: - Pinning dependencies to specific versions.",
"πŸ‘· - :construction_worker: - Adding CI build system.",
"πŸ“ˆ - :chart_with_upwards_trend: - Adding analytics or tracking code.",
"♻️ - :recycle: - Refactoring code.",
"🐳 - :whale: - Work about Docker.",
"βž• - :heavy_plus_sign: - Adding a dependency.",
"βž– - :heavy_minus_sign: - Removing a dependency.",
"πŸ”§ - :wrench: - Changing configuration files.",
"🌐 - :globe_with_meridians: - Internationalization and localization.",
"✏️ - :pencil2: - Fixing typos.",
"πŸ’© - :poop: - Writing bad code that needs to be improved.",
"βͺ - :rewind: - Reverting changes.",
"πŸ”€ - :twisted_rightwards_arrows: - Merging branches.",
"πŸ“¦ - :package: - Updating compiled files or packages.",
"πŸ‘½ - :alien: - Updating code due to external API changes.",
"🚚 - :truck: - Moving or renaming files.",
"πŸ“„ - :page_facing_up: - Adding or updating license.",
"πŸ’₯ - :boom: - Introducing breaking changes.",
"🍱 - :bento: - Adding or updating assets.",
"πŸ‘Œ - :ok_hand: - Updating code due to code review changes.",
"♿️ - :wheelchair: - Improving accessibility.",
"πŸ’‘ - :bulb: - Documenting source code.",
"🍻 - :beers: - Writing code drunkenly.",
"πŸ’¬ - :speech_balloon: - Updating text and literals.",
"πŸ—ƒ - :card_file_box: - Performing database related changes.",
"πŸ”Š - :loud_sound: - Adding logs.",
"πŸ”‡ - :mute: - Removing logs.",
"πŸ‘₯ - :busts_in_silhouette: - Adding contributor(s).",
"🚸 - :children_crossing: - Improving user experience / usability."
]
var body: some View {
TabView {
HostViewController {
List(emojiList, id: \.self) { Text($0) }
}.tabItem {
Image(systemName: "star")
}
NavigationView {
List(emojiList, id: \.self) { Text($0) }
.navigationBarTitle(Text("Title"), displayMode: .large)
}.tabItem {
Image(systemName: "bookmark")
}
NavigationView {
VStack {
Text("Do Something here")
}.navigationBarTitle(Text("Title"), displayMode: .large)
}.tabItem {
Image(systemName: "bookmark")
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment