mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
feat(text-view): allow easy subclassing on ios (#8663)
This commit is contained in:
@ -30,7 +30,7 @@ class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate {
|
|||||||
public textViewShouldBeginEditing(textView: UITextView): boolean {
|
public textViewShouldBeginEditing(textView: UITextView): boolean {
|
||||||
const owner = this._owner.get();
|
const owner = this._owner.get();
|
||||||
if (owner) {
|
if (owner) {
|
||||||
owner.showText();
|
return owner.textViewShouldBeginEditing(textView);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -39,47 +39,28 @@ class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate {
|
|||||||
public textViewDidBeginEditing(textView: UITextView): void {
|
public textViewDidBeginEditing(textView: UITextView): void {
|
||||||
const owner = this._owner.get();
|
const owner = this._owner.get();
|
||||||
if (owner) {
|
if (owner) {
|
||||||
owner._isEditing = true;
|
owner.textViewDidBeginEditing(textView);
|
||||||
owner.notify({ eventName: TextView.focusEvent, object: owner });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public textViewDidEndEditing(textView: UITextView) {
|
public textViewDidEndEditing(textView: UITextView): void {
|
||||||
const owner = this._owner.get();
|
const owner = this._owner.get();
|
||||||
if (owner) {
|
if (owner) {
|
||||||
if (owner.updateTextTrigger === "focusLost") {
|
owner.textViewDidEndEditing(textView);
|
||||||
textProperty.nativeValueChange(owner, textView.text);
|
|
||||||
}
|
|
||||||
|
|
||||||
owner._isEditing = false;
|
|
||||||
owner.dismissSoftInput();
|
|
||||||
owner._refreshHintState(owner.hint, textView.text);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public textViewDidChange(textView: UITextView) {
|
public textViewDidChange(textView: UITextView): void {
|
||||||
const owner = this._owner.get();
|
const owner = this._owner.get();
|
||||||
if (owner) {
|
if (owner) {
|
||||||
if (owner.updateTextTrigger === "textChanged") {
|
owner.textViewDidChange(textView);
|
||||||
textProperty.nativeValueChange(owner, textView.text);
|
|
||||||
}
|
|
||||||
owner.requestLayout();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public textViewShouldChangeTextInRangeReplacementText(textView: UITextView, range: NSRange, replacementString: string): boolean {
|
public textViewShouldChangeTextInRangeReplacementText(textView: UITextView, range: NSRange, replacementString: string): boolean {
|
||||||
const owner = this._owner.get();
|
const owner = this._owner.get();
|
||||||
if (owner) {
|
if (owner) {
|
||||||
const delta = replacementString.length - range.length;
|
return owner.textViewShouldChangeTextInRangeReplacementText(textView, range, replacementString);
|
||||||
if (delta > 0) {
|
|
||||||
if (textView.text.length + delta > owner.maxLength) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (owner.formattedText) {
|
|
||||||
_updateCharactersInRangeReplacementString(owner.formattedText, range.location, range.length, replacementString);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -88,13 +69,7 @@ class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate {
|
|||||||
public scrollViewDidScroll(sv: UIScrollView): void {
|
public scrollViewDidScroll(sv: UIScrollView): void {
|
||||||
const owner = this._owner.get();
|
const owner = this._owner.get();
|
||||||
if (owner) {
|
if (owner) {
|
||||||
const contentOffset = owner.nativeViewProtected.contentOffset;
|
return owner.scrollViewDidScroll(sv);
|
||||||
owner.notify(<ScrollEventData>{
|
|
||||||
object: owner,
|
|
||||||
eventName: "scroll",
|
|
||||||
scrollX: contentOffset.x,
|
|
||||||
scrollY: contentOffset.y
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,6 +128,59 @@ export class TextView extends TextViewBaseCommon {
|
|||||||
return this.nativeViewProtected;
|
return this.nativeViewProtected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public textViewShouldBeginEditing(textView: UITextView): boolean {
|
||||||
|
this.showText();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public textViewDidBeginEditing(textView: UITextView): void {
|
||||||
|
this._isEditing = true;
|
||||||
|
this.notify({ eventName: TextView.focusEvent, object: this });
|
||||||
|
}
|
||||||
|
|
||||||
|
public textViewDidEndEditing(textView: UITextView): void {
|
||||||
|
if (this.updateTextTrigger === "focusLost") {
|
||||||
|
textProperty.nativeValueChange(this, textView.text);
|
||||||
|
}
|
||||||
|
|
||||||
|
this._isEditing = false;
|
||||||
|
this.dismissSoftInput();
|
||||||
|
this._refreshHintState(this.hint, textView.text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public textViewDidChange(textView: UITextView): void {
|
||||||
|
if (this.updateTextTrigger === "textChanged") {
|
||||||
|
textProperty.nativeValueChange(this, textView.text);
|
||||||
|
}
|
||||||
|
this.requestLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
public textViewShouldChangeTextInRangeReplacementText(textView: UITextView, range: NSRange, replacementString: string): boolean {
|
||||||
|
const delta = replacementString.length - range.length;
|
||||||
|
if (delta > 0) {
|
||||||
|
if (textView.text.length + delta > this.maxLength) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.formattedText) {
|
||||||
|
_updateCharactersInRangeReplacementString(this.formattedText, range.location, range.length, replacementString);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public scrollViewDidScroll(sv: UIScrollView): void {
|
||||||
|
const contentOffset = this.nativeViewProtected.contentOffset;
|
||||||
|
this.notify(<ScrollEventData>{
|
||||||
|
object: this,
|
||||||
|
eventName: "scroll",
|
||||||
|
scrollX: contentOffset.x,
|
||||||
|
scrollY: contentOffset.y
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public _refreshHintState(hint: string, text: string) {
|
public _refreshHintState(hint: string, text: string) {
|
||||||
if (this.formattedText) {
|
if (this.formattedText) {
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user