Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-24808] Implement autofill hints for TextField and TextArea #9368

Merged
merged 8 commits into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
TiC.PROPERTY_ATTRIBUTED_STRING,
TiC.PROPERTY_AUTOCAPITALIZATION,
TiC.PROPERTY_AUTOCORRECT,
TiC.PROPERTY_AUTOFILL_TYPE,
TiC.PROPERTY_AUTO_LINK,
TiC.PROPERTY_CLEAR_ON_EDIT,
TiC.PROPERTY_COLOR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
TiC.PROPERTY_ATTRIBUTED_HINT_TEXT,
TiC.PROPERTY_AUTOCAPITALIZATION,
TiC.PROPERTY_AUTOCORRECT,
TiC.PROPERTY_AUTOFILL_TYPE,
TiC.PROPERTY_AUTO_LINK,
TiC.PROPERTY_CLEAR_ON_EDIT,
TiC.PROPERTY_COLOR,
Expand Down
14 changes: 14 additions & 0 deletions android/modules/ui/src/java/ti/modules/titanium/ui/UIModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ public class UIModule extends KrollModule implements Handler.Callback
@Kroll.constant public static final int AUTOLINK_URLS = Linkify.WEB_URLS;
@Kroll.constant public static final int AUTOLINK_NONE = 16;

@Kroll.constant public static final String AUTOFILL_TYPE_USERNAME = View.AUTOFILL_HINT_USERNAME;
@Kroll.constant public static final String AUTOFILL_TYPE_PASSWORD = View.AUTOFILL_HINT_PASSWORD;
@Kroll.constant public static final String AUTOFILL_TYPE_EMAIL = View.AUTOFILL_HINT_EMAIL_ADDRESS;
@Kroll.constant public static final String AUTOFILL_TYPE_NAME = View.AUTOFILL_HINT_NAME;
@Kroll.constant public static final String AUTOFILL_TYPE_PHONE = View.AUTOFILL_HINT_PHONE;
@Kroll.constant public static final String AUTOFILL_TYPE_ADDRESS = View.AUTOFILL_HINT_POSTAL_ADDRESS;
@Kroll.constant public static final String AUTOFILL_TYPE_POSTAL_CODE = View.AUTOFILL_HINT_POSTAL_CODE;
@Kroll.constant public static final String AUTOFILL_TYPE_CARD_NUMBER = View.AUTOFILL_HINT_CREDIT_CARD_NUMBER;
@Kroll.constant public static final String AUTOFILL_TYPE_CARD_SECURITY_CODE = View.AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE;
@Kroll.constant public static final String AUTOFILL_TYPE_CARD_EXPIRATION_DATE = View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE;
@Kroll.constant public static final String AUTOFILL_TYPE_CARD_EXPIRATION_DAY = View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY;
@Kroll.constant public static final String AUTOFILL_TYPE_CARD_EXPIRATION_MONTH = View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH;
@Kroll.constant public static final String AUTOFILL_TYPE_CARD_EXPIRATION_YEAR = View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR;

@Kroll.constant public static final int INPUT_BORDERSTYLE_NONE = 0;
@Kroll.constant public static final int INPUT_BORDERSTYLE_ROUNDED = 1;
@Kroll.constant public static final int INPUT_BORDERSTYLE_BEZEL = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ public void processProperties(KrollDict d)
{
super.processProperties(d);

if (d.containsKey(TiC.PROPERTY_AUTOFILL_TYPE) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
tv.setAutofillHints(d.getString(TiC.PROPERTY_AUTOFILL_TYPE));
}

if (d.containsKey(TiC.PROPERTY_ENABLED)) {
tv.setEnabled(TiConvert.toBoolean(d, TiC.PROPERTY_ENABLED, true));
}
Expand Down Expand Up @@ -278,7 +282,9 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
if (Log.isDebugModeEnabled()) {
Log.d(TAG, "Property: " + key + " old: " + oldValue + " new: " + newValue, Log.DEBUG_MODE);
}
if (key.equals(TiC.PROPERTY_ENABLED)) {
if (key.equals(TiC.PROPERTY_AUTOFILL_TYPE) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
tv.setAutofillHints(TiConvert.toString(newValue));
} else if (key.equals(TiC.PROPERTY_ENABLED)) {
tv.setEnabled(TiConvert.toBoolean(newValue));
} else if (key.equals(TiC.PROPERTY_VALUE)) {
tv.setText(TiConvert.toString(newValue));
Expand Down
5 changes: 5 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,11 @@ public class TiC
*/
public static final String PROPERTY_AUTOCORRECT = "autocorrect";

/**
* @module.api
*/
public static final String PROPERTY_AUTOFILL_TYPE = "autofillType";

/**
* @module.api
*/
Expand Down
12 changes: 11 additions & 1 deletion apidoc/Titanium/UI/TextArea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ properties:
type: Boolean
platforms: [android, iphone, ipad]

- name: autofillType
summary: Sets the autofill type for the text area.
description: |
This sets the hint or content type to aid the autofill feature of iOS and Android to function.
type: String
constants: Titanium.UI.AUTOFILL_TYPE_*
default: undefined
since: "6.3.0"
osver: {ios: {min: "10.0"}, android: {min: "8.0"}}
platforms: [iphone, ipad, android]

- name: autoLink
summary: Automatically convert text to clickable links.
description: |
Expand Down Expand Up @@ -351,7 +362,6 @@ properties:
constants: Titanium.UI.TEXT_ALIGNMENT_*
default: <Titanium.UI.TEXT_ALIGNMENT_LEFT>


- name: value
summary: Value of this text area, which may be set programmatically and modified by the user.
description: |
Expand Down
10 changes: 10 additions & 0 deletions apidoc/Titanium/UI/TextField.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ properties:
default value is undefined, but all behave as if the value is `true`.
type: Boolean

- name: autofillType
summary: Sets the autofill type for the text field.
description: |
This sets the hint or content type to aid the autofill feature of iOS and Android to function.
type: String
constants: Titanium.UI.AUTOFILL_TYPE_*
default: undefined
since: "6.3.0"
osver: {ios: {min: "10.0"}, android: {min: "8.0"}}
platforms: [iphone, ipad, android]

- name: autoLink
summary: Automatically convert text to clickable links.
Expand Down
240 changes: 240 additions & 0 deletions apidoc/Titanium/UI/UI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,246 @@ properties:
permission: read-only
platforms: [iphone, ipad]

- name: AUTOFILL_TYPE_USERNAME
summary: Specifies the expectation of an account or login name.
type: String
platforms: [iphone, ipad, android]
since: "6.3.0"
osver: {ios: {min: "11.0"}, android: {min: "8.0"}}
permission: read-only

- name: AUTOFILL_TYPE_PASSWORD
summary: Specifies the expectation of a password.
type: String
platforms: [iphone, ipad, android]
since: "6.3.0"
osver: {ios: {min: "11.0"}, android: {min: "8.0"}}
permission: read-only

- name: AUTOFILL_TYPE_NAME
summary: Specifies the expectation of a name.
type: String
platforms: [iphone, ipad, android]
since: "6.3.0"
osver: {ios: {min: "10.0"}, android: {min: "8.0"}}
permission: read-only

- name: AUTOFILL_TYPE_NAME_PREFIX
summary: Specifies the expectation of a prefix or title, such as 'Dr.'
type: String
platforms: [iphone, ipad]
since: "6.3.0"
osver: {ios: {min: "10.0"}}
permission: read-only

- name: AUTOFILL_TYPE_GIVEN_NAME
summary: Specifies the expectation of a given name.
type: String
platforms: [iphone, ipad]
since: "6.3.0"
osver: {ios: {min: "10.0"}}
permission: read-only

- name: AUTOFILL_TYPE_MIDDLE_NAME
summary: Specifies the expectation of a middle name.
type: String
platforms: [iphone, ipad]
since: "6.3.0"
osver: {ios: {min: "10.0"}}
permission: read-only

- name: AUTOFILL_TYPE_FAMILY_NAME
summary: Specifies the expectation of a family name.
type: String
platforms: [iphone, ipad]
since: "6.3.0"
osver: {ios: {min: "10.0"}}
permission: read-only

- name: AUTOFILL_TYPE_NAME_SUFFIX
summary: Specifies the expectation of a suffix, such as 'Jr.'
type: String
platforms: [iphone, ipad]
since: "6.3.0"
osver: {ios: {min: "10.0"}}
permission: read-only

- name: AUTOFILL_TYPE_NICKNAME
summary: Specifies the expectation of a nickname.
type: String
platforms: [iphone, ipad]
since: "6.3.0"
osver: {ios: {min: "10.0"}}
permission: read-only

- name: AUTOFILL_TYPE_JOB_TITLE
summary: Specifies the expectation of a job title.
type: String
platforms: [iphone, ipad]
since: "6.3.0"
osver: {ios: {min: "10.0"}}
permission: read-only

- name: AUTOFILL_TYPE_ORGANIZATION_NAME
summary: Specifies the expectation of an organization name.
type: String
platforms: [iphone, ipad]
since: "6.3.0"
osver: {ios: {min: "10.0"}}
permission: read-only

- name: AUTOFILL_TYPE_LOCATION
summary: Specifies the expectation of a location, such as a point of interest, an address, or another way to identify a location.
type: String
platforms: [iphone, ipad]
since: "6.3.0"
osver: {ios: {min: "10.0"}}
permission: read-only

- name: AUTOFILL_TYPE_ADDRESS
summary: Specifies the expectation of an address.
type: String
platforms: [iphone, ipad, android]
since: "6.3.0"
osver: {ios: {min: "10.0"}, android: {min: "8.0"}}
permission: read-only

- name: AUTOFILL_TYPE_ADDRESS_LINE1
summary: Specifies the expectation of the first line of a street address.
type: String
platforms: [iphone, ipad]
since: "6.3.0"
osver: {ios: {min: "10.0"}}
permission: read-only

- name: AUTOFILL_TYPE_ADDRESS_LINE2
summary: Specifies the expectation of the second line of a street address.
type: String
platforms: [iphone, ipad]
since: "6.3.0"
osver: {ios: {min: "10.0"}}
permission: read-only

- name: AUTOFILL_TYPE_ADDRESS_CITY
summary: Specifies the expectation of a city name.
type: String
platforms: [iphone, ipad]
since: "6.3.0"
osver: {ios: {min: "10.0"}}
permission: read-only

- name: AUTOFILL_TYPE_ADDRESS_STATE
summary: Specifies the expectation of a state name.
type: String
platforms: [iphone, ipad]
since: "6.3.0"
osver: {ios: {min: "10.0"}}
permission: read-only

- name: AUTOFILL_TYPE_ADDRESS_CITY_STATE
summary: Specifies the expectation of a city name combined with a state name.
type: String
platforms: [iphone, ipad]
since: "6.3.0"
osver: {ios: {min: "10.0"}}
permission: read-only

- name: AUTOFILL_TYPE_SUBLOCALITY
summary: Specifies the expectation of a sublocality.
type: String
platforms: [iphone, ipad]
since: "6.3.0"
osver: {ios: {min: "10.0"}}
permission: read-only

- name: AUTOFILL_TYPE_COUNTRY_NAME
summary: Specifies the expectation of a country name.
type: String
platforms: [iphone, ipad]
since: "6.3.0"
osver: {ios: {min: "10.0"}}
permission: read-only

- name: AUTOFILL_TYPE_POSTAL_CODE
summary: Specifies the expectation of a postal code.
type: String
platforms: [iphone, ipad, android]
since: "6.3.0"
osver: {ios: {min: "10.0"}, android: {min: "8.0"}}
permission: read-only

- name: AUTOFILL_TYPE_PHONE
summary: Specifies the expectation of a telephone number.
type: String
platforms: [iphone, ipad, android]
since: "6.3.0"
osver: {ios: {min: "10.0"}, android: {min: "8.0"}}
permission: read-only

- name: AUTOFILL_TYPE_EMAIL
summary: Specifies the expectation of an email address.
type: String
platforms: [iphone, ipad, android]
since: "6.3.0"
osver: {ios: {min: "10.0"}, android: {min: "8.0"}}
permission: read-only

- name: AUTOFILL_TYPE_URL
summary: Specifies the expectation of a URL.
type: String
platforms: [iphone, ipad]
since: "6.3.0"
osver: {ios: {min: "10.0"}}
permission: read-only

- name: AUTOFILL_TYPE_CARD_NUMBER
summary: Specifies the expectation of a card number.
type: String
platforms: [iphone, ipad, android]
since: "6.3.0"
osver: {ios: {min: "10.0"}, android: {min: "8.0"}}
permission: read-only

- name: AUTOFILL_TYPE_CARD_SECURITY_CODE
summary: Specifies the expectation of a card security code.
type: String
platforms: [android]
since: "6.3.0"
osver: {android: {min: "8.0"}}
permission: read-only

- name: AUTOFILL_TYPE_CARD_EXPIRATION_DATE
summary: Specifies the expectation of a card expiration date.
type: String
platforms: [android]
since: "6.3.0"
osver: {android: {min: "8.0"}}
permission: read-only

- name: AUTOFILL_TYPE_CARD_EXPIRATION_DAY
summary: Specifies the expectation of a card expectation day.
type: String
platforms: [android]
since: "6.3.0"
osver: {android: {min: "8.0"}}
permission: read-only

- name: AUTOFILL_TYPE_CARD_EXPIRATION_MONTH
summary: Specifies the expectation of a card expectation month.
type: String
platforms: [android]
since: "6.3.0"
osver: {android: {min: "8.0"}}
permission: read-only

- name: AUTOFILL_TYPE_CARD_EXPIRATION_YEAR
summary: Specifies the expectation of a card expectation year.
type: String
platforms: [android]
since: "6.3.0"
osver: {android: {min: "8.0"}}
permission: read-only

- name: AUTOLINK_MAP_ADDRESSES
summary: Converts strings formatted as addresses into clickable links.
description: |
Expand Down
14 changes: 13 additions & 1 deletion iphone/Classes/TiUITextWidget.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ - (void)setAutocorrect_:(id)value
[[self textWidgetView] setAutocorrectionType:[TiUtils boolValue:value] ? UITextAutocorrectionTypeYes : UITextAutocorrectionTypeNo];
}

- (void)setAutofillType_:(id)value
{
ENSURE_TYPE_OR_NIL(value, NSString);

if (![TiUtils isIOS10OrGreater]) {
NSLog(@"[ERROR] The 'autofillHint' property is only available on iOS 10 and later.");
return;
}

[[self textWidgetView] setTextContentType:[TiUtils stringValue:value]];
}

#pragma mark Responder methods
//These used to be blur/focus, but that's moved to the proxy only.
//The reason for that is so checking the toolbar can use UIResponder methods.
Expand Down Expand Up @@ -266,4 +278,4 @@ - (void)updateKeyboardStatus

@end

#endif
#endif