|
1 | 1 | /** |
2 | 2 | * iOS specific dialogs functions implementation. |
3 | 3 | */ |
4 | | -import { ios as iosView } from "../core/view"; |
| 4 | +import { ios as iosView, traceCategories, traceWrite, traceMessageType } from "../core/view"; |
5 | 5 | import { ConfirmOptions, PromptOptions, PromptResult, LoginOptions, LoginResult, ActionOptions } from "."; |
6 | 6 | import { getCurrentPage, getLabelColor, getButtonColors, getTextFieldColor, isDialogOptions, inputType, capitalizationType, ALERT, OK, CONFIRM, CANCEL, PROMPT, parseLoginOptions } from "./dialogs-common"; |
7 | 7 | import { isString, isDefined, isFunction } from "../../utils/types"; |
8 | | -import { getRootView } from "../../application"; |
| 8 | +import { getRootView, ios } from "../../application"; |
9 | 9 |
|
10 | 10 | export * from "./dialogs-common"; |
11 | 11 |
|
@@ -200,54 +200,42 @@ export function login(...args: any[]): Promise<LoginResult> { |
200 | 200 | } |
201 | 201 |
|
202 | 202 | function showUIAlertController(alertController: UIAlertController) { |
203 | | - let currentView = getCurrentPage() || getRootView(); |
| 203 | + let viewController = ios.rootController; |
| 204 | + |
| 205 | + while (viewController && viewController.presentedViewController) { |
| 206 | + viewController = viewController.presentedViewController; |
| 207 | + } |
204 | 208 |
|
205 | | - if (currentView) { |
206 | | - currentView = currentView.modal || currentView; |
| 209 | + if (!viewController) { |
| 210 | + traceWrite(`No root controller found to open dialog.`, traceCategories.Error, traceMessageType.warn); |
| 211 | + |
| 212 | + return; |
| 213 | + } |
207 | 214 |
|
208 | | - //get to the top most view controller on the stack |
209 | | - while (currentView && currentView.modal) { |
210 | | - currentView = currentView.modal; |
211 | | - } |
212 | | - |
213 | | - let viewController: UIViewController = currentView.ios; |
| 215 | + if (alertController.popoverPresentationController) { |
| 216 | + alertController.popoverPresentationController.sourceView = viewController.view; |
| 217 | + alertController.popoverPresentationController.sourceRect = CGRectMake(viewController.view.bounds.size.width / 2.0, viewController.view.bounds.size.height / 2.0, 1.0, 1.0); |
| 218 | + alertController.popoverPresentationController.permittedArrowDirections = 0; |
| 219 | + } |
214 | 220 |
|
215 | | - if (viewController.presentedViewController) { |
216 | | - viewController = viewController.presentedViewController; |
217 | | - } |
| 221 | + let color = getButtonColors().color; |
| 222 | + if (color) { |
| 223 | + alertController.view.tintColor = color.ios; |
| 224 | + } |
218 | 225 |
|
219 | | - if (!(currentView.ios instanceof UIViewController)) { |
220 | | - const parentWithController = iosView.getParentWithViewController(currentView); |
221 | | - viewController = parentWithController ? parentWithController.viewController : undefined; |
| 226 | + let lblColor = getLabelColor(); |
| 227 | + if (lblColor) { |
| 228 | + if (alertController.title) { |
| 229 | + let title = NSAttributedString.alloc().initWithStringAttributes(alertController.title, <any>{ [NSForegroundColorAttributeName]: lblColor.ios }); |
| 230 | + alertController.setValueForKey(title, "attributedTitle"); |
222 | 231 | } |
223 | | - |
224 | | - if (viewController) { |
225 | | - if (alertController.popoverPresentationController) { |
226 | | - alertController.popoverPresentationController.sourceView = viewController.view; |
227 | | - alertController.popoverPresentationController.sourceRect = CGRectMake(viewController.view.bounds.size.width / 2.0, viewController.view.bounds.size.height / 2.0, 1.0, 1.0); |
228 | | - alertController.popoverPresentationController.permittedArrowDirections = 0; |
229 | | - } |
230 | | - |
231 | | - let color = getButtonColors().color; |
232 | | - if (color) { |
233 | | - alertController.view.tintColor = color.ios; |
234 | | - } |
235 | | - |
236 | | - let lblColor = getLabelColor(); |
237 | | - if (lblColor) { |
238 | | - if (alertController.title) { |
239 | | - let title = NSAttributedString.alloc().initWithStringAttributes(alertController.title, <any>{ [NSForegroundColorAttributeName]: lblColor.ios }); |
240 | | - alertController.setValueForKey(title, "attributedTitle"); |
241 | | - } |
242 | | - if (alertController.message) { |
243 | | - let message = NSAttributedString.alloc().initWithStringAttributes(alertController.message, <any>{ [NSForegroundColorAttributeName]: lblColor.ios }); |
244 | | - alertController.setValueForKey(message, "attributedMessage"); |
245 | | - } |
246 | | - } |
247 | | - |
248 | | - viewController.presentModalViewControllerAnimated(alertController, true); |
| 232 | + if (alertController.message) { |
| 233 | + let message = NSAttributedString.alloc().initWithStringAttributes(alertController.message, <any>{ [NSForegroundColorAttributeName]: lblColor.ios }); |
| 234 | + alertController.setValueForKey(message, "attributedMessage"); |
249 | 235 | } |
250 | 236 | } |
| 237 | + |
| 238 | + viewController.presentModalViewControllerAnimated(alertController, true); |
251 | 239 | } |
252 | 240 |
|
253 | 241 | export function action(): Promise<string> { |
|
0 commit comments