Created
March 20, 2020 21:59
-
-
Save amadeu01/9dbd56d4a373d7fd2fce65120efdef06 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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