feat(ios): allow disabling text animations (#10505)

This commit is contained in:
Eduardo Speroni
2024-04-03 19:59:10 -03:00
committed by GitHub
parent 73709125c4
commit 9ca490250e
3 changed files with 65 additions and 29 deletions

View File

@ -99,6 +99,16 @@ export class TextBase extends View implements AddChildFromBuilder {
*/
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.
* This method will add a child element (value) to current element.

View File

@ -291,8 +291,17 @@ export class TextBase extends TextBaseCommon {
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 {
this._animationWrap(() => {
if (reset) {
const nativeView = this.nativeTextViewProtected;
if (nativeView instanceof UIButton) {
@ -324,6 +333,7 @@ export class TextBase extends TextBaseCommon {
if (this.style?.textStroke) {
this.nativeTextViewProtected.nativeScriptSetFormattedTextStrokeColor(Length.toDevicePixels(this.style.textStroke.width, 0), this.style.textStroke.color.ios);
}
});
}
createFormattedTextNative(value: FormattedString) {

View File

@ -1,6 +1,6 @@
// Types
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';
// Requires.
@ -24,6 +24,8 @@ export abstract class TextBaseCommon extends View implements TextBaseDefinition
public _isSingleLine: boolean;
public text: string;
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.
@ -236,6 +238,20 @@ export const formattedTextProperty = new Property<TextBaseCommon, FormattedStrin
});
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) {
if (oldValue) {
oldValue.off(Observable.propertyChangeEvent, textBase._onFormattedTextContentsChanged, textBase);