From dff35882a39442041cdb8857ff46409090757395 Mon Sep 17 00:00:00 2001 From: Pavlos Vinieratos Date: Thu, 27 Jun 2019 03:16:22 -0700 Subject: [PATCH] add `passwordRules` for `textContentType` `newPassword` (#25407) Summary: On `textContentType` `newPassword` on ios, there is another property called `passwordRules` on ios 12 that can give hints to the os to generate a password with specific requirements like [here](https://developer.apple.com/password-rules/). This is useful for apps that have a "register" screen with `emailAddress`/`username` and a `newPassword` fields, to let ios make a password that will satisfy the requirements and not one that might be not accepted after the user presses "register". ## Changelog [iOS] [Added] - PasswordRules for new password textContentType input fields Pull Request resolved: https://github.com/facebook/react-native/pull/25407 Test Plan: This is a bit harder, but to test you need to make an app that has associated domains with an apple-app-site-association file on that domain, enable iCloud Keychain on the test device, and then iOS will suggest a password, otherwise you will just get a warning on Xcode saying "Couldn't suggest password because of: blabla". Differential Revision: D16028684 Pulled By: cpojer fbshipit-source-id: d22426e07f1db45d1f79f5dad81f1465a9701f0b --- Libraries/Components/TextInput/TextInput.js | 3 +++ Libraries/Text/TextInput/RCTBaseTextInputView.m | 10 ++++++++++ Libraries/Text/TextInput/RCTBaseTextInputViewManager.m | 1 + 3 files changed, 14 insertions(+) diff --git a/Libraries/Components/TextInput/TextInput.js b/Libraries/Components/TextInput/TextInput.js index 9e4f29c94c9..14d13fcb7a8 100644 --- a/Libraries/Components/TextInput/TextInput.js +++ b/Libraries/Components/TextInput/TextInput.js @@ -208,6 +208,8 @@ export type TextContentType = | 'newPassword' | 'oneTimeCode'; +type PasswordRules = string; + type IOSProps = $ReadOnly<{| spellCheck?: ?boolean, keyboardAppearance?: ?('default' | 'light' | 'dark'), @@ -220,6 +222,7 @@ type IOSProps = $ReadOnly<{| | $ReadOnlyArray, inputAccessoryViewID?: ?string, textContentType?: ?TextContentType, + PasswordRules?: ?PasswordRules, scrollEnabled?: ?boolean, |}>; diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index ff8bd3140d2..c82c7b8142e 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -260,6 +260,16 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame) #endif } + +- (void)setPasswordRules:(NSString *)descriptor +{ + #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_12_0 + if (@available(iOS 12.0, *)) { + self.backedTextInputView.passwordRules = [UITextInputPasswordRules passwordRulesWithDescriptor:descriptor]; + } + #endif +} + - (UIKeyboardType)keyboardType { return self.backedTextInputView.keyboardType; diff --git a/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m b/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m index d226782be62..a1a3671be8c 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m @@ -57,6 +57,7 @@ RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL) RCT_EXPORT_VIEW_PROPERTY(selection, RCTTextSelection) RCT_EXPORT_VIEW_PROPERTY(inputAccessoryViewID, NSString) RCT_EXPORT_VIEW_PROPERTY(textContentType, NSString) +RCT_EXPORT_VIEW_PROPERTY(passwordRules, NSString) RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onSelectionChange, RCTDirectEventBlock)