|
8 | 8 |
|
9 | 9 | #import "TiUIOptionDialogProxy.h" |
10 | 10 | #import "TiToolbarButton.h" |
| 11 | +#import "TiUIButtonProxy.h" |
11 | 12 | #import <TitaniumKit/TiApp.h> |
12 | 13 | #import <TitaniumKit/TiTab.h> |
13 | 14 | #import <TitaniumKit/TiToolbar.h> |
@@ -67,9 +68,7 @@ - (void)show:(id)args |
67 | 68 | animated = [TiUtils boolValue:@"animated" properties:args def:YES]; |
68 | 69 | id obj = [args objectForKey:@"rect"]; |
69 | 70 | if (obj != nil) { |
70 | | - dialogRect = [TiUtils rectValue:obj]; |
71 | | - } else { |
72 | | - dialogRect = CGRectZero; |
| 71 | + DEPRECATED_REMOVED(@"UI.OptionDialog", @"13.0.0", @"13.0.0"); |
73 | 72 | } |
74 | 73 |
|
75 | 74 | RELEASE_TO_NIL(alertController); |
@@ -110,23 +109,18 @@ - (void)show:(id)args |
110 | 109 | if ([TiUtils isIPad]) { |
111 | 110 | UIViewController *topVC = [[[TiApp app] controller] topPresentedController]; |
112 | 111 | isPopover = ((topVC.modalPresentationStyle == UIModalPresentationPopover) && (![topVC isKindOfClass:[UIAlertController class]])); |
113 | | - /** |
114 | | - ** This block commented out since it seems to have no effect on the alert controller. |
115 | | - ** If you read the modalPresentationStyle after setting the value, it still shows UIModalPresentationPopover |
116 | | - ** However not configuring the UIPopoverPresentationController seems to do the trick. |
117 | | - ** This hack in place to conserve current behavior. Should revisit when iOS7 is dropped so that |
118 | | - ** option dialogs are always presented in UIModalPresentationPopover |
119 | | - if (isPopover) { |
120 | | - alertController.modalPresentationStyle = UIModalPresentationCurrentContext; |
121 | | - alertController.modalTransitionStyle = UIModalTransitionStyleCoverVertical; |
122 | | - } |
123 | | - */ |
124 | 112 | } |
| 113 | + |
125 | 114 | /*See Comment above. Remove if condition to see difference in behavior on iOS8*/ |
126 | 115 | if (!isPopover) { |
127 | 116 | UIPopoverPresentationController *presentationController = alertController.popoverPresentationController; |
128 | 117 | presentationController.permittedArrowDirections = UIPopoverArrowDirectionAny; |
129 | 118 | presentationController.delegate = self; |
| 119 | + |
| 120 | + // Configure anchor using `view` for all iOS devices (not iPad only) |
| 121 | + if (dialogView != nil) { |
| 122 | + [self configureSourceView:presentationController]; |
| 123 | + } |
130 | 124 | } |
131 | 125 |
|
132 | 126 | [self retain]; |
@@ -161,76 +155,6 @@ - (void)suspended:(NSNotification *)note |
161 | 155 | } |
162 | 156 | } |
163 | 157 |
|
164 | | -#pragma mark UIPopoverPresentationControllerDelegate |
165 | | -- (void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController |
166 | | -{ |
167 | | - if (dialogView != nil) { |
168 | | - if ([dialogView supportsNavBarPositioning] && [dialogView isUsingBarButtonItem]) { |
169 | | - UIBarButtonItem *theItem = [dialogView barButtonItem]; |
170 | | - if (theItem != nil) { |
171 | | - popoverPresentationController.barButtonItem = [dialogView barButtonItem]; |
172 | | - return; |
173 | | - } |
174 | | - } |
175 | | - |
176 | | - if ([dialogView conformsToProtocol:@protocol(TiToolbar)]) { |
177 | | - UIToolbar *toolbar = [(id<TiToolbar>)dialogView toolbar]; |
178 | | - if (toolbar != nil) { |
179 | | - popoverPresentationController.sourceView = toolbar; |
180 | | - popoverPresentationController.sourceRect = [toolbar bounds]; |
181 | | - return; |
182 | | - } |
183 | | - } |
184 | | - |
185 | | - if ([dialogView conformsToProtocol:@protocol(TiTab)]) { |
186 | | - id<TiTab> tab = (id<TiTab>)dialogView; |
187 | | - UITabBar *tabbar = [[tab tabGroup] tabbar]; |
188 | | - if (tabbar != nil) { |
189 | | - popoverPresentationController.sourceView = tabbar; |
190 | | - popoverPresentationController.sourceRect = [tabbar bounds]; |
191 | | - return; |
192 | | - } |
193 | | - } |
194 | | - |
195 | | - UIView *view = [dialogView view]; |
196 | | - if (view != nil) { |
197 | | - popoverPresentationController.sourceView = view; |
198 | | - popoverPresentationController.sourceRect = (CGRectEqualToRect(CGRectZero, dialogRect) ? CGRectMake(view.bounds.size.width / 2, view.bounds.size.height / 2, 1, 1) : dialogRect); |
199 | | - return; |
200 | | - } |
201 | | - } |
202 | | - |
203 | | - // Fell through. |
204 | | - UIViewController *presentingController = [alertController presentingViewController]; |
205 | | - popoverPresentationController.permittedArrowDirections = 0; |
206 | | - popoverPresentationController.sourceView = [presentingController view]; |
207 | | - popoverPresentationController.sourceRect = (CGRectEqualToRect(CGRectZero, dialogRect) ? CGRectMake(presentingController.view.bounds.size.width / 2, presentingController.view.bounds.size.height / 2, 1, 1) : dialogRect); |
208 | | - ; |
209 | | -} |
210 | | - |
211 | | -- (void)popoverPresentationController:(UIPopoverPresentationController *)popoverPresentationController willRepositionPopoverToRect:(inout CGRect *)rect inView:(inout UIView **)view |
212 | | -{ |
213 | | - // This will never be called when using bar button item |
214 | | - BOOL canUseDialogRect = !CGRectEqualToRect(CGRectZero, dialogRect); |
215 | | - UIView *theSourceView = *view; |
216 | | - BOOL shouldUseViewBounds = ([theSourceView isKindOfClass:[UIToolbar class]] || [theSourceView isKindOfClass:[UITabBar class]]); |
217 | | - |
218 | | - if (shouldUseViewBounds) { |
219 | | - rect->origin = CGPointMake(theSourceView.bounds.origin.x, theSourceView.bounds.origin.y); |
220 | | - rect->size = CGSizeMake(theSourceView.bounds.size.width, theSourceView.bounds.size.height); |
221 | | - } else if (!canUseDialogRect) { |
222 | | - rect->origin = CGPointMake(theSourceView.bounds.size.width / 2, theSourceView.bounds.size.height / 2); |
223 | | - rect->size = CGSizeMake(1, 1); |
224 | | - } |
225 | | - |
226 | | - popoverPresentationController.sourceRect = *rect; |
227 | | -} |
228 | | - |
229 | | -- (void)popoverPresentationControllerDidDismissPopover:(UIPopoverPresentationController *)popoverPresentationController |
230 | | -{ |
231 | | - [self cleanup]; |
232 | | -} |
233 | | - |
234 | 158 | #pragma mark Internal Use Only |
235 | 159 | - (void)fireClickEventWithAction:(UIAlertAction *)theAction |
236 | 160 | { |
@@ -271,6 +195,51 @@ - (void)cleanup |
271 | 195 | } |
272 | 196 | } |
273 | 197 |
|
| 198 | +- (void)configureSourceView:(UIPopoverPresentationController *)presentationController |
| 199 | +{ |
| 200 | + if ([dialogView isKindOfClass:TiUIButtonProxy.class]) { |
| 201 | + if ([dialogView isUsingBarButtonItem]) { |
| 202 | + UIBarButtonItem *theItem = [dialogView barButtonItem]; |
| 203 | + if (theItem != nil) { |
| 204 | + presentationController.barButtonItem = theItem; |
| 205 | + } |
| 206 | + } else { |
| 207 | + UIView *btnView = [dialogView view]; |
| 208 | + if (btnView != nil) { |
| 209 | + presentationController.sourceView = btnView; |
| 210 | + } |
| 211 | + } |
| 212 | + } else if ([dialogView supportsNavBarPositioning] && [dialogView isUsingBarButtonItem]) { |
| 213 | + UIBarButtonItem *theItem = [dialogView barButtonItem]; |
| 214 | + if (theItem != nil) { |
| 215 | + presentationController.barButtonItem = theItem; |
| 216 | + } |
| 217 | + } else if ([dialogView conformsToProtocol:@protocol(TiToolbar)]) { |
| 218 | + UIToolbar *toolbar = [(id<TiToolbar>)dialogView toolbar]; |
| 219 | + if (toolbar != nil) { |
| 220 | + presentationController.sourceView = toolbar; |
| 221 | + } |
| 222 | + } else if ([dialogView conformsToProtocol:@protocol(TiTab)]) { |
| 223 | + id<TiTab> tab = (id<TiTab>)dialogView; |
| 224 | + UITabBar *tabbar = [[tab tabGroup] tabbar]; |
| 225 | + if (tabbar != nil) { |
| 226 | + presentationController.sourceView = tabbar; |
| 227 | + } |
| 228 | + } else { |
| 229 | + UIView *view = [dialogView view]; |
| 230 | + if (view != nil) { |
| 231 | + presentationController.sourceView = view; |
| 232 | + } |
| 233 | + } |
| 234 | +} |
| 235 | + |
| 236 | +#pragma mark UIPopoverPresentationControllerDelegate |
| 237 | + |
| 238 | +- (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController |
| 239 | +{ |
| 240 | + [self cleanup]; |
| 241 | +} |
| 242 | + |
274 | 243 | @end |
275 | 244 |
|
276 | 245 | #endif |
0 commit comments