feat(core): text-shadow support (#8991)

This commit is contained in:
Tiago Alves
2021-01-29 19:46:58 +00:00
committed by Nathan Walker
parent 0750ce5399
commit cbba5ed19d
10 changed files with 133 additions and 28 deletions

View File

@@ -1,9 +1,9 @@
// Types
import { TextDecoration, TextAlignment, TextTransform, getClosestPropertyValue } from './text-base-common';
import { TextDecoration, TextAlignment, TextTransform, TextShadow, getClosestPropertyValue } from './text-base-common';
// Requires
import { Font } from '../styling/font';
import { TextBaseCommon, textProperty, formattedTextProperty, textAlignmentProperty, textDecorationProperty, textTransformProperty, letterSpacingProperty, lineHeightProperty, resetSymbol } from './text-base-common';
import { TextBaseCommon, textProperty, formattedTextProperty, textAlignmentProperty, textDecorationProperty, textTransformProperty, textShadowProperty, letterSpacingProperty, lineHeightProperty, resetSymbol } from './text-base-common';
import { Color } from '../../color';
import { FormattedString } from './formatted-string';
import { Span } from './span';
@@ -188,6 +188,10 @@ export class TextBase extends TextBaseCommon {
this._setNativeText();
}
[textShadowProperty.setNative](value: TextShadow) {
this._setShadow(value);
}
_setNativeText(reset = false): void {
if (reset) {
const nativeView = this.nativeTextViewProtected;
@@ -343,6 +347,32 @@ export class TextBase extends TextBaseCommon {
}
}
_setShadow(value: TextShadow): void {
let layer;
if (this.nativeTextViewProtected instanceof UITextView) {
layer = this.nativeTextViewProtected.layer.sublayers.objectAtIndex(1);
} else {
layer = this.nativeTextViewProtected.layer;
}
if (isNullOrUndefined(value)) {
// clear the text shadow
layer.shadowOpacity = 0;
layer.shadowRadius = 0;
layer.shadowColor = UIColor.clearColor;
layer.shadowOffset = CGSizeMake(0, 0);
return;
}
layer.shadowOpacity = 1;
layer.shadowRadius = value.blurRadius;
layer.shadowColor = value.color.ios.CGColor;
layer.shadowOffset = CGSizeMake(value.offsetX, value.offsetY);
layer.shouldRasterize = true;
layer.masksToBounds = false;
}
createNSMutableAttributedString(formattedString: FormattedString): NSMutableAttributedString {
const mas = NSMutableAttributedString.alloc().init();
this._spanRanges = [];