1use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-foundation")]
7use objc2_core_foundation::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12#[repr(transparent)]
25#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
26pub struct UINavigationControllerOperation(pub NSInteger);
27impl UINavigationControllerOperation {
28    #[doc(alias = "UINavigationControllerOperationNone")]
29    pub const None: Self = Self(0);
30    #[doc(alias = "UINavigationControllerOperationPush")]
31    pub const Push: Self = Self(1);
32    #[doc(alias = "UINavigationControllerOperationPop")]
33    pub const Pop: Self = Self(2);
34}
35
36unsafe impl Encode for UINavigationControllerOperation {
37    const ENCODING: Encoding = NSInteger::ENCODING;
38}
39
40unsafe impl RefEncode for UINavigationControllerOperation {
41    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
42}
43
44extern "C" {
45    #[cfg(feature = "objc2-core-foundation")]
47    pub static UINavigationControllerHideShowBarDuration: CGFloat;
48}
49
50extern_class!(
51    #[unsafe(super(UIViewController, UIResponder, NSObject))]
53    #[thread_kind = MainThreadOnly]
54    #[derive(Debug, PartialEq, Eq, Hash)]
55    #[cfg(all(feature = "UIResponder", feature = "UIViewController"))]
56    pub struct UINavigationController;
57);
58
59#[cfg(all(feature = "UIResponder", feature = "UIViewController"))]
60extern_conformance!(
61    unsafe impl NSCoding for UINavigationController {}
62);
63
64#[cfg(all(feature = "UIResponder", feature = "UIViewController"))]
65extern_conformance!(
66    unsafe impl NSObjectProtocol for UINavigationController {}
67);
68
69#[cfg(all(
70    feature = "UIAppearance",
71    feature = "UIResponder",
72    feature = "UIViewController"
73))]
74extern_conformance!(
75    unsafe impl UIAppearanceContainer for UINavigationController {}
76);
77
78#[cfg(all(feature = "UIResponder", feature = "UIViewController"))]
79extern_conformance!(
80    unsafe impl UIContentContainer for UINavigationController {}
81);
82
83#[cfg(all(
84    feature = "UIFocus",
85    feature = "UIResponder",
86    feature = "UIViewController"
87))]
88extern_conformance!(
89    unsafe impl UIFocusEnvironment for UINavigationController {}
90);
91
92#[cfg(all(feature = "UIResponder", feature = "UIViewController"))]
93extern_conformance!(
94    unsafe impl UIResponderStandardEditActions for UINavigationController {}
95);
96
97#[cfg(all(
98    feature = "UIResponder",
99    feature = "UITraitCollection",
100    feature = "UIViewController"
101))]
102extern_conformance!(
103    unsafe impl UITraitEnvironment for UINavigationController {}
104);
105
106#[cfg(all(feature = "UIResponder", feature = "UIViewController"))]
107impl UINavigationController {
108    extern_methods!(
109        #[unsafe(method(initWithNavigationBarClass:toolbarClass:))]
114        #[unsafe(method_family = init)]
115        pub unsafe fn initWithNavigationBarClass_toolbarClass(
116            this: Allocated<Self>,
117            navigation_bar_class: Option<&AnyClass>,
118            toolbar_class: Option<&AnyClass>,
119        ) -> Retained<Self>;
120
121        #[unsafe(method(initWithRootViewController:))]
122        #[unsafe(method_family = init)]
123        pub fn initWithRootViewController(
124            this: Allocated<Self>,
125            root_view_controller: &UIViewController,
126        ) -> Retained<Self>;
127
128        #[unsafe(method(initWithNibName:bundle:))]
129        #[unsafe(method_family = init)]
130        pub fn initWithNibName_bundle(
131            this: Allocated<Self>,
132            nib_name_or_nil: Option<&NSString>,
133            nib_bundle_or_nil: Option<&NSBundle>,
134        ) -> Retained<Self>;
135
136        #[unsafe(method(initWithCoder:))]
140        #[unsafe(method_family = init)]
141        pub unsafe fn initWithCoder(
142            this: Allocated<Self>,
143            a_decoder: &NSCoder,
144        ) -> Option<Retained<Self>>;
145
146        #[unsafe(method(pushViewController:animated:))]
147        #[unsafe(method_family = none)]
148        pub fn pushViewController_animated(
149            &self,
150            view_controller: &UIViewController,
151            animated: bool,
152        );
153
154        #[unsafe(method(popViewControllerAnimated:))]
155        #[unsafe(method_family = none)]
156        pub fn popViewControllerAnimated(
157            &self,
158            animated: bool,
159        ) -> Option<Retained<UIViewController>>;
160
161        #[unsafe(method(popToViewController:animated:))]
162        #[unsafe(method_family = none)]
163        pub fn popToViewController_animated(
164            &self,
165            view_controller: &UIViewController,
166            animated: bool,
167        ) -> Option<Retained<NSArray<UIViewController>>>;
168
169        #[unsafe(method(popToRootViewControllerAnimated:))]
170        #[unsafe(method_family = none)]
171        pub fn popToRootViewControllerAnimated(
172            &self,
173            animated: bool,
174        ) -> Option<Retained<NSArray<UIViewController>>>;
175
176        #[unsafe(method(topViewController))]
177        #[unsafe(method_family = none)]
178        pub fn topViewController(&self) -> Option<Retained<UIViewController>>;
179
180        #[unsafe(method(visibleViewController))]
181        #[unsafe(method_family = none)]
182        pub fn visibleViewController(&self) -> Option<Retained<UIViewController>>;
183
184        #[unsafe(method(viewControllers))]
185        #[unsafe(method_family = none)]
186        pub fn viewControllers(&self) -> Retained<NSArray<UIViewController>>;
187
188        #[unsafe(method(setViewControllers:))]
192        #[unsafe(method_family = none)]
193        pub fn setViewControllers(&self, view_controllers: &NSArray<UIViewController>);
194
195        #[unsafe(method(setViewControllers:animated:))]
196        #[unsafe(method_family = none)]
197        pub fn setViewControllers_animated(
198            &self,
199            view_controllers: &NSArray<UIViewController>,
200            animated: bool,
201        );
202
203        #[unsafe(method(isNavigationBarHidden))]
204        #[unsafe(method_family = none)]
205        pub fn isNavigationBarHidden(&self) -> bool;
206
207        #[unsafe(method(setNavigationBarHidden:))]
209        #[unsafe(method_family = none)]
210        pub fn setNavigationBarHidden(&self, navigation_bar_hidden: bool);
211
212        #[unsafe(method(setNavigationBarHidden:animated:))]
213        #[unsafe(method_family = none)]
214        pub fn setNavigationBarHidden_animated(&self, hidden: bool, animated: bool);
215
216        #[cfg(all(feature = "UINavigationBar", feature = "UIView"))]
217        #[unsafe(method(navigationBar))]
218        #[unsafe(method_family = none)]
219        pub fn navigationBar(&self) -> Retained<UINavigationBar>;
220
221        #[unsafe(method(isToolbarHidden))]
222        #[unsafe(method_family = none)]
223        pub fn isToolbarHidden(&self) -> bool;
224
225        #[unsafe(method(setToolbarHidden:))]
227        #[unsafe(method_family = none)]
228        pub fn setToolbarHidden(&self, toolbar_hidden: bool);
229
230        #[unsafe(method(setToolbarHidden:animated:))]
231        #[unsafe(method_family = none)]
232        pub fn setToolbarHidden_animated(&self, hidden: bool, animated: bool);
233
234        #[cfg(all(feature = "UIToolbar", feature = "UIView"))]
235        #[unsafe(method(toolbar))]
236        #[unsafe(method_family = none)]
237        pub fn toolbar(&self) -> Option<Retained<UIToolbar>>;
238
239        #[unsafe(method(delegate))]
240        #[unsafe(method_family = none)]
241        pub fn delegate(
242            &self,
243        ) -> Option<Retained<ProtocolObject<dyn UINavigationControllerDelegate>>>;
244
245        #[unsafe(method(setDelegate:))]
249        #[unsafe(method_family = none)]
250        pub unsafe fn setDelegate(
251            &self,
252            delegate: Option<&ProtocolObject<dyn UINavigationControllerDelegate>>,
253        );
254
255        #[cfg(feature = "UIGestureRecognizer")]
256        #[unsafe(method(interactivePopGestureRecognizer))]
259        #[unsafe(method_family = none)]
260        pub fn interactivePopGestureRecognizer(&self) -> Option<Retained<UIGestureRecognizer>>;
261
262        #[cfg(feature = "UIGestureRecognizer")]
263        #[unsafe(method(interactiveContentPopGestureRecognizer))]
267        #[unsafe(method_family = none)]
268        pub fn interactiveContentPopGestureRecognizer(
269            &self,
270        ) -> Option<Retained<UIGestureRecognizer>>;
271
272        #[unsafe(method(showViewController:sender:))]
276        #[unsafe(method_family = none)]
277        pub unsafe fn showViewController_sender(
278            &self,
279            vc: &UIViewController,
280            sender: Option<&AnyObject>,
281        );
282
283        #[unsafe(method(hidesBarsWhenKeyboardAppears))]
285        #[unsafe(method_family = none)]
286        pub fn hidesBarsWhenKeyboardAppears(&self) -> bool;
287
288        #[unsafe(method(setHidesBarsWhenKeyboardAppears:))]
290        #[unsafe(method_family = none)]
291        pub fn setHidesBarsWhenKeyboardAppears(&self, hides_bars_when_keyboard_appears: bool);
292
293        #[unsafe(method(hidesBarsOnSwipe))]
297        #[unsafe(method_family = none)]
298        pub fn hidesBarsOnSwipe(&self) -> bool;
299
300        #[unsafe(method(setHidesBarsOnSwipe:))]
302        #[unsafe(method_family = none)]
303        pub fn setHidesBarsOnSwipe(&self, hides_bars_on_swipe: bool);
304
305        #[cfg(all(feature = "UIGestureRecognizer", feature = "UIPanGestureRecognizer"))]
306        #[unsafe(method(barHideOnSwipeGestureRecognizer))]
308        #[unsafe(method_family = none)]
309        pub fn barHideOnSwipeGestureRecognizer(&self) -> Retained<UIPanGestureRecognizer>;
310
311        #[unsafe(method(hidesBarsWhenVerticallyCompact))]
313        #[unsafe(method_family = none)]
314        pub fn hidesBarsWhenVerticallyCompact(&self) -> bool;
315
316        #[unsafe(method(setHidesBarsWhenVerticallyCompact:))]
318        #[unsafe(method_family = none)]
319        pub fn setHidesBarsWhenVerticallyCompact(&self, hides_bars_when_vertically_compact: bool);
320
321        #[unsafe(method(hidesBarsOnTap))]
325        #[unsafe(method_family = none)]
326        pub fn hidesBarsOnTap(&self) -> bool;
327
328        #[unsafe(method(setHidesBarsOnTap:))]
330        #[unsafe(method_family = none)]
331        pub fn setHidesBarsOnTap(&self, hides_bars_on_tap: bool);
332
333        #[cfg(all(feature = "UIGestureRecognizer", feature = "UITapGestureRecognizer"))]
334        #[unsafe(method(barHideOnTapGestureRecognizer))]
340        #[unsafe(method_family = none)]
341        pub unsafe fn barHideOnTapGestureRecognizer(&self) -> Retained<UITapGestureRecognizer>;
342    );
343}
344
345#[cfg(all(feature = "UIResponder", feature = "UIViewController"))]
347impl UINavigationController {
348    extern_methods!(
349        #[unsafe(method(init))]
350        #[unsafe(method_family = init)]
351        pub fn init(this: Allocated<Self>) -> Retained<Self>;
352
353        #[unsafe(method(new))]
354        #[unsafe(method_family = new)]
355        pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
356    );
357}
358
359extern_protocol!(
360    pub unsafe trait UINavigationControllerDelegate:
362        NSObjectProtocol + MainThreadOnly
363    {
364        #[cfg(all(feature = "UIResponder", feature = "UIViewController"))]
365        #[optional]
366        #[unsafe(method(navigationController:willShowViewController:animated:))]
367        #[unsafe(method_family = none)]
368        fn navigationController_willShowViewController_animated(
369            &self,
370            navigation_controller: &UINavigationController,
371            view_controller: &UIViewController,
372            animated: bool,
373        );
374
375        #[cfg(all(feature = "UIResponder", feature = "UIViewController"))]
376        #[optional]
377        #[unsafe(method(navigationController:didShowViewController:animated:))]
378        #[unsafe(method_family = none)]
379        fn navigationController_didShowViewController_animated(
380            &self,
381            navigation_controller: &UINavigationController,
382            view_controller: &UIViewController,
383            animated: bool,
384        );
385
386        #[cfg(all(
387            feature = "UIOrientation",
388            feature = "UIResponder",
389            feature = "UIViewController"
390        ))]
391        #[optional]
392        #[unsafe(method(navigationControllerSupportedInterfaceOrientations:))]
393        #[unsafe(method_family = none)]
394        fn navigationControllerSupportedInterfaceOrientations(
395            &self,
396            navigation_controller: &UINavigationController,
397        ) -> UIInterfaceOrientationMask;
398
399        #[cfg(all(
400            feature = "UIOrientation",
401            feature = "UIResponder",
402            feature = "UIViewController"
403        ))]
404        #[optional]
405        #[unsafe(method(navigationControllerPreferredInterfaceOrientationForPresentation:))]
406        #[unsafe(method_family = none)]
407        fn navigationControllerPreferredInterfaceOrientationForPresentation(
408            &self,
409            navigation_controller: &UINavigationController,
410        ) -> UIInterfaceOrientation;
411
412        #[cfg(all(
413            feature = "UIResponder",
414            feature = "UIViewController",
415            feature = "UIViewControllerTransitioning"
416        ))]
417        #[optional]
418        #[unsafe(method(navigationController:interactionControllerForAnimationController:))]
419        #[unsafe(method_family = none)]
420        fn navigationController_interactionControllerForAnimationController(
421            &self,
422            navigation_controller: &UINavigationController,
423            animation_controller: &ProtocolObject<dyn UIViewControllerAnimatedTransitioning>,
424        ) -> Option<Retained<ProtocolObject<dyn UIViewControllerInteractiveTransitioning>>>;
425
426        #[cfg(all(
427            feature = "UIResponder",
428            feature = "UIViewController",
429            feature = "UIViewControllerTransitioning"
430        ))]
431        #[optional]
432        #[unsafe(method(navigationController:animationControllerForOperation:fromViewController:toViewController:))]
433        #[unsafe(method_family = none)]
434        fn navigationController_animationControllerForOperation_fromViewController_toViewController(
435            &self,
436            navigation_controller: &UINavigationController,
437            operation: UINavigationControllerOperation,
438            from_vc: &UIViewController,
439            to_vc: &UIViewController,
440        ) -> Option<Retained<ProtocolObject<dyn UIViewControllerAnimatedTransitioning>>>;
441    }
442);
443
444#[cfg(all(feature = "UIResponder", feature = "UIViewController"))]
446impl UIViewController {
447    extern_methods!(
448        #[cfg(feature = "UINavigationItem")]
449        #[unsafe(method(navigationItem))]
450        #[unsafe(method_family = none)]
451        pub fn navigationItem(&self) -> Retained<UINavigationItem>;
452
453        #[unsafe(method(hidesBottomBarWhenPushed))]
454        #[unsafe(method_family = none)]
455        pub fn hidesBottomBarWhenPushed(&self) -> bool;
456
457        #[unsafe(method(setHidesBottomBarWhenPushed:))]
459        #[unsafe(method_family = none)]
460        pub fn setHidesBottomBarWhenPushed(&self, hides_bottom_bar_when_pushed: bool);
461
462        #[unsafe(method(navigationController))]
463        #[unsafe(method_family = none)]
464        pub fn navigationController(&self) -> Option<Retained<UINavigationController>>;
465    );
466}
467
468#[cfg(all(feature = "UIResponder", feature = "UIViewController"))]
470impl UIViewController {
471    extern_methods!(
472        #[cfg(all(feature = "UIBarButtonItem", feature = "UIBarItem"))]
473        #[unsafe(method(toolbarItems))]
474        #[unsafe(method_family = none)]
475        pub fn toolbarItems(&self) -> Option<Retained<NSArray<UIBarButtonItem>>>;
476
477        #[cfg(all(feature = "UIBarButtonItem", feature = "UIBarItem"))]
478        #[unsafe(method(setToolbarItems:))]
480        #[unsafe(method_family = none)]
481        pub fn setToolbarItems(&self, toolbar_items: Option<&NSArray<UIBarButtonItem>>);
482
483        #[cfg(all(feature = "UIBarButtonItem", feature = "UIBarItem"))]
484        #[unsafe(method(setToolbarItems:animated:))]
485        #[unsafe(method_family = none)]
486        pub fn setToolbarItems_animated(
487            &self,
488            toolbar_items: Option<&NSArray<UIBarButtonItem>>,
489            animated: bool,
490        );
491    );
492}