mirror of
				https://github.com/NativeScript/NativeScript.git
				synced 2025-11-01 00:25:37 +08:00 
			
		
		
		
	feat(dialogs): allow using keyboard enter/return to confirm on iOS (#10799)
This commit is contained in:
		| @ -17,7 +17,7 @@ function addButtonsToAlertController(alertController: UIAlertController, options | |||||||
| 		alertController.addAction( | 		alertController.addAction( | ||||||
| 			UIAlertAction.actionWithTitleStyleHandler(options.cancelButtonText, UIAlertActionStyle.Default, () => { | 			UIAlertAction.actionWithTitleStyleHandler(options.cancelButtonText, UIAlertActionStyle.Default, () => { | ||||||
| 				raiseCallback(callback, false); | 				raiseCallback(callback, false); | ||||||
| 			}) | 			}), | ||||||
| 		); | 		); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @ -25,16 +25,16 @@ function addButtonsToAlertController(alertController: UIAlertController, options | |||||||
| 		alertController.addAction( | 		alertController.addAction( | ||||||
| 			UIAlertAction.actionWithTitleStyleHandler(options.neutralButtonText, UIAlertActionStyle.Default, () => { | 			UIAlertAction.actionWithTitleStyleHandler(options.neutralButtonText, UIAlertActionStyle.Default, () => { | ||||||
| 				raiseCallback(callback, undefined); | 				raiseCallback(callback, undefined); | ||||||
| 			}) | 			}), | ||||||
| 		); | 		); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if (isString(options.okButtonText)) { | 	if (isString(options.okButtonText)) { | ||||||
| 		alertController.addAction( | 		const action = UIAlertAction.actionWithTitleStyleHandler(options.okButtonText, UIAlertActionStyle.Default, () => { | ||||||
| 			UIAlertAction.actionWithTitleStyleHandler(options.okButtonText, UIAlertActionStyle.Default, () => { | 			raiseCallback(callback, true); | ||||||
| 				raiseCallback(callback, true); | 		}); | ||||||
| 			}) | 		alertController.addAction(action); | ||||||
| 		); | 		alertController.preferredAction = action; // Allows using keyboard enter/return to confirm the dialog | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -91,7 +91,7 @@ export function alert(arg: any): Promise<void> { | |||||||
| 						title: DialogStrings.ALERT, | 						title: DialogStrings.ALERT, | ||||||
| 						okButtonText: DialogStrings.OK, | 						okButtonText: DialogStrings.OK, | ||||||
| 						message: arg + '', | 						message: arg + '', | ||||||
| 				  } | 					} | ||||||
| 				: arg; | 				: arg; | ||||||
| 			const alertController = UIAlertController.alertControllerWithTitleMessagePreferredStyle(options.title, options.message, UIAlertControllerStyle.Alert); | 			const alertController = UIAlertController.alertControllerWithTitleMessagePreferredStyle(options.title, options.message, UIAlertControllerStyle.Alert); | ||||||
|  |  | ||||||
| @ -115,7 +115,7 @@ export function confirm(arg: any): Promise<boolean> { | |||||||
| 						okButtonText: DialogStrings.OK, | 						okButtonText: DialogStrings.OK, | ||||||
| 						cancelButtonText: DialogStrings.CANCEL, | 						cancelButtonText: DialogStrings.CANCEL, | ||||||
| 						message: arg + '', | 						message: arg + '', | ||||||
| 				  } | 					} | ||||||
| 				: arg; | 				: arg; | ||||||
| 			const alertController = UIAlertController.alertControllerWithTitleMessagePreferredStyle(options.title, options.message, UIAlertControllerStyle.Alert); | 			const alertController = UIAlertController.alertControllerWithTitleMessagePreferredStyle(options.title, options.message, UIAlertControllerStyle.Alert); | ||||||
|  |  | ||||||
| @ -301,7 +301,7 @@ export function action(...args): Promise<string> { | |||||||
| 						alertController.addAction( | 						alertController.addAction( | ||||||
| 							UIAlertAction.actionWithTitleStyleHandler(action, dialogType, (arg: UIAlertAction) => { | 							UIAlertAction.actionWithTitleStyleHandler(action, dialogType, (arg: UIAlertAction) => { | ||||||
| 								resolve(arg.title); | 								resolve(arg.title); | ||||||
| 							}) | 							}), | ||||||
| 						); | 						); | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| @ -311,7 +311,7 @@ export function action(...args): Promise<string> { | |||||||
| 				alertController.addAction( | 				alertController.addAction( | ||||||
| 					UIAlertAction.actionWithTitleStyleHandler(options.cancelButtonText, UIAlertActionStyle.Cancel, (arg: UIAlertAction) => { | 					UIAlertAction.actionWithTitleStyleHandler(options.cancelButtonText, UIAlertActionStyle.Cancel, (arg: UIAlertAction) => { | ||||||
| 						resolve(arg.title); | 						resolve(arg.title); | ||||||
| 					}) | 					}), | ||||||
| 				); | 				); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Samuel Schultze
					Samuel Schultze