Skip to content

Conversation

@timothy-huynh
Copy link

@timothy-huynh timothy-huynh commented Apr 22, 2025

Summary:

We added a new Boost perk called "Enhanced Role Colors/Styles" that allows admins to set gradient colors for roles in their guild. To support this on mobile, we have to provide native components that can render gradients.

At first, we were planning to create a custom native component but ran into 2 issues:

  1. The custom component needed a height and width defined for it to render. This was fixed by using a ShadowNode but we ran into other sizing issues.
  2. Our string formatter nests Text nodes and wouldn't render our custom view even when it extended BaseText.

We decided rather than creating a new custom component and solving for the above issues, it'd be easier to update Text to support gradient colors.

Changelog:

  • updates iOS and Android Text to support gradientColors which is an optional array of numbers

Test Plan:

Tested updating ChatInputReplyBar to show gradient colors with the following test cases:

  • gradientColors with a list of numbers
  • gradientColors with some null values
  • gradientColors with some string values
  • gradientColors with some double values

For the value types not int, the goal is to not crash the app. This equates to different behaviors between the platforms but the dev will get a type error on the React JS side of things so things should generally work as expected.

I picked ChatInputReplyBar because it demonstrates the behavior with nested Text nodes and is a place where we will want to render gradient colors.

screenshots

happy path
image

tertiaryColor is string (which is ignored so only first 2 colors show)
image

tertiaryColor is double (which is translated as 0 on Android and some other number on iOS)
image

@timothy-huynh timothy-huynh requested review from Flewp and mrkcsc April 22, 2025 18:04
*/
minimumFontScale?: number | undefined;

gradientColors?: number[] | undefined;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's a fork but maybe doc on the expected format, eg: what type of "int based color" is expected here and also presumably its a horizontal gradient only.

protected boolean mIsBackgroundColorSet = false;
protected int mBackgroundColor;

protected int[] mGradientColors = new int[0];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just leave it as null so we don't pay any added memory cost for the majority case where gradient colors are not being used.

}
}
if (colors.size() >= 2) {
mGradientColors = colors.stream()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be wary of using .stream() I am not entirely sure if this Java API is backported to all the old Android versions we support.

I'd suggest sticking to a simple for loop.

@timothy-huynh timothy-huynh merged commit 483dda8 into 0.76.6-discord Apr 22, 2025
16 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants