]> git.saurik.com Git - cydia.git/blob - CyteKit/TabBarController.mm
7a4ead30b30fa1c41b124bbc1e9b5c2320a22f99
[cydia.git] / CyteKit / TabBarController.mm
1 /* Cydia - iPhone UIKit Front-End for Debian APT
2 * Copyright (C) 2008-2015 Jay Freeman (saurik)
3 */
4
5 /* GNU General Public License, Version 3 {{{ */
6 /*
7 * Cydia is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 3 of the License,
10 * or (at your option) any later version.
11 *
12 * Cydia is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Cydia. If not, see <http://www.gnu.org/licenses/>.
19 **/
20 /* }}} */
21
22 #include "CyteKit/UCPlatform.h"
23
24 #include "CyteKit/TabBarController.h"
25
26 #include "iPhonePrivate.h"
27 #include <Menes/ObjectHandle.h>
28
29 @implementation UITabBarController (Cydia)
30
31 @end
32
33 @implementation CyteTabBarController {
34 _transient UIViewController *transient_;
35 _H<UIViewController> remembered_;
36 }
37
38 - (void) didReceiveMemoryWarning {
39 [super didReceiveMemoryWarning];
40
41 // presenting a UINavigationController on 2.x does not update its transitionView
42 // it thereby will not allow its topViewController to be unloaded by memory pressure
43 if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
44 UIViewController *selected([self selectedViewController]);
45 for (UINavigationController *controller in [self viewControllers])
46 if (controller != selected)
47 if (UIViewController *top = [controller topViewController])
48 [top unloadView];
49 }
50 }
51
52 - (void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
53 if ([self unselectedViewController])
54 [self setUnselectedViewController:nil];
55
56 // presenting a UINavigationController on 2.x does not update its transitionView
57 // if this view was unloaded, the tranitionView may currently be presenting nothing
58 if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
59 UINavigationController *navigation((UINavigationController *) viewController);
60 [navigation pushViewController:[[[UIViewController alloc] init] autorelease] animated:NO];
61 [navigation popViewControllerAnimated:NO];
62 }
63 }
64
65 - (void) dismissModalViewControllerAnimated:(BOOL)animated {
66 if ([self modalViewController] == nil && [self unselectedViewController] != nil)
67 [self setUnselectedViewController:nil];
68 else
69 [super dismissModalViewControllerAnimated:YES];
70 }
71
72 - (void) setUnselectedViewController:(UIViewController *)transient {
73 if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
74 if (transient != nil) {
75 [[[self viewControllers] objectAtIndex:0] pushViewController:transient animated:YES];
76 [self setSelectedIndex:0];
77 } return;
78 }
79
80 NSMutableArray *controllers = [[[self viewControllers] mutableCopy] autorelease];
81 if (transient != nil) {
82 UINavigationController *navigation([[[UINavigationController alloc] init] autorelease]);
83 [navigation setViewControllers:[NSArray arrayWithObject:transient]];
84 transient = navigation;
85
86 if (transient_ == nil)
87 remembered_ = [controllers objectAtIndex:0];
88 transient_ = transient;
89 [transient_ setTabBarItem:[remembered_ tabBarItem]];
90 [controllers replaceObjectAtIndex:0 withObject:transient_];
91 [self setSelectedIndex:0];
92 [self setViewControllers:controllers];
93 [self concealTabBarSelection];
94 } else if (remembered_ != nil) {
95 [remembered_ setTabBarItem:[transient_ tabBarItem]];
96 transient_ = transient;
97 [controllers replaceObjectAtIndex:0 withObject:remembered_];
98 remembered_ = nil;
99 [self setViewControllers:controllers];
100 [self revealTabBarSelection];
101 }
102 }
103
104 - (UIViewController *) unselectedViewController {
105 return transient_;
106 }
107
108 - (void) unloadData {
109 [super unloadData];
110
111 for (UINavigationController *controller in [self viewControllers])
112 [controller unloadData];
113
114 if (UIViewController *selected = [self selectedViewController])
115 [selected reloadData];
116
117 if (UIViewController *unselected = [self unselectedViewController]) {
118 [unselected unloadData];
119 [unselected reloadData];
120 }
121 }
122
123 #include "InterfaceOrientation.h"
124
125 @end