Skip to content

Commit 918a1d4

Browse files
committed
refactor: Added Alert function in TabLinkNavigator and changed Protocol
The 'alert' function that was previously in TabPartialNavigator has been added to TabLinkNavigator as well, and related examples have been included.
1 parent 87bad03 commit 918a1d4

4 files changed

Lines changed: 22 additions & 6 deletions

File tree

Examples/TabNavigator/03-TabEventSubscriber/TabEventSubscriber/Pages/Common/Step1/Step1Page.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ struct Step1Page: View {
2020
Text("Close Sheet")
2121
}
2222

23+
Button(action: {
24+
navigator.alert(model: .init(
25+
title: "Test Title",
26+
message: "Message",
27+
buttons: [
28+
.init(
29+
title: "OK",
30+
style: .default)
31+
],
32+
flagType: .default))
33+
}) {
34+
Text("Show Alert")
35+
}
36+
2337
Spacer()
2438
}
2539
.onAppear {

Sources/LinkNavigator/Core/Core/TabLinkNavigator/TabLinkNavigator.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ extension TabLinkNavigator {
161161
NotificationCenter.default
162162
.post(name: TabbarEventNotification.onSelectedTab, object: targetPath)
163163
}
164+
165+
public func alert(model: Alert) {
166+
let currentController = modalController ?? fullSheetController ?? mainController?.selectedViewController
167+
currentController?.present(model.build(), animated: true)
168+
}
164169
}
165170

166171
extension UINavigationController {

Sources/LinkNavigator/Core/Core/TabLinkNavigator/TabPartialNavigator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ extension TabPartialNavigator: TabLinkNavigatorProtocol {
259259
currentTabNavigationController.setViewControllers(reloadedVC, animated: isAnimated)
260260
}
261261

262-
public func alert(target _: NavigationTarget, model: Alert) {
263-
currentController?.present(model.build(), animated: true)
262+
public func alert(model: Alert) {
263+
rootNavigator?.alert(model: model)
264264
}
265265

266266
public func send(targetTabPath: String?, linkItem: LinkItem) {

Sources/LinkNavigator/Core/Protocol/TabLinkNavigatorProtocol.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,8 @@ public protocol TabLinkNavigatorProtocol {
130130
/// the alert is displayed either on the root or the sub-controller.
131131
///
132132
/// - Parameters:
133-
/// - target: The target specifying where to display the alert. It can be root, sub, or default.
134-
/// If the target is default, it determines whether to present the alert on sub or root based
135-
/// on the `isSubNavigatorActive` property.
136133
/// - model: The model containing information for building and displaying the alert.
137-
func alert(target: NavigationTarget, model: Alert)
134+
func alert(model: Alert)
138135

139136
/// Sends the specified link item to a specific subscriber ('sub') or page sheet within the current navigation stack.
140137
/// This method facilitates communication between pages, allowing data to be transferred to a specific 'sub' or page sheet as defined in the link item.

0 commit comments

Comments
 (0)