Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/react-native/Libraries/Text/RCTTextAttributes.mm
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ - (UIColor *)effectiveForegroundColor
}

if([cgColors count] > 0) {
[cgColors addObject:cgColors[0]];
CAGradientLayer *gradient = [CAGradientLayer layer];
// this pattern width corresponds roughly to desktop's pattern width
int patternWidth = 100;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,12 @@ private static void buildSpannedFromShadowNode(
}
int end = sb.length();
if (end >= start) {
if (textShadowNode.mIsColorSet || textShadowNode.mGradientColors != null) {
if (textShadowNode.mGradientColors != null && textShadowNode.mGradientColors.length >= 2) {
if (textShadowNode.mIsColorSet) {
ops.add(new SetSpanOperation(start, end, new ReactForegroundColorSpan(textShadowNode.mColor)));
}
if (textShadowNode.mGradientColors != null && textShadowNode.mGradientColors.length >= 2) {
int effectiveFontSize = textAttributes.getEffectiveFontSize();
ops.add(
new SetSpanOperation(start, end, new LinearGradientSpan(start * effectiveFontSize, textShadowNode.mGradientColors)));
} else {
ops.add(
new SetSpanOperation(start, end, new ReactForegroundColorSpan(textShadowNode.mColor)));
}
ops.add(new SetSpanOperation(start, end, new LinearGradientSpan(start * effectiveFontSize, textShadowNode.mGradientColors)));
}
if (textShadowNode.mIsBackgroundColorSet) {
ops.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public class LinearGradientSpan(
) : CharacterStyle(), ReactSpan,
UpdateAppearance {
public override fun updateDrawState(tp: TextPaint) {
// without setting the paint color, the gradient appears "faded" if no foreground color span is also applied
// https://stackoverflow.com/a/52289927
tp.setColor(colors[0])
val textShader: Shader =
LinearGradient(
start,
Expand Down
Loading