mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-14 18:12:09 +08:00
feat(ios): allow disabling text animations (#10505)
This commit is contained in:
10
packages/core/ui/text-base/index.d.ts
vendored
10
packages/core/ui/text-base/index.d.ts
vendored
@ -99,6 +99,16 @@ export class TextBase extends View implements AddChildFromBuilder {
|
|||||||
*/
|
*/
|
||||||
paddingTop: CoreTypes.LengthType;
|
paddingTop: CoreTypes.LengthType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify wether the native text should be applied with or without animations
|
||||||
|
*/
|
||||||
|
iosTextAnimation: 'inherit' | boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The value used when the iosTextAnimation is set to 'inherit'
|
||||||
|
*/
|
||||||
|
static iosTextAnimationFallback: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called for every child element declared in xml.
|
* Called for every child element declared in xml.
|
||||||
* This method will add a child element (value) to current element.
|
* This method will add a child element (value) to current element.
|
||||||
|
@ -291,8 +291,17 @@ export class TextBase extends TextBaseCommon {
|
|||||||
this.nativeTextViewProtected.textColor = color;
|
this.nativeTextViewProtected.textColor = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_animationWrap(fn: () => void) {
|
||||||
|
const shouldAnimate = this.iosTextAnimation === 'inherit' ? TextBase.iosTextAnimationFallback : this.iosTextAnimation;
|
||||||
|
if (shouldAnimate) {
|
||||||
|
fn();
|
||||||
|
} else {
|
||||||
|
UIView.performWithoutAnimation(fn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_setNativeText(reset = false): void {
|
_setNativeText(reset = false): void {
|
||||||
|
this._animationWrap(() => {
|
||||||
if (reset) {
|
if (reset) {
|
||||||
const nativeView = this.nativeTextViewProtected;
|
const nativeView = this.nativeTextViewProtected;
|
||||||
if (nativeView instanceof UIButton) {
|
if (nativeView instanceof UIButton) {
|
||||||
@ -324,6 +333,7 @@ export class TextBase extends TextBaseCommon {
|
|||||||
if (this.style?.textStroke) {
|
if (this.style?.textStroke) {
|
||||||
this.nativeTextViewProtected.nativeScriptSetFormattedTextStrokeColor(Length.toDevicePixels(this.style.textStroke.width, 0), this.style.textStroke.color.ios);
|
this.nativeTextViewProtected.nativeScriptSetFormattedTextStrokeColor(Length.toDevicePixels(this.style.textStroke.width, 0), this.style.textStroke.color.ios);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
createFormattedTextNative(value: FormattedString) {
|
createFormattedTextNative(value: FormattedString) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// Types
|
// Types
|
||||||
import { PropertyChangeData } from '../../data/observable';
|
import { PropertyChangeData } from '../../data/observable';
|
||||||
import { ViewBase } from '../core/view-base';
|
import { ViewBase, booleanConverter } from '../core/view-base';
|
||||||
import { FontStyleType, FontWeightType } from '../styling/font-interfaces';
|
import { FontStyleType, FontWeightType } from '../styling/font-interfaces';
|
||||||
|
|
||||||
// Requires.
|
// Requires.
|
||||||
@ -24,6 +24,8 @@ export abstract class TextBaseCommon extends View implements TextBaseDefinition
|
|||||||
public _isSingleLine: boolean;
|
public _isSingleLine: boolean;
|
||||||
public text: string;
|
public text: string;
|
||||||
public formattedText: FormattedString;
|
public formattedText: FormattedString;
|
||||||
|
public iosTextAnimation: 'inherit' | boolean;
|
||||||
|
static iosTextAnimationFallback = true;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* In the NativeScript Core; by default the nativeTextViewProtected points to the same value as nativeViewProtected.
|
* In the NativeScript Core; by default the nativeTextViewProtected points to the same value as nativeViewProtected.
|
||||||
@ -236,6 +238,20 @@ export const formattedTextProperty = new Property<TextBaseCommon, FormattedStrin
|
|||||||
});
|
});
|
||||||
formattedTextProperty.register(TextBaseCommon);
|
formattedTextProperty.register(TextBaseCommon);
|
||||||
|
|
||||||
|
export const iosTextAnimationProperty = new Property<TextBaseCommon, 'inherit' | boolean>({
|
||||||
|
name: 'iosTextAnimation',
|
||||||
|
defaultValue: 'inherit',
|
||||||
|
affectsLayout: false,
|
||||||
|
valueConverter(value: string) {
|
||||||
|
try {
|
||||||
|
return booleanConverter(value);
|
||||||
|
} catch (e) {
|
||||||
|
return 'inherit';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
iosTextAnimationProperty.register(TextBaseCommon);
|
||||||
|
|
||||||
function onFormattedTextPropertyChanged(textBase: TextBaseCommon, oldValue: FormattedString, newValue: FormattedString) {
|
function onFormattedTextPropertyChanged(textBase: TextBaseCommon, oldValue: FormattedString, newValue: FormattedString) {
|
||||||
if (oldValue) {
|
if (oldValue) {
|
||||||
oldValue.off(Observable.propertyChangeEvent, textBase._onFormattedTextContentsChanged, textBase);
|
oldValue.off(Observable.propertyChangeEvent, textBase._onFormattedTextContentsChanged, textBase);
|
||||||
|
Reference in New Issue
Block a user