mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
Resolved #147: Add autocorrect property to TextField and TextView.
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
<StackLayout id="stack">
|
<StackLayout id="stack">
|
||||||
<Button id="button" text="textChanged" height="100" margin="20" tap="onTap" backgroundColor="Red"/>
|
<Button id="button" text="textChanged" height="100" margin="20" tap="onTap" backgroundColor="Red"/>
|
||||||
<Label id="label" text="{{ text }}" height="100" margin="20"/>
|
<Label id="label" text="{{ text }}" height="100" margin="20"/>
|
||||||
<TextField id="textField" text="{{ text }}" margin="20" autocapitalizationType="none"/>
|
<TextField id="textField" text="{{ text }}" margin="20" autocapitalizationType="none" autocorrect="false"/>
|
||||||
<TextView id="textView" text="{{ text }}" height="100" margin="20" autocapitalizationType="none"/>
|
<TextView id="textView" text="{{ text }}" height="100" margin="20" autocapitalizationType="none" autocorrect="false"/>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
</Page>
|
</Page>
|
@ -34,6 +34,12 @@ var autocapitalizationTypeProperty = new dependencyObservable.Property(
|
|||||||
new proxy.PropertyMetadata(enums.AutocapitalizationType.sentences, dependencyObservable.PropertyMetadataSettings.None)
|
new proxy.PropertyMetadata(enums.AutocapitalizationType.sentences, dependencyObservable.PropertyMetadataSettings.None)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
var autocorrectProperty = new dependencyObservable.Property(
|
||||||
|
"autocorrect",
|
||||||
|
"EditableTextBase",
|
||||||
|
new proxy.PropertyMetadata(undefined, dependencyObservable.PropertyMetadataSettings.None)
|
||||||
|
);
|
||||||
|
|
||||||
function onKeyboardTypePropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
function onKeyboardTypePropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
var editableTextBase = <EditableTextBase>data.object;
|
var editableTextBase = <EditableTextBase>data.object;
|
||||||
editableTextBase._onKeyboardTypePropertyChanged(data);
|
editableTextBase._onKeyboardTypePropertyChanged(data);
|
||||||
@ -62,6 +68,13 @@ function onAutocapitalizationTypePropertyChanged(data: dependencyObservable.Prop
|
|||||||
|
|
||||||
(<proxy.PropertyMetadata>autocapitalizationTypeProperty.metadata).onSetNativeValue = onAutocapitalizationTypePropertyChanged;
|
(<proxy.PropertyMetadata>autocapitalizationTypeProperty.metadata).onSetNativeValue = onAutocapitalizationTypePropertyChanged;
|
||||||
|
|
||||||
|
function onAutocorrectPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
|
var editableTextBase = <EditableTextBase>data.object;
|
||||||
|
editableTextBase._onAutocorrectPropertyChanged(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
(<proxy.PropertyMetadata>autocorrectProperty.metadata).onSetNativeValue = onAutocorrectPropertyChanged;
|
||||||
|
|
||||||
export class EditableTextBase extends textBase.TextBase implements definition.EditableTextBase {
|
export class EditableTextBase extends textBase.TextBase implements definition.EditableTextBase {
|
||||||
|
|
||||||
public static keyboardTypeProperty = keyboardTypeProperty;
|
public static keyboardTypeProperty = keyboardTypeProperty;
|
||||||
@ -74,6 +87,8 @@ export class EditableTextBase extends textBase.TextBase implements definition.Ed
|
|||||||
|
|
||||||
public static autocapitalizationTypeProperty = autocapitalizationTypeProperty;
|
public static autocapitalizationTypeProperty = autocapitalizationTypeProperty;
|
||||||
|
|
||||||
|
public static autocorrectProperty = autocorrectProperty;
|
||||||
|
|
||||||
constructor(options?: definition.Options) {
|
constructor(options?: definition.Options) {
|
||||||
super(options);
|
super(options);
|
||||||
}
|
}
|
||||||
@ -118,6 +133,14 @@ export class EditableTextBase extends textBase.TextBase implements definition.Ed
|
|||||||
this._setValue(EditableTextBase.autocapitalizationTypeProperty, value);
|
this._setValue(EditableTextBase.autocapitalizationTypeProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get autocorrect(): boolean {
|
||||||
|
return this._getValue(EditableTextBase.autocorrectProperty);
|
||||||
|
}
|
||||||
|
|
||||||
|
set autocorrect(value: boolean) {
|
||||||
|
this._setValue(EditableTextBase.autocorrectProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
public dismissSoftInput() {
|
public dismissSoftInput() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
@ -138,4 +161,8 @@ export class EditableTextBase extends textBase.TextBase implements definition.Ed
|
|||||||
public _onAutocapitalizationTypePropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
public _onAutocapitalizationTypePropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public _onAutocorrectPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
|
//
|
||||||
|
}
|
||||||
}
|
}
|
@ -212,4 +212,34 @@ export class EditableTextBase extends common.EditableTextBase {
|
|||||||
|
|
||||||
editableTextBase.android.setInputType(inputType);
|
editableTextBase.android.setInputType(inputType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public _onAutocorrectPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
|
var editableTextBase = <EditableTextBase>data.object;
|
||||||
|
if (!editableTextBase.android) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var inputType = editableTextBase.android.getInputType();
|
||||||
|
console.log("BEFORE: " + inputType);
|
||||||
|
|
||||||
|
switch (data.newValue) {
|
||||||
|
case true:
|
||||||
|
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;
|
||||||
|
break;
|
||||||
|
case false:
|
||||||
|
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;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// We can't do anything.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
editableTextBase.android.setInputType(inputType);
|
||||||
|
console.log("AFTER: " + inputType);
|
||||||
|
}
|
||||||
}
|
}
|
12
ui/editable-text-base/editable-text-base.d.ts
vendored
12
ui/editable-text-base/editable-text-base.d.ts
vendored
@ -11,6 +11,7 @@
|
|||||||
public static editableProperty: dependencyObservable.Property;
|
public static editableProperty: dependencyObservable.Property;
|
||||||
public static updateTextTriggerProperty: dependencyObservable.Property;
|
public static updateTextTriggerProperty: dependencyObservable.Property;
|
||||||
public static autocapitalizationTypeProperty: dependencyObservable.Property;
|
public static autocapitalizationTypeProperty: dependencyObservable.Property;
|
||||||
|
public static autocorrectProperty: dependencyObservable.Property;
|
||||||
|
|
||||||
constructor(options?: Options);
|
constructor(options?: Options);
|
||||||
|
|
||||||
@ -40,6 +41,11 @@
|
|||||||
*/
|
*/
|
||||||
autocapitalizationType: string;
|
autocapitalizationType: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables or disables autocorrection.
|
||||||
|
*/
|
||||||
|
autocorrect: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hides the soft input method, ususally a soft keyboard.
|
* Hides the soft input method, ususally a soft keyboard.
|
||||||
*/
|
*/
|
||||||
@ -67,7 +73,6 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets or sets a value indicating when the text property will be updated.
|
* Gets or sets a value indicating when the text property will be updated.
|
||||||
* Possible values are contained in the UpdateTextTrigger enumeration located in "ui/enums" module.
|
|
||||||
*/
|
*/
|
||||||
updateTextTrigger?: string;
|
updateTextTrigger?: string;
|
||||||
|
|
||||||
@ -75,5 +80,10 @@
|
|||||||
* Gets or sets the autocapitalization type.
|
* Gets or sets the autocapitalization type.
|
||||||
*/
|
*/
|
||||||
autocapitalizationType?: string;
|
autocapitalizationType?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables or disables autocorrection.
|
||||||
|
*/
|
||||||
|
autocorrect?: boolean;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,7 +13,7 @@ export class EditableTextBase extends common.EditableTextBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public _onKeyboardTypePropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
public _onKeyboardTypePropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
var newKeyboardType;
|
var newKeyboardType: UIKeyboardType;
|
||||||
switch (data.newValue) {
|
switch (data.newValue) {
|
||||||
case enums.KeyboardType.datetime:
|
case enums.KeyboardType.datetime:
|
||||||
newKeyboardType = UIKeyboardType.UIKeyboardTypeNumbersAndPunctuation;
|
newKeyboardType = UIKeyboardType.UIKeyboardTypeNumbersAndPunctuation;
|
||||||
@ -39,33 +39,33 @@ export class EditableTextBase extends common.EditableTextBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public _onReturnKeyTypePropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
public _onReturnKeyTypePropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
var newReturnKeyType;
|
var newValue;
|
||||||
switch (data.newValue) {
|
switch (data.newValue) {
|
||||||
case enums.ReturnKeyType.done:
|
case enums.ReturnKeyType.done:
|
||||||
newReturnKeyType = UIReturnKeyType.UIReturnKeyDone;
|
newValue = UIReturnKeyType.UIReturnKeyDone;
|
||||||
break;
|
break;
|
||||||
case enums.ReturnKeyType.go:
|
case enums.ReturnKeyType.go:
|
||||||
newReturnKeyType = UIReturnKeyType.UIReturnKeyGo;
|
newValue = UIReturnKeyType.UIReturnKeyGo;
|
||||||
break;
|
break;
|
||||||
case enums.ReturnKeyType.next:
|
case enums.ReturnKeyType.next:
|
||||||
newReturnKeyType = UIReturnKeyType.UIReturnKeyNext;
|
newValue = UIReturnKeyType.UIReturnKeyNext;
|
||||||
break;
|
break;
|
||||||
case enums.ReturnKeyType.search:
|
case enums.ReturnKeyType.search:
|
||||||
newReturnKeyType = UIReturnKeyType.UIReturnKeySearch;
|
newValue = UIReturnKeyType.UIReturnKeySearch;
|
||||||
break;
|
break;
|
||||||
case enums.ReturnKeyType.send:
|
case enums.ReturnKeyType.send:
|
||||||
newReturnKeyType = UIReturnKeyType.UIReturnKeySend;
|
newValue = UIReturnKeyType.UIReturnKeySend;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
newReturnKeyType = UIReturnKeyType.UIReturnKeyDefault;
|
newValue = UIReturnKeyType.UIReturnKeyDefault;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
(<UITextInputTraits>this.ios).returnKeyType = newReturnKeyType;
|
(<UITextInputTraits>this.ios).returnKeyType = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public _onAutocapitalizationTypePropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
public _onAutocapitalizationTypePropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
var newValue;
|
var newValue: UITextAutocapitalizationType;
|
||||||
switch (data.newValue) {
|
switch (data.newValue) {
|
||||||
case enums.AutocapitalizationType.none:
|
case enums.AutocapitalizationType.none:
|
||||||
newValue = UITextAutocapitalizationType.UITextAutocapitalizationTypeNone;
|
newValue = UITextAutocapitalizationType.UITextAutocapitalizationTypeNone;
|
||||||
@ -86,4 +86,24 @@ export class EditableTextBase extends common.EditableTextBase {
|
|||||||
|
|
||||||
(<UITextInputTraits>this.ios).autocapitalizationType = newValue;
|
(<UITextInputTraits>this.ios).autocapitalizationType = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public _onAutocorrectPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
|
console.log("BEFORE: " + (<UITextInputTraits>this.ios).autocorrectionType);
|
||||||
|
|
||||||
|
var newValue: UITextAutocorrectionType;
|
||||||
|
switch (data.newValue) {
|
||||||
|
case true:
|
||||||
|
newValue = UITextAutocorrectionType.UITextAutocorrectionTypeYes;
|
||||||
|
break;
|
||||||
|
case false:
|
||||||
|
newValue = UITextAutocorrectionType.UITextAutocorrectionTypeNo;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
newValue = UITextAutocorrectionType.UITextAutocorrectionTypeDefault;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
(<UITextInputTraits>this.ios).autocorrectionType = newValue;
|
||||||
|
console.log("AFTER: " + (<UITextInputTraits>this.ios).autocorrectionType);
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user