chore: cleanup

This commit is contained in:
Nathan Walker
2020-07-06 14:25:11 -07:00
parent 94cf5c4706
commit 6336eac4b5
477 changed files with 59087 additions and 74961 deletions

View File

@@ -1,134 +1,100 @@
import { TextFieldBase, secureProperty } from "./text-field-common";
import { whiteSpaceProperty, WhiteSpace } from "../text-base";
import { keyboardTypeProperty } from "../editable-text-base";
import { TextFieldBase, secureProperty } from './text-field-common';
import { whiteSpaceProperty, WhiteSpace } from '../text-base';
import { keyboardTypeProperty } from '../editable-text-base';
export * from "./text-field-common";
export * from './text-field-common';
export class TextField extends TextFieldBase {
public _configureEditText(editText: android.widget.EditText) {
editText.setInputType(
android.text.InputType.TYPE_CLASS_TEXT |
android.text.InputType.TYPE_TEXT_VARIATION_NORMAL |
android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES |
android.text.InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
);
editText.setLines(1);
editText.setMaxLines(1);
editText.setHorizontallyScrolling(true);
}
public _configureEditText(editText: android.widget.EditText) {
editText.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_NORMAL | android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | android.text.InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
editText.setLines(1);
editText.setMaxLines(1);
editText.setHorizontallyScrolling(true);
}
public _onReturnPress() {
this.notify({ eventName: TextField.returnPressEvent, object: this });
}
public _onReturnPress() {
this.notify({ eventName: TextField.returnPressEvent, object: this });
}
[secureProperty.setNative]() {
this.setSecureAndKeyboardType();
}
[secureProperty.setNative]() {
this.setSecureAndKeyboardType();
}
[keyboardTypeProperty.setNative]() {
this.setSecureAndKeyboardType();
}
[keyboardTypeProperty.setNative]() {
this.setSecureAndKeyboardType();
}
setSecureAndKeyboardType(): void {
let inputType: number;
setSecureAndKeyboardType(): void {
let inputType: number;
// Password variations are supported only for Text and Number classes.
if (this.secure) {
if (this.keyboardType === "number") {
inputType =
android.text.InputType.TYPE_CLASS_NUMBER |
android.text.InputType.TYPE_NUMBER_VARIATION_PASSWORD;
} else {
inputType =
android.text.InputType.TYPE_CLASS_TEXT |
android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD;
}
} else {
// default
inputType =
android.text.InputType.TYPE_CLASS_TEXT |
android.text.InputType.TYPE_TEXT_VARIATION_NORMAL;
// Password variations are supported only for Text and Number classes.
if (this.secure) {
if (this.keyboardType === 'number') {
inputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_VARIATION_PASSWORD;
} else {
inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD;
}
} else {
// default
inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_NORMAL;
// add autocorrect flags
if (this.autocorrect) {
inputType =
inputType |
android.text.InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE;
inputType =
inputType |
android.text.InputType.TYPE_TEXT_FLAG_AUTO_CORRECT;
inputType =
inputType &
~android.text.InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
}
// add autocorrect flags
if (this.autocorrect) {
inputType = inputType | android.text.InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE;
inputType = inputType | android.text.InputType.TYPE_TEXT_FLAG_AUTO_CORRECT;
inputType = inputType & ~android.text.InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
}
// add autocapitalization type
switch (this.autocapitalizationType) {
case "words":
inputType =
inputType |
android.text.InputType.TYPE_TEXT_FLAG_CAP_WORDS; //8192 (0x00020000) 14th bit
break;
case "sentences":
inputType =
inputType |
android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; //16384(0x00040000) 15th bit
break;
case "allcharacters":
inputType =
inputType |
android.text.InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; //4096 (0x00010000) 13th bit
break;
default:
break;
}
// add autocapitalization type
switch (this.autocapitalizationType) {
case 'words':
inputType = inputType | android.text.InputType.TYPE_TEXT_FLAG_CAP_WORDS; //8192 (0x00020000) 14th bit
break;
case 'sentences':
inputType = inputType | android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; //16384(0x00040000) 15th bit
break;
case 'allcharacters':
inputType = inputType | android.text.InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; //4096 (0x00010000) 13th bit
break;
default:
break;
}
// add keyboardType flags.
// They override previous if set.
switch (this.keyboardType) {
case "datetime":
inputType =
android.text.InputType.TYPE_CLASS_DATETIME |
android.text.InputType.TYPE_DATETIME_VARIATION_NORMAL;
break;
case "phone":
inputType = android.text.InputType.TYPE_CLASS_PHONE;
break;
case "number":
inputType =
android.text.InputType.TYPE_CLASS_NUMBER |
android.text.InputType.TYPE_NUMBER_VARIATION_NORMAL |
android.text.InputType.TYPE_NUMBER_FLAG_SIGNED |
android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL;
break;
case "url":
inputType =
android.text.InputType.TYPE_CLASS_TEXT |
android.text.InputType.TYPE_TEXT_VARIATION_URI;
break;
case "email":
inputType =
android.text.InputType.TYPE_CLASS_TEXT |
android.text.InputType
.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
break;
case "integer":
inputType = android.text.InputType.TYPE_CLASS_NUMBER;
break;
default:
break;
}
}
// add keyboardType flags.
// They override previous if set.
switch (this.keyboardType) {
case 'datetime':
inputType = android.text.InputType.TYPE_CLASS_DATETIME | android.text.InputType.TYPE_DATETIME_VARIATION_NORMAL;
break;
case 'phone':
inputType = android.text.InputType.TYPE_CLASS_PHONE;
break;
case 'number':
inputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_VARIATION_NORMAL | android.text.InputType.TYPE_NUMBER_FLAG_SIGNED | android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL;
break;
case 'url':
inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_URI;
break;
case 'email':
inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
break;
case 'integer':
inputType = android.text.InputType.TYPE_CLASS_NUMBER;
break;
default:
break;
}
}
this._setInputType(inputType);
}
this._setInputType(inputType);
}
[whiteSpaceProperty.getDefault](): WhiteSpace {
return "nowrap";
}
[whiteSpaceProperty.setNative](value: WhiteSpace) {
// Don't change it otherwise TextField will go to multiline mode.
}
[whiteSpaceProperty.getDefault](): WhiteSpace {
return 'nowrap';
}
[whiteSpaceProperty.setNative](value: WhiteSpace) {
// Don't change it otherwise TextField will go to multiline mode.
}
}
TextField.prototype._isSingleLine = true;

View File

@@ -1,5 +1,5 @@
import { EditableTextBase } from "../editable-text-base";
import { Property } from "../core/properties";
import { EditableTextBase } from '../editable-text-base';
import { Property } from '../core/properties';
export const secureProperty: Property<TextField, boolean>;
@@ -7,30 +7,30 @@ export const secureProperty: Property<TextField, boolean>;
* Represents an editable text field.
*/
export class TextField extends EditableTextBase {
public static returnPressEvent: string;
public static returnPressEvent: string;
/**
* Gets the native [android widget](http://developer.android.com/reference/android/widget/EditText.html) that represents the user interface for this component. Valid only when running on Android OS.
*/
android: any /* android.widget.EditText */;
/**
* Gets the native [android widget](http://developer.android.com/reference/android/widget/EditText.html) that represents the user interface for this component. Valid only when running on Android OS.
*/
android: any /* android.widget.EditText */;
/**
* Gets the native iOS [UITextField](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextField_Class/) that represents the user interface for this component. Valid only when running on iOS.
*/
ios: any /* UITextField */;
/**
* Gets the native iOS [UITextField](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextField_Class/) that represents the user interface for this component. Valid only when running on iOS.
*/
ios: any /* UITextField */;
/**
* Gets or sets if a text field is for password entry.
*/
secure: boolean;
/**
* Gets or sets if a text field is for password entry.
*/
secure: boolean;
/**
* Gets or sets if a text field should dismiss on return.
*/
closeOnReturn: boolean;
/**
* Gets or sets if a text field should dismiss on return.
*/
closeOnReturn: boolean;
/**
* iOS only (to avoid 12+ auto suggested strong password handling)
*/
secureWithoutAutofill: boolean;
/**
* iOS only (to avoid 12+ auto suggested strong password handling)
*/
secureWithoutAutofill: boolean;
}

View File

@@ -1,368 +1,308 @@
import { TextFieldBase, secureProperty } from "./text-field-common";
import { textProperty } from "../text-base";
import {
hintProperty,
placeholderColorProperty,
_updateCharactersInRangeReplacementString,
} from "../editable-text-base";
import { Color } from "../../color";
import {
colorProperty,
Length,
paddingTopProperty,
paddingRightProperty,
paddingBottomProperty,
paddingLeftProperty,
} from "../styling/style-properties";
import { layout } from "../../utils/utils";
import { profile } from "../../profiling";
import { TextFieldBase, secureProperty } from './text-field-common';
import { textProperty } from '../text-base';
import { hintProperty, placeholderColorProperty, _updateCharactersInRangeReplacementString } from '../editable-text-base';
import { Color } from '../../color';
import { colorProperty, Length, paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty } from '../styling/style-properties';
import { layout } from '../../utils';
import { profile } from '../../profiling';
export * from "./text-field-common";
export * from './text-field-common';
const zeroLength: Length = {
value: 0,
unit: "px",
value: 0,
unit: 'px',
};
class UITextFieldDelegateImpl extends NSObject implements UITextFieldDelegate {
public static ObjCProtocols = [UITextFieldDelegate];
public static ObjCProtocols = [UITextFieldDelegate];
private _owner: WeakRef<TextField>;
private firstEdit: boolean;
private _owner: WeakRef<TextField>;
private firstEdit: boolean;
public static initWithOwner(
owner: WeakRef<TextField>
): UITextFieldDelegateImpl {
const delegate = <UITextFieldDelegateImpl>UITextFieldDelegateImpl.new();
delegate._owner = owner;
public static initWithOwner(owner: WeakRef<TextField>): UITextFieldDelegateImpl {
const delegate = <UITextFieldDelegateImpl>UITextFieldDelegateImpl.new();
delegate._owner = owner;
return delegate;
}
return delegate;
}
public textFieldShouldBeginEditing(textField: UITextField): boolean {
const owner = this._owner.get();
if (owner) {
return owner.textFieldShouldBeginEditing(textField);
}
public textFieldShouldBeginEditing(textField: UITextField): boolean {
const owner = this._owner.get();
if (owner) {
return owner.textFieldShouldBeginEditing(textField);
}
return true;
}
return true;
}
public textFieldDidBeginEditing(textField: UITextField): void {
const owner = this._owner.get();
if (owner) {
owner.textFieldDidBeginEditing(textField);
}
}
public textFieldDidBeginEditing(textField: UITextField): void {
const owner = this._owner.get();
if (owner) {
owner.textFieldDidBeginEditing(textField);
}
}
public textFieldDidEndEditing(textField: UITextField) {
const owner = this._owner.get();
if (owner) {
owner.textFieldDidEndEditing(textField);
}
}
public textFieldDidEndEditing(textField: UITextField) {
const owner = this._owner.get();
if (owner) {
owner.textFieldDidEndEditing(textField);
}
}
public textFieldShouldClear(textField: UITextField) {
const owner = this._owner.get();
if (owner) {
return owner.textFieldShouldClear(textField);
}
public textFieldShouldClear(textField: UITextField) {
const owner = this._owner.get();
if (owner) {
return owner.textFieldShouldClear(textField);
}
return true;
}
return true;
}
public textFieldShouldReturn(textField: UITextField): boolean {
// Called when the user presses the return button.
const owner = this._owner.get();
if (owner) {
return owner.textFieldShouldReturn(textField);
}
public textFieldShouldReturn(textField: UITextField): boolean {
// Called when the user presses the return button.
const owner = this._owner.get();
if (owner) {
return owner.textFieldShouldReturn(textField);
}
return true;
}
return true;
}
public textFieldShouldChangeCharactersInRangeReplacementString(
textField: UITextField,
range: NSRange,
replacementString: string
): boolean {
const owner = this._owner.get();
if (owner) {
return owner.textFieldShouldChangeCharactersInRangeReplacementString(
textField,
range,
replacementString
);
}
public textFieldShouldChangeCharactersInRangeReplacementString(textField: UITextField, range: NSRange, replacementString: string): boolean {
const owner = this._owner.get();
if (owner) {
return owner.textFieldShouldChangeCharactersInRangeReplacementString(textField, range, replacementString);
}
return true;
}
return true;
}
}
class UITextFieldImpl extends UITextField {
private _owner: WeakRef<TextField>;
private _owner: WeakRef<TextField>;
public static initWithOwner(owner: WeakRef<TextField>): UITextFieldImpl {
const handler = <UITextFieldImpl>UITextFieldImpl.new();
handler._owner = owner;
public static initWithOwner(owner: WeakRef<TextField>): UITextFieldImpl {
const handler = <UITextFieldImpl>UITextFieldImpl.new();
handler._owner = owner;
return handler;
}
return handler;
}
private _getTextRectForBounds(bounds: CGRect): CGRect {
const owner = this._owner ? this._owner.get() : null;
private _getTextRectForBounds(bounds: CGRect): CGRect {
const owner = this._owner ? this._owner.get() : null;
if (!owner) {
return bounds;
}
if (!owner) {
return bounds;
}
const size = bounds.size;
const size = bounds.size;
const x = layout.toDeviceIndependentPixels(
owner.effectiveBorderLeftWidth + owner.effectivePaddingLeft
);
const y = layout.toDeviceIndependentPixels(
owner.effectiveBorderTopWidth + owner.effectivePaddingTop
);
const width = layout.toDeviceIndependentPixels(
layout.toDevicePixels(size.width) -
(owner.effectiveBorderLeftWidth +
owner.effectivePaddingLeft +
owner.effectivePaddingRight +
owner.effectiveBorderRightWidth)
);
const height = layout.toDeviceIndependentPixels(
layout.toDevicePixels(size.height) -
(owner.effectiveBorderTopWidth +
owner.effectivePaddingTop +
owner.effectivePaddingBottom +
owner.effectiveBorderBottomWidth)
);
const x = layout.toDeviceIndependentPixels(owner.effectiveBorderLeftWidth + owner.effectivePaddingLeft);
const y = layout.toDeviceIndependentPixels(owner.effectiveBorderTopWidth + owner.effectivePaddingTop);
const width = layout.toDeviceIndependentPixels(layout.toDevicePixels(size.width) - (owner.effectiveBorderLeftWidth + owner.effectivePaddingLeft + owner.effectivePaddingRight + owner.effectiveBorderRightWidth));
const height = layout.toDeviceIndependentPixels(layout.toDevicePixels(size.height) - (owner.effectiveBorderTopWidth + owner.effectivePaddingTop + owner.effectivePaddingBottom + owner.effectiveBorderBottomWidth));
return CGRectMake(x, y, width, height);
}
return CGRectMake(x, y, width, height);
}
public textRectForBounds(bounds: CGRect): CGRect {
return this._getTextRectForBounds(bounds);
}
public textRectForBounds(bounds: CGRect): CGRect {
return this._getTextRectForBounds(bounds);
}
public editingRectForBounds(bounds: CGRect): CGRect {
return this._getTextRectForBounds(bounds);
}
public editingRectForBounds(bounds: CGRect): CGRect {
return this._getTextRectForBounds(bounds);
}
}
export class TextField extends TextFieldBase {
nativeViewProtected: UITextField;
private _delegate: UITextFieldDelegateImpl;
nativeViewProtected: UITextField;
private _delegate: UITextFieldDelegateImpl;
createNativeView() {
return UITextFieldImpl.initWithOwner(new WeakRef(this));
}
createNativeView() {
return UITextFieldImpl.initWithOwner(new WeakRef(this));
}
initNativeView() {
super.initNativeView();
this._delegate = UITextFieldDelegateImpl.initWithOwner(
new WeakRef(this)
);
}
initNativeView() {
super.initNativeView();
this._delegate = UITextFieldDelegateImpl.initWithOwner(new WeakRef(this));
}
disposeNativeView() {
this._delegate = null;
super.disposeNativeView();
}
disposeNativeView() {
this._delegate = null;
super.disposeNativeView();
}
@profile()
public onLoaded() {
super.onLoaded();
this.ios.delegate = this._delegate;
}
@profile()
public onLoaded() {
super.onLoaded();
this.ios.delegate = this._delegate;
}
public onUnloaded() {
this.ios.delegate = null;
super.onUnloaded();
}
public onUnloaded() {
this.ios.delegate = null;
super.onUnloaded();
}
get ios(): UITextField {
return this.nativeViewProtected;
}
get ios(): UITextField {
return this.nativeViewProtected;
}
private firstEdit: boolean;
private firstEdit: boolean;
public textFieldShouldBeginEditing(textField: UITextField): boolean {
this.firstEdit = true;
public textFieldShouldBeginEditing(textField: UITextField): boolean {
this.firstEdit = true;
return this.editable;
}
return this.editable;
}
public textFieldDidBeginEditing(textField: UITextField): void {
this.notify({ eventName: TextField.focusEvent, object: this });
}
public textFieldDidBeginEditing(textField: UITextField): void {
this.notify({ eventName: TextField.focusEvent, object: this });
}
public textFieldDidEndEditing(textField: UITextField) {
if (this.updateTextTrigger === "focusLost") {
textProperty.nativeValueChange(this, textField.text);
}
public textFieldDidEndEditing(textField: UITextField) {
if (this.updateTextTrigger === 'focusLost') {
textProperty.nativeValueChange(this, textField.text);
}
this.dismissSoftInput();
}
this.dismissSoftInput();
}
public textFieldShouldClear(textField: UITextField) {
this.firstEdit = false;
textProperty.nativeValueChange(this, "");
public textFieldShouldClear(textField: UITextField) {
this.firstEdit = false;
textProperty.nativeValueChange(this, '');
return true;
}
return true;
}
public textFieldShouldReturn(textField: UITextField): boolean {
// Called when the user presses the return button.
if (this.closeOnReturn) {
this.dismissSoftInput();
}
this.notify({ eventName: TextField.returnPressEvent, object: this });
public textFieldShouldReturn(textField: UITextField): boolean {
// Called when the user presses the return button.
if (this.closeOnReturn) {
this.dismissSoftInput();
}
this.notify({ eventName: TextField.returnPressEvent, object: this });
return true;
}
return true;
}
public textFieldShouldChangeCharactersInRangeReplacementString(
textField: UITextField,
range: NSRange,
replacementString: string
): boolean {
if (this.secureWithoutAutofill && !textField.secureTextEntry) {
/**
* Helps avoid iOS 12+ autofill strong password suggestion prompt
* Discussed in several circles but for example:
* https://github.com/expo/expo/issues/2571#issuecomment-473347380
*/
textField.secureTextEntry = true;
}
const delta = replacementString.length - range.length;
if (delta > 0) {
if (textField.text.length + delta > this.maxLength) {
return false;
}
}
public textFieldShouldChangeCharactersInRangeReplacementString(textField: UITextField, range: NSRange, replacementString: string): boolean {
if (this.secureWithoutAutofill && !textField.secureTextEntry) {
/**
* Helps avoid iOS 12+ autofill strong password suggestion prompt
* Discussed in several circles but for example:
* https://github.com/expo/expo/issues/2571#issuecomment-473347380
*/
textField.secureTextEntry = true;
}
const delta = replacementString.length - range.length;
if (delta > 0) {
if (textField.text.length + delta > this.maxLength) {
return false;
}
}
if (this.updateTextTrigger === "textChanged") {
if (textField.secureTextEntry && this.firstEdit) {
textProperty.nativeValueChange(this, replacementString);
} else {
if (range.location <= textField.text.length) {
const newText = NSString.stringWithString(
textField.text
).stringByReplacingCharactersInRangeWithString(
range,
replacementString
);
textProperty.nativeValueChange(this, newText);
}
}
}
if (this.updateTextTrigger === 'textChanged') {
if (textField.secureTextEntry && this.firstEdit) {
textProperty.nativeValueChange(this, replacementString);
} else {
if (range.location <= textField.text.length) {
const newText = NSString.stringWithString(textField.text).stringByReplacingCharactersInRangeWithString(range, replacementString);
textProperty.nativeValueChange(this, newText);
}
}
}
if (this.formattedText) {
_updateCharactersInRangeReplacementString(
this.formattedText,
range.location,
range.length,
replacementString
);
}
if (this.formattedText) {
_updateCharactersInRangeReplacementString(this.formattedText, range.location, range.length, replacementString);
}
this.firstEdit = false;
this.firstEdit = false;
return true;
}
return true;
}
[hintProperty.getDefault](): string {
return this.nativeTextViewProtected.placeholder;
}
[hintProperty.setNative](value: string) {
this._updateAttributedPlaceholder();
}
[hintProperty.getDefault](): string {
return this.nativeTextViewProtected.placeholder;
}
[hintProperty.setNative](value: string) {
this._updateAttributedPlaceholder();
}
[secureProperty.getDefault](): boolean {
return this.nativeTextViewProtected.secureTextEntry;
}
[secureProperty.setNative](value: boolean) {
this.nativeTextViewProtected.secureTextEntry = value;
}
[secureProperty.getDefault](): boolean {
return this.nativeTextViewProtected.secureTextEntry;
}
[secureProperty.setNative](value: boolean) {
this.nativeTextViewProtected.secureTextEntry = value;
}
[colorProperty.getDefault](): { textColor: UIColor; tintColor: UIColor } {
return {
textColor: this.nativeTextViewProtected.textColor,
tintColor: this.nativeTextViewProtected.tintColor,
};
}
[colorProperty.setNative](
value: Color | { textColor: UIColor; tintColor: UIColor }
) {
if (value instanceof Color) {
let color = value instanceof Color ? value.ios : value;
this.nativeTextViewProtected.textColor = color;
this.nativeTextViewProtected.tintColor = color;
} else {
this.nativeTextViewProtected.textColor = value.textColor;
this.nativeTextViewProtected.tintColor = value.tintColor;
}
}
[colorProperty.getDefault](): { textColor: UIColor; tintColor: UIColor } {
return {
textColor: this.nativeTextViewProtected.textColor,
tintColor: this.nativeTextViewProtected.tintColor,
};
}
[colorProperty.setNative](value: Color | { textColor: UIColor; tintColor: UIColor }) {
if (value instanceof Color) {
let color = value instanceof Color ? value.ios : value;
this.nativeTextViewProtected.textColor = color;
this.nativeTextViewProtected.tintColor = color;
} else {
this.nativeTextViewProtected.textColor = value.textColor;
this.nativeTextViewProtected.tintColor = value.tintColor;
}
}
[placeholderColorProperty.getDefault](): UIColor {
return null;
}
[placeholderColorProperty.setNative](value: UIColor | Color) {
this._updateAttributedPlaceholder();
}
[placeholderColorProperty.getDefault](): UIColor {
return null;
}
[placeholderColorProperty.setNative](value: UIColor | Color) {
this._updateAttributedPlaceholder();
}
_updateAttributedPlaceholder(): void {
let stringValue = this.hint;
if (stringValue === null || stringValue === void 0) {
stringValue = "";
} else {
stringValue = stringValue + "";
}
if (stringValue === "") {
// we do not use empty string since initWithStringAttributes does not return proper value and
// nativeView.attributedPlaceholder will be null
stringValue = " ";
}
const attributes: any = {};
if (this.style.placeholderColor) {
attributes[
NSForegroundColorAttributeName
] = this.style.placeholderColor.ios;
}
const attributedPlaceholder = NSAttributedString.alloc().initWithStringAttributes(
stringValue,
attributes
);
this.nativeTextViewProtected.attributedPlaceholder = attributedPlaceholder;
}
_updateAttributedPlaceholder(): void {
let stringValue = this.hint;
if (stringValue === null || stringValue === void 0) {
stringValue = '';
} else {
stringValue = stringValue + '';
}
if (stringValue === '') {
// we do not use empty string since initWithStringAttributes does not return proper value and
// nativeView.attributedPlaceholder will be null
stringValue = ' ';
}
const attributes: any = {};
if (this.style.placeholderColor) {
attributes[NSForegroundColorAttributeName] = this.style.placeholderColor.ios;
}
const attributedPlaceholder = NSAttributedString.alloc().initWithStringAttributes(stringValue, attributes);
this.nativeTextViewProtected.attributedPlaceholder = attributedPlaceholder;
}
[paddingTopProperty.getDefault](): Length {
return zeroLength;
}
[paddingTopProperty.setNative](value: Length) {
// Padding is realized via UITextFieldImpl.textRectForBounds method
}
[paddingTopProperty.getDefault](): Length {
return zeroLength;
}
[paddingTopProperty.setNative](value: Length) {
// Padding is realized via UITextFieldImpl.textRectForBounds method
}
[paddingRightProperty.getDefault](): Length {
return zeroLength;
}
[paddingRightProperty.setNative](value: Length) {
// Padding is realized via UITextFieldImpl.textRectForBounds method
}
[paddingRightProperty.getDefault](): Length {
return zeroLength;
}
[paddingRightProperty.setNative](value: Length) {
// Padding is realized via UITextFieldImpl.textRectForBounds method
}
[paddingBottomProperty.getDefault](): Length {
return zeroLength;
}
[paddingBottomProperty.setNative](value: Length) {
// Padding is realized via UITextFieldImpl.textRectForBounds method
}
[paddingBottomProperty.getDefault](): Length {
return zeroLength;
}
[paddingBottomProperty.setNative](value: Length) {
// Padding is realized via UITextFieldImpl.textRectForBounds method
}
[paddingLeftProperty.getDefault](): Length {
return zeroLength;
}
[paddingLeftProperty.setNative](value: Length) {
// Padding is realized via UITextFieldImpl.textRectForBounds method
}
[paddingLeftProperty.getDefault](): Length {
return zeroLength;
}
[paddingLeftProperty.setNative](value: Length) {
// Padding is realized via UITextFieldImpl.textRectForBounds method
}
}

View File

@@ -1,31 +1,30 @@
import { TextField as TextFieldDefinition } from ".";
import { EditableTextBase } from "../editable-text-base";
import { Property } from "../core/properties";
import { CSSType } from "../core/view";
import { booleanConverter } from "../core/view-base";
import { TextField as TextFieldDefinition } from '.';
import { EditableTextBase } from '../editable-text-base';
import { Property } from '../core/properties';
import { CSSType } from '../core/view';
import { booleanConverter } from '../core/view-base';
@CSSType("TextField")
export class TextFieldBase extends EditableTextBase
implements TextFieldDefinition {
public static returnPressEvent = "returnPress";
public secure: boolean;
public closeOnReturn: boolean;
// iOS only (to avoid 12+ suggested strong password handling)
public secureWithoutAutofill: boolean;
@CSSType('TextField')
export class TextFieldBase extends EditableTextBase implements TextFieldDefinition {
public static returnPressEvent = 'returnPress';
public secure: boolean;
public closeOnReturn: boolean;
// iOS only (to avoid 12+ suggested strong password handling)
public secureWithoutAutofill: boolean;
}
TextFieldBase.prototype.recycleNativeView = "auto";
TextFieldBase.prototype.recycleNativeView = 'auto';
export const secureProperty = new Property<TextFieldBase, boolean>({
name: "secure",
defaultValue: false,
valueConverter: booleanConverter,
name: 'secure',
defaultValue: false,
valueConverter: booleanConverter,
});
secureProperty.register(TextFieldBase);
export const closeOnReturnProperty = new Property<TextFieldBase, boolean>({
name: "closeOnReturn",
defaultValue: true,
valueConverter: booleanConverter,
name: 'closeOnReturn',
defaultValue: true,
valueConverter: booleanConverter,
});
closeOnReturnProperty.register(TextFieldBase);