@@ -87,115 +87,19 @@ public extension NXNavigationRouter {
8787@available ( iOS 14 . 0 , macOS 11 . 0 , tvOS 14 . 0 , watchOS 7 . 0 , * )
8888public extension View {
8989
90- /// 通过 View 添加 `NXNavigationBar` 的包装对象,提供当前导航栏的外观的便利。
91- /// - Parameter context: 当前对象的 NXNavigationRouter.Context 实例对象
92- /// - Returns: 返回高度为 0,宽度为 0,并且是隐藏的 View
93- ///
94- /// import SwiftUI
95- /// import NXNavigationExtension
96- ///
97- /// struct ContentView: View {
98- /// @State private var context: NXNavigationRouter.Context
99- ///
100- /// init() {
101- /// context = NXNavigationRouter.Context(routeName: "/index")
102- /// }
103- ///
104- /// var body: some View {
105- /// NavigationView {
106- /// NavigationLink {
107- /// Button {
108- /// NXNavigationRouter.of(context).pop()
109- /// } label: {
110- /// Text("Pop")
111- /// }
112- /// } label: {
113- /// Text("NXNavigationExtension")
114- /// .padding()
115- /// .useNXNavigationView(context: $context)
116- /// }
117- /// }
118- /// }
119- /// }
120- func useNXNavigationView( context: Binding < NXNavigationRouter . Context > ) -> some View {
121- useNXNavigationView ( context: context, onPrepareConfiguration: nil , onBackHandler: nil )
122- }
123-
124- /// 通过 View 添加 `NXNavigationBar` 的包装对象,提供当前导航栏的外观的便利。
125- /// - Parameter onPrepareConfiguration: 即将应用配置到当前视图控制器的回调,执行 `setNeedsNavigationBarAppearanceUpdate` 方法时也会触发此回调。
126- /// - Returns: 返回高度为 0,宽度为 0,并且是隐藏的 View
127- ///
128- /// import SwiftUI
129- /// import NXNavigationExtension
130- ///
131- /// struct ContentView: View {
132- /// var body: some View {
133- /// NavigationView {
134- /// NavigationLink {
135- /// Text("Destination")
136- /// .padding()
137- /// } label: {
138- /// Text("NXNavigationExtension")
139- /// .padding()
140- /// .useNXNavigationView { configuration in
141- /// configuration.navigationBarAppearance.backgroundColor = .blue
142- /// }
143- /// }
144- /// }
145- /// }
146- /// }
147- func useNXNavigationView( onPrepareConfiguration: @escaping ( NXNavigationConfiguration ) -> Void ) -> some View {
148- useNXNavigationView ( context: . constant( NXNavigationRouter . Context ( routeName: " " ) ) , onPrepareConfiguration: onPrepareConfiguration, onBackHandler: nil )
149- }
150-
151- /// 通过 View 添加 `NXNavigationBar` 的包装对象,提供当前导航栏的外观的便利。
152- /// - Parameter onBackHandler: 使用手势滑动返回或点击系统返回按钮过程中可以拦截或中断返回继而执行其他操作
153- /// 执行 `NXNavigationRouter.of(context).nx.\pop()\popToRoot()\popUntil("routeName")\popToFirstUntil("routeName")\popToLastUntil("routeName")` 等方法后也会触发这个代理回调
154- /// - Returns: 返回高度为 0,宽度为 0,并且是隐藏的 View
155- ///
156- /// import SwiftUI
157- /// import NXNavigationExtension
158- ///
159- /// struct ContentView: View {
160- /// var body: some View {
161- /// NavigationView {
162- /// NavigationLink {
163- /// Text("Destination")
164- /// .padding()
165- /// } label: {
166- /// Text("NXNavigationExtension")
167- /// .padding()
168- /// .useNXNavigationView(onBackHandler: { action in
169- /// switch action {
170- /// case .clickBackButton, .clickBackButtonMenu, .callingNXPopMethod, .interactionGesture:
171- /// /// Do something...
172- /// return false
173- /// default:
174- /// /// Do an other something...
175- /// return true
176- /// }
177- /// })
178- /// }
179- /// }
180- /// }
181- /// }
182- func useNXNavigationView( onBackHandler: @escaping ( NXNavigationBackAction ) -> Bool ) -> some View {
183- useNXNavigationView ( context: . constant( NXNavigationRouter . Context ( routeName: " " ) ) , onPrepareConfiguration: nil , onBackHandler: onBackHandler)
184- }
185-
18690 /// 通过 View 添加 `NXNavigationBar` 的包装对象,提供当前导航栏的外观的便利。
18791 /// - Parameters:
18892 /// - context: 当前对象的 NXNavigationRouter.Context 实例对象
18993 /// - onPrepareConfiguration: 即将应用配置到当前视图控制器的回调,执行 `setNeedsNavigationBarAppearanceUpdate` 方法时也会触发此回调。
190- /// - onBackHandler : 使用手势滑动返回或点击系统返回按钮过程中可以拦截或中断返回继而执行其他操作
94+ /// - onBackActionHandler : 使用手势滑动返回或点击系统返回按钮过程中可以拦截或中断返回继而执行其他操作
19195 /// 执行 `NXNavigationRouter.of(context).nx.\pop()\popToRoot()\popUntil("routeName")\popToFirstUntil("routeName")\popToLastUntil("routeName")` 等方法后也会触发这个代理回调
19296 /// - Returns: 返回高度为 0,宽度为 0,并且是隐藏的 View
19397 func useNXNavigationView( context: Binding < NXNavigationRouter . Context > ,
19498 onPrepareConfiguration: ( ( NXNavigationConfiguration ) -> Void ) ? = nil ,
195- onBackHandler : ( ( NXNavigationBackAction ) -> Bool ) ? = nil ) -> some View {
99+ onBackActionHandler : ( ( NXNavigationBackAction ) -> Bool ) ? = nil ) -> some View {
196100 let view = NXNavigationWrapperView ( context: context,
197101 onPrepareConfiguration: onPrepareConfiguration,
198- onBackHandler : onBackHandler )
102+ onBackActionHandler : onBackActionHandler )
199103 . frame ( width: 0 , height: 0 )
200104
201105 return ZStack {
@@ -207,6 +111,18 @@ public extension View {
207111 }
208112 }
209113
114+ /// 通过 View 添加 `NXNavigationBar` 的包装对象,提供当前导航栏的外观的便利。
115+ /// - Parameters:
116+ /// - onPrepareConfiguration: 即将应用配置到当前视图控制器的回调,执行 `setNeedsNavigationBarAppearanceUpdate` 方法时也会触发此回调。
117+ /// - onBackActionHandler: 使用手势滑动返回或点击系统返回按钮过程中可以拦截或中断返回继而执行其他操作
118+ /// - Returns: 返回高度为 0,宽度为 0,并且是隐藏的 View
119+ func useNXNavigationView( onPrepareConfiguration: ( ( NXNavigationConfiguration ) -> Void ) ? = nil ,
120+ onBackActionHandler: ( ( NXNavigationBackAction ) -> Bool ) ? = nil ) -> some View {
121+ useNXNavigationView ( context: . constant( NXNavigationRouter . Context ( routeName: " " ) ) ,
122+ onPrepareConfiguration: onPrepareConfiguration,
123+ onBackActionHandler: onBackActionHandler)
124+ }
125+
210126}
211127
212128#endif
0 commit comments