Resolved #147: Add autocorrect property to TextField and TextView.

This commit is contained in:
Rossen Hristov
2015-03-10 13:12:12 +02:00
parent f0380c04ef
commit 014182b376
5 changed files with 100 additions and 13 deletions

View File

@ -2,7 +2,7 @@
<StackLayout id="stack">
<Button id="button" text="textChanged" height="100" margin="20" tap="onTap" backgroundColor="Red"/>
<Label id="label" text="{{ text }}" height="100" margin="20"/>
<TextField id="textField" text="{{ text }}" margin="20" autocapitalizationType="none"/>
<TextView id="textView" text="{{ text }}" height="100" 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" autocorrect="false"/>
</StackLayout>
</Page>

View File

@ -34,6 +34,12 @@ var autocapitalizationTypeProperty = new dependencyObservable.Property(
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) {
var editableTextBase = <EditableTextBase>data.object;
editableTextBase._onKeyboardTypePropertyChanged(data);
@ -62,6 +68,13 @@ function onAutocapitalizationTypePropertyChanged(data: dependencyObservable.Prop
(<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 {
public static keyboardTypeProperty = keyboardTypeProperty;
@ -74,6 +87,8 @@ export class EditableTextBase extends textBase.TextBase implements definition.Ed
public static autocapitalizationTypeProperty = autocapitalizationTypeProperty;
public static autocorrectProperty = autocorrectProperty;
constructor(options?: definition.Options) {
super(options);
}
@ -118,6 +133,14 @@ export class EditableTextBase extends textBase.TextBase implements definition.Ed
this._setValue(EditableTextBase.autocapitalizationTypeProperty, value);
}
get autocorrect(): boolean {
return this._getValue(EditableTextBase.autocorrectProperty);
}
set autocorrect(value: boolean) {
this._setValue(EditableTextBase.autocorrectProperty, value);
}
public dismissSoftInput() {
//
}
@ -138,4 +161,8 @@ export class EditableTextBase extends textBase.TextBase implements definition.Ed
public _onAutocapitalizationTypePropertyChanged(data: dependencyObservable.PropertyChangeData) {
//
}
public _onAutocorrectPropertyChanged(data: dependencyObservable.PropertyChangeData) {
//
}
}

View File

@ -212,4 +212,34 @@ export class EditableTextBase extends common.EditableTextBase {
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);
}
}

View File

@ -11,6 +11,7 @@
public static editableProperty: dependencyObservable.Property;
public static updateTextTriggerProperty: dependencyObservable.Property;
public static autocapitalizationTypeProperty: dependencyObservable.Property;
public static autocorrectProperty: dependencyObservable.Property;
constructor(options?: Options);
@ -40,6 +41,11 @@
*/
autocapitalizationType: string;
/**
* Enables or disables autocorrection.
*/
autocorrect: boolean;
/**
* 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.
* Possible values are contained in the UpdateTextTrigger enumeration located in "ui/enums" module.
*/
updateTextTrigger?: string;
@ -75,5 +80,10 @@
* Gets or sets the autocapitalization type.
*/
autocapitalizationType?: string;
/**
* Enables or disables autocorrection.
*/
autocorrect?: boolean;
}
}

View File

@ -13,7 +13,7 @@ export class EditableTextBase extends common.EditableTextBase {
}
public _onKeyboardTypePropertyChanged(data: dependencyObservable.PropertyChangeData) {
var newKeyboardType;
var newKeyboardType: UIKeyboardType;
switch (data.newValue) {
case enums.KeyboardType.datetime:
newKeyboardType = UIKeyboardType.UIKeyboardTypeNumbersAndPunctuation;
@ -39,33 +39,33 @@ export class EditableTextBase extends common.EditableTextBase {
}
public _onReturnKeyTypePropertyChanged(data: dependencyObservable.PropertyChangeData) {
var newReturnKeyType;
var newValue;
switch (data.newValue) {
case enums.ReturnKeyType.done:
newReturnKeyType = UIReturnKeyType.UIReturnKeyDone;
newValue = UIReturnKeyType.UIReturnKeyDone;
break;
case enums.ReturnKeyType.go:
newReturnKeyType = UIReturnKeyType.UIReturnKeyGo;
newValue = UIReturnKeyType.UIReturnKeyGo;
break;
case enums.ReturnKeyType.next:
newReturnKeyType = UIReturnKeyType.UIReturnKeyNext;
newValue = UIReturnKeyType.UIReturnKeyNext;
break;
case enums.ReturnKeyType.search:
newReturnKeyType = UIReturnKeyType.UIReturnKeySearch;
newValue = UIReturnKeyType.UIReturnKeySearch;
break;
case enums.ReturnKeyType.send:
newReturnKeyType = UIReturnKeyType.UIReturnKeySend;
newValue = UIReturnKeyType.UIReturnKeySend;
break;
default:
newReturnKeyType = UIReturnKeyType.UIReturnKeyDefault;
newValue = UIReturnKeyType.UIReturnKeyDefault;
break;
}
(<UITextInputTraits>this.ios).returnKeyType = newReturnKeyType;
(<UITextInputTraits>this.ios).returnKeyType = newValue;
}
public _onAutocapitalizationTypePropertyChanged(data: dependencyObservable.PropertyChangeData) {
var newValue;
var newValue: UITextAutocapitalizationType;
switch (data.newValue) {
case enums.AutocapitalizationType.none:
newValue = UITextAutocapitalizationType.UITextAutocapitalizationTypeNone;
@ -86,4 +86,24 @@ export class EditableTextBase extends common.EditableTextBase {
(<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);
}
}