rename clickable to tappable in Span

This commit is contained in:
Eduardo Speroni
2019-05-06 20:20:03 -03:00
parent cca70cc49f
commit 8fc42ff917
6 changed files with 29 additions and 29 deletions

View File

@@ -44,6 +44,6 @@ export function loadExamples() {
examples.set("background-shorthand", "css/background-shorthand");
examples.set("background-image-linear-gradient", "css/background-image-linear-gradient");
examples.set("background-image", "css/background-image");
examples.set("clickable-span", "css/clickable-span");
examples.set("tappable-span", "css/tappable-span");
return examples;
}

View File

@@ -5,9 +5,9 @@
<FormattedString>
<FormattedString.spans>
<Span text="The quick brown " style="font-weight: bold; color: green;" />
<Span text="fox" style="font-weight: italic; color: green;" linkClick="foxTap"/>
<Span text="fox" style="font-weight: italic; color: green;" linkTap="foxTap"/>
<Span text=" jumps over the lazy " style="font-weight: bold; color: red;" />
<Span text="dog" style="font-weight: bold; color: blue;" linkClick="dogTap"/>
<Span text="dog" style="font-weight: bold; color: blue;" linkTap="dogTap"/>
<Span text="." style="font-weight: bold; color: green;" />
</FormattedString.spans>
</FormattedString>

View File

@@ -52,14 +52,14 @@ export class Span extends ViewBase {
public text: string;
/**
* String value used when hooking to linkClicked event.
* String value used when hooking to linkTap event.
*/
public static linkClickedEvent: string;
public static linkTapEvent: string;
/**
* Gets if the span is clickable or not.
* Gets if the span is tappable or not.
*/
public readonly clickable: boolean;
public readonly tappable: boolean;
//@private
/**

View File

@@ -5,9 +5,9 @@ import { FontStyle, FontWeight, } from "../ui/styling/font";
import { TextDecoration, EventData } from "../ui/text-base";
export class Span extends ViewBase implements SpanDefinition {
static linkClickEvent = "linkClick";
static linkTapEvent = "linkTap";
private _text: string;
private _clickable: boolean = false;
private _tappable: boolean = false;
get fontFamily(): string {
return this.style.fontFamily;
@@ -70,28 +70,28 @@ export class Span extends ViewBase implements SpanDefinition {
}
}
get clickable(): boolean {
return this._clickable;
get tappable(): boolean {
return this._tappable;
}
addEventListener(arg: string, callback: (data: EventData) => void, thisArg?: any) {
super.addEventListener(arg, callback, thisArg);
this._setClickable(this.hasListeners(Span.linkClickEvent));
this._setTappable(this.hasListeners(Span.linkTapEvent));
}
removeEventListener(arg: string, callback?: any, thisArg?: any) {
super.removeEventListener(arg, callback, thisArg);
this._setClickable(this.hasListeners(Span.linkClickEvent));
this._setTappable(this.hasListeners(Span.linkTapEvent));
}
_setTextInternal(value: string): void {
this._text = value;
}
private _setClickable(value: boolean): void {
if (this._clickable !== value) {
this._clickable = value;
this.notifyPropertyChange("clickable", value);
private _setTappable(value: boolean): void {
if (this._tappable !== value) {
this._tappable = value;
this.notifyPropertyChange("tappable", value);
}
}
}

View File

@@ -72,7 +72,7 @@ function initializeClickableSpan(): void {
onClick(view: android.view.View): void {
const owner = this.owner.get();
if (owner) {
owner._emit(Span.linkClickEvent);
owner._emit(Span.linkTapEvent);
}
view.clearFocus();
view.invalidate();
@@ -94,7 +94,7 @@ export class TextBase extends TextBaseCommon {
private _maxHeight: number;
private _minLines: number;
private _maxLines: number;
private _clickable: boolean = false;
private _tappable: boolean = false;
private _defaultMovementMethod: android.text.method.MovementMethod;
public initNativeView(): void {
@@ -148,7 +148,7 @@ export class TextBase extends TextBaseCommon {
if (!reset && this.formattedText) {
return;
}
this._setClickableState(false);
this._setTappableState(false);
this._setNativeText(reset);
}
@@ -169,7 +169,7 @@ export class TextBase extends TextBaseCommon {
const spannableStringBuilder = createSpannableStringBuilder(value);
nativeView.setText(<any>spannableStringBuilder);
this._setClickableState(isStringClickable(value));
this._setTappableState(isStringTappable(value));
textProperty.nativeValueChange(this, (value === null || value === undefined) ? "" : value.toString());
@@ -353,10 +353,10 @@ export class TextBase extends TextBaseCommon {
this.nativeTextViewProtected.setText(<any>transformedText);
}
_setClickableState(clickable: boolean) {
if (this._clickable !== clickable) {
this._clickable = clickable;
if (this._clickable) {
_setTappableState(tappable: boolean) {
if (this._tappable !== tappable) {
this._tappable = tappable;
if (this._tappable) {
this.nativeViewProtected.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
this.nativeViewProtected.setHighlightColor(null);
}
@@ -396,13 +396,13 @@ export function getTransformedText(text: string, textTransform: TextTransform):
}
}
function isStringClickable(formattedString: FormattedString) {
function isStringTappable(formattedString: FormattedString) {
if (!formattedString) {
return false;
}
for (let i = 0, length = formattedString.spans.length; i < length; i++) {
const span = formattedString.spans.getItem(i);
if (span.clickable) {
if (span.tappable) {
return true;
}
}
@@ -507,8 +507,8 @@ function setSpanModifiers(ssb: android.text.SpannableStringBuilder, span: Span,
}
}
const clickable = span.clickable;
if (clickable) {
const tappable = span.tappable;
if (tappable) {
initializeClickableSpan();
ssb.setSpan(new ClickableSpan(span), start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}