Skip to content

Commit 1cab274

Browse files
committed
feat: added Extra parameter to set large title for navigation.
1 parent 6994be6 commit 1cab274

6 files changed

Lines changed: 35 additions & 13 deletions

File tree

Examples/MVI-Example/MVI-Example/AppMain.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension AppMain: App {
2121
var body: some Scene {
2222
WindowGroup {
2323
navigator
24-
.launch(paths: ["home"], items: [:])
24+
.launch(paths: ["home"], items: [:], prefersLargeTitles: true)
2525
.onOpenURL { url in
2626
print(url.absoluteString)
2727
// !!!: mvi-ex://host/home/page1/page2/page3/page4?page3-message=hello&page4-message=%ED%95%9C%EA%B8%80

Examples/MVI-Example/MVI-Example/Feature/Home/HomeIntent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ extension HomeIntent: IntentType, HomeIntentType {
5959
navigator.sheet(paths: ["page1", "page2"], items: [:], isAnimated: true)
6060

6161
case .onTapFullSheet:
62-
navigator.fullSheet(paths: ["page1", "page2"], items: [:], isAnimated: true)
62+
navigator.fullSheet(paths: ["page1", "page2"], items: [:], isAnimated: true, prefersLargeTitles: true)
6363
}
6464
}
6565
}

Examples/MVI-Example/MVI-Example/Feature/Home/HomeView.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ extension HomeView: View {
1414
var body: some View {
1515
ScrollView {
1616
VStack(spacing: 40) {
17-
Text("Home")
18-
.font(.system(size: 60, weight: .thin))
19-
2017
NavigationStackViewer(paths: state.paths)
2118

2219
Button(action: { intent.send(action: .onTapNext) }) {
@@ -65,6 +62,7 @@ extension HomeView: View {
6562
Spacer()
6663
}
6764
.padding(.horizontal)
65+
.navigationBarTitleDisplayMode(.large)
6866
.navigationTitle("Home")
6967
.onAppear {
7068
intent.send(action: .getPaths)

Examples/TCA-Example/TCA-Example/AppMain.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extension AppMain: App {
2323
var body: some Scene {
2424
WindowGroup {
2525
navigator
26-
.launch(paths: ["home"], items: [:])
26+
.launch(paths: ["home"], items: [:], prefersLargeTitles: false)
2727
.onOpenURL { url in
2828
print(url.absoluteString)
2929
// !!!: tca-ex://host/home/page1/page2/page3/page4?page3-message=hello&page4-message=%ED%95%9C%EA%B8%80

Examples/TCA-Example/TCA-Example/Feature/Home/HomeSideEffect.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ extension HomeSideEffectLive: HomeSideEffect {
5757

5858
public var routeToFullSheet: () -> Void {
5959
{
60-
navigator.fullSheet(paths: ["page1", "page2"], items: [:], isAnimated: true)
60+
navigator.fullSheet(paths: ["page1", "page2"], items: [:], isAnimated: true, prefersLargeTitles: true)
6161
}
6262
}
6363
}

Sources/LinkNavigator/Core/LinkNavigator.swift

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ public protocol LinkNavigatorType {
100100
/// - paths: An array of ``RouteBuilder/matchPath`` for some specific pages.
101101
/// - items: A dictionary of `String` type key-value pairs.
102102
/// - isAnimated: makes the transition to be animated.
103-
func fullSheet(paths: [String], items: [String: String], isAnimated: Bool)
103+
/// - prefersLargeTitles:
104+
/// The SubNavigationViewController has a Boolean value that determines whether to display the title in a large format.
105+
/// ``If the value is null or .none, the previously set value will be maintained.``
106+
/// You can set it to true to use a large title in the modal or control it dynamically.
107+
///
108+
func fullSheet(paths: [String], items: [String: String], isAnimated: Bool, prefersLargeTitles: Bool?)
104109

105110
/// Presents a custom sheet that has its own navigation stack.
106111
///
@@ -112,7 +117,8 @@ public protocol LinkNavigatorType {
112117
/// items: [:],
113118
/// isAnimated: true,
114119
/// iPhonePresentationStyle: .fullScreen,
115-
/// iPadPresentationStyle: .automatic)
120+
/// iPadPresentationStyle: .automatic,
121+
/// prefersLargeTitles: .none)
116122
/// ```
117123
///
118124
/// - Note: If there's an active modal in `rootNavigationController`, then
@@ -123,12 +129,17 @@ public protocol LinkNavigatorType {
123129
/// - paths: An array of ``RouteBuilder/matchPath`` for some specific pages.
124130
/// - items: A dictionary of `String` type key-value pairs.
125131
/// - isAnimated: makes the transition to be animated.
132+
/// - prefersLargeTitles:
133+
/// The SubNavigationViewController has a Boolean value that determines whether to display the title in a large format.
134+
/// ``If the value is null or .none, the previously set value will be maintained.``
135+
/// You can set it to true to use a large title in the modal or control it dynamically.
126136
func customSheet(
127137
paths: [String],
128138
items: [String: String],
129139
isAnimated: Bool,
130140
iPhonePresentationStyle: UIModalPresentationStyle,
131-
iPadPresentationStyle: UIModalPresentationStyle)
141+
iPadPresentationStyle: UIModalPresentationStyle,
142+
prefersLargeTitles: Bool?)
132143

133144
/// Replaces current navigation stack managed by `rootNavigationController` with the new one.
134145
///
@@ -390,11 +401,13 @@ public enum NavigationTarget {
390401
}
391402

392403
extension LinkNavigator {
393-
public func launch(paths: [String], items: [String: String]) -> RootNavigator {
404+
405+
public func launch(paths: [String], items: [String: String], prefersLargeTitles: Bool = false) -> RootNavigator {
394406
let viewControllers = paths.compactMap { path in
395407
builders.first(where: { $0.matchPath == path })?.build(self, items, dependency)
396408
}
397409
rootNavigationController.setViewControllers(viewControllers, animated: false)
410+
rootNavigationController.navigationBar.prefersLargeTitles = prefersLargeTitles
398411

399412
return RootNavigator(viewController: rootNavigationController)
400413
}
@@ -443,13 +456,18 @@ extension LinkNavigator: LinkNavigatorType {
443456
rootNavigationController.present(subNavigationController, animated: isAnimated)
444457
}
445458

446-
public func fullSheet(paths: [String], items: [String: String], isAnimated: Bool) {
459+
public func fullSheet(paths: [String], items: [String: String], isAnimated: Bool, prefersLargeTitles: Bool?) {
447460
rootNavigationController.dismiss(animated: true)
448461

449462
subNavigationController.modalPresentationStyle = .fullScreen
450463
let new = paths.compactMap { path in
451464
builders.first(where: { $0.matchPath == path })?.build(self, items, dependency)
452465
}
466+
467+
if let prefersLargeTitles {
468+
subNavigationController.navigationBar.prefersLargeTitles = prefersLargeTitles
469+
}
470+
453471
subNavigationController.setViewControllers(new, animated: false)
454472
rootNavigationController.present(subNavigationController, animated: isAnimated)
455473
}
@@ -459,7 +477,8 @@ extension LinkNavigator: LinkNavigatorType {
459477
items: [String: String],
460478
isAnimated: Bool,
461479
iPhonePresentationStyle: UIModalPresentationStyle,
462-
iPadPresentationStyle: UIModalPresentationStyle)
480+
iPadPresentationStyle: UIModalPresentationStyle,
481+
prefersLargeTitles: Bool?)
463482
{
464483
rootNavigationController.dismiss(animated: true)
465484

@@ -470,6 +489,11 @@ extension LinkNavigator: LinkNavigatorType {
470489
let new = paths.compactMap { path in
471490
builders.first(where: { $0.matchPath == path })?.build(self, items, dependency)
472491
}
492+
493+
if let prefersLargeTitles {
494+
subNavigationController.navigationBar.prefersLargeTitles = prefersLargeTitles
495+
}
496+
473497
subNavigationController.setViewControllers(new, animated: false)
474498
rootNavigationController.present(subNavigationController, animated: isAnimated)
475499
}

0 commit comments

Comments
 (0)