-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: withSpring color properties flickering #6821
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,6 +164,13 @@ function parsePercentage(str: string): number { | |
return int / 100; | ||
} | ||
|
||
function clampRGBA(RGBA: ParsedColorArray): void { | ||
'worklet'; | ||
for (let i = 0; i < 4; i++) { | ||
RGBA[i] = Math.max(0, Math.min(RGBA[i], 1)); | ||
} | ||
} | ||
|
||
const names: Record<string, number> = makeShareable({ | ||
transparent: 0x00000000, | ||
|
||
|
@@ -693,6 +700,7 @@ export function convertToRGBA(color: unknown): ParsedColorArray { | |
|
||
export function rgbaArrayToRGBAColor(RGBA: ParsedColorArray): string { | ||
'worklet'; | ||
clampRGBA(RGBA); | ||
const alpha = RGBA[3] < 0.001 ? 0 : RGBA[3]; | ||
return `rgba(${Math.round(RGBA[0] * 255)}, ${Math.round( | ||
RGBA[1] * 255 | ||
|
@@ -718,6 +726,7 @@ export function toGammaSpace( | |
): ParsedColorArray { | ||
'worklet'; | ||
const res = []; | ||
clampRGBA(RGBA); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand that you want to clamp values before converting the color array into a string, as done in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be honest animation.current = rgbaArrayToRGBAColor(
toGammaSpace(res as ParsedColorArray)
); It is also helpful to put it in return rgbaColor(
toGammaSpace(r, gamma),
toGammaSpace(g, gamma),
toGammaSpace(b, gamma),
a
); So answering your question, |
||
for (let i = 0; i < 3; ++i) { | ||
res.push(Math.pow(RGBA[i], 1 / gamma)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
convertToRGBA
andtoLinearSpace
functions?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
convertToRGBA
converts from rgba string (rgba(255, 0, 0, 1)
) to RGBA array, so it should receive correct input. In our current implementation firstconvertToRGBA
is called transformingrgba(255, 0, 0, 1)
to[1,0,0,1]
, thenwithSpring
happens, perhaps returning negative values. And this is the moment where we clamp the values. We could also put clamp in those function you mentioned, but i think it'll overkill because they are protected when other functions (ex.rgbaArrayToRGBAColor
) are clamped.In retrospective we can also move the clamping to
util.ts
file functioncolorOnFrame
, and clamp the result. In my opinion it will be better to leave clamping inColors.ts
(and if you want extended toconvertToRGBA
andtoLinearSpace
). If we were ever to use converting functions in files other thatutil.ts
, then it would guarantee safe result.