mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
Merge pull request #1071 from NativeScript/textview-delegate
TextView delegate improved
This commit is contained in:
@ -8,42 +8,52 @@ global.moduleMerge(common, exports);
|
|||||||
class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate {
|
class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate {
|
||||||
public static ObjCProtocols = [UITextViewDelegate];
|
public static ObjCProtocols = [UITextViewDelegate];
|
||||||
|
|
||||||
static new(): UITextViewDelegateImpl {
|
private _owner: WeakRef<TextView>;
|
||||||
return <UITextViewDelegateImpl>super.new();
|
|
||||||
}
|
|
||||||
|
|
||||||
private _owner: TextView;
|
public static initWithOwner(owner: WeakRef<TextView>): UITextViewDelegateImpl {
|
||||||
|
let impl = <UITextViewDelegateImpl>UITextViewDelegateImpl.new();
|
||||||
public initWithOwner(owner: TextView): UITextViewDelegateImpl {
|
impl._owner = owner;
|
||||||
this._owner = owner;
|
return impl;
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public textViewShouldBeginEditing(textView: UITextView): boolean {
|
public textViewShouldBeginEditing(textView: UITextView): boolean {
|
||||||
this._owner._hideHint();
|
let owner = this._owner.get();
|
||||||
|
if (owner) {
|
||||||
|
owner._hideHint();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public textViewDidBeginEditing(textView: UITextView) {
|
public textViewDidBeginEditing(textView: UITextView) {
|
||||||
this._owner.style._updateTextDecoration();
|
let owner = this._owner.get();
|
||||||
|
if (owner) {
|
||||||
|
owner.style._updateTextDecoration();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public textViewDidEndEditing(textView: UITextView) {
|
public textViewDidEndEditing(textView: UITextView) {
|
||||||
if (this._owner.updateTextTrigger === enums.UpdateTextTrigger.focusLost) {
|
let owner = this._owner.get();
|
||||||
this._owner._onPropertyChangedFromNative(textBase.TextBase.textProperty, textView.text);
|
if (owner) {
|
||||||
|
if (owner.updateTextTrigger === enums.UpdateTextTrigger.focusLost) {
|
||||||
|
owner._onPropertyChangedFromNative(textBase.TextBase.textProperty, textView.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._owner.dismissSoftInput();
|
owner.dismissSoftInput();
|
||||||
this._owner._refreshHintState(this._owner.hint, textView.text);
|
owner._refreshHintState(owner.hint, textView.text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public textViewDidChange(textView: UITextView) {
|
public textViewDidChange(textView: UITextView) {
|
||||||
|
let owner = this._owner.get();
|
||||||
|
if (owner) {
|
||||||
var range = textView.selectedRange;
|
var range = textView.selectedRange;
|
||||||
this._owner.style._updateTextDecoration();
|
owner.style._updateTextDecoration();
|
||||||
textView.selectedRange = range;
|
textView.selectedRange = range;
|
||||||
|
|
||||||
if (this._owner.updateTextTrigger === enums.UpdateTextTrigger.textChanged) {
|
if (owner.updateTextTrigger === enums.UpdateTextTrigger.textChanged) {
|
||||||
this._owner._onPropertyChangedFromNative(textBase.TextBase.textProperty, textView.text);
|
owner._onPropertyChangedFromNative(textBase.TextBase.textProperty, textView.text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,7 +69,7 @@ export class TextView extends common.TextView {
|
|||||||
if (!this._ios.font) {
|
if (!this._ios.font) {
|
||||||
this._ios.font = UIFont.systemFontOfSize(12);
|
this._ios.font = UIFont.systemFontOfSize(12);
|
||||||
}
|
}
|
||||||
this._delegate = UITextViewDelegateImpl.new().initWithOwner(this);
|
this._delegate = UITextViewDelegateImpl.initWithOwner(new WeakRef(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public onLoaded() {
|
public onLoaded() {
|
||||||
|
Reference in New Issue
Block a user