-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
MM-59973: fix the emoji count 0 issue when archive and unarchive chan… #8146
Changes from 7 commits
4b12bc7
9a0b74a
6e08ff6
6fea662
aac779d
e4843fb
5ed7630
955c04f
e2a4233
d144114
3862eeb
00d9cb4
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 |
---|---|---|
|
@@ -8,7 +8,7 @@ interface Props { | |
animateToNumber: number; | ||
fontStyle?: StyleProp<TextStyle>; | ||
animationDuration?: number; | ||
easing?: ((input: number) => number) | undefined; | ||
easing?: number; | ||
} | ||
|
||
const NUMBERS = Array(10).fill(null).map((_, i) => i); | ||
|
@@ -26,43 +26,43 @@ const AnimatedNumber = ({ | |
animateToNumber, | ||
animationDuration, | ||
fontStyle, | ||
easing, | ||
easing = 1.2, | ||
}: Props) => { | ||
const prevNumber = usePrevious(animateToNumber); | ||
const animateToNumberString = String(Math.abs(animateToNumber)); | ||
const prevNumberString = String(Math.abs(prevNumber)); | ||
|
||
const numberStringToDigitsArray = Array.from(animateToNumberString, Number); | ||
const prevNumberersArr = Array.from(prevNumberString, Number); | ||
|
||
const [numberHeight, setNumberHeight] = React.useState(0); | ||
const animations = useMemo(() => numberStringToDigitsArray.map((__, index) => { | ||
if (typeof prevNumberersArr[index] !== 'number') { | ||
return new Animated.Value(0); | ||
const animations = useMemo(() => { | ||
if (numberHeight === 0) { | ||
return []; | ||
} | ||
const numberStringToDigitsArray = Array.from(animateToNumberString, Number); | ||
const prevNumberersArr = Array.from(prevNumberString, Number); | ||
|
||
const animationHeight = -1 * (numberHeight * prevNumberersArr[index]); | ||
return new Animated.Value(animationHeight); | ||
}), [numberStringToDigitsArray]); | ||
return numberStringToDigitsArray.map((digit, index) => { | ||
// Skip animation if the current and previous digits are the same | ||
if (prevNumberersArr[index] === digit) { | ||
return new Animated.Value(-1 * (numberHeight * digit)); | ||
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.
if (prevNumberersArr[index] === digit) { Following the DRY principle, you could remove it. However, I think a comment explaining the next line
...could add value. 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. Yes, this condition could indeed cause an issue when transitioning from 99 to 100. The problem arises because we skip the animation when the digits are the same. For example:
When comparing the first digit ( The issue is not necessarily in this block itself, but the logic could behave unexpectedly if we are rapidly changing values (e.g., every 100ms). Skipping digits could lead to an incorrect visual transition, especially when the change is rapid, such as going from To ensure the conditions for rapid changes are avoided we can add an extra condition for checking whether the length of the |
||
} | ||
|
||
const setButtonLayout = useCallback((e: LayoutChangeEvent) => { | ||
setNumberHeight(e.nativeEvent.layout.height); | ||
}, []); | ||
const prevHeight = -1 * (numberHeight * (prevNumberersArr[index] || 0)); | ||
const animation = new Animated.Value(prevHeight); | ||
|
||
React.useEffect(() => { | ||
animations.forEach((animation, index) => { | ||
Animated.timing(animation, { | ||
toValue: -1 * (numberHeight * numberStringToDigitsArray[index]), | ||
duration: animationDuration || 1400, | ||
toValue: -1 * (numberHeight * digit), | ||
duration: animationDuration, | ||
rahimrahman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
useNativeDriver: true, | ||
easing: easing || Easing.elastic(1.2), | ||
easing: Easing.elastic(easing), | ||
}).start(); | ||
|
||
return animation; | ||
}); | ||
}, [animateToNumber, animationDuration, fontStyle, numberHeight]); | ||
}, [animateToNumberString, prevNumber, numberHeight, animationDuration, easing]); | ||
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.
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. Updated the dependency. |
||
|
||
const getTranslateY = (index: number) => { | ||
return animations[index]; | ||
}; | ||
const setButtonLayout = useCallback((e: LayoutChangeEvent) => { | ||
setNumberHeight(e.nativeEvent.layout.height); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
|
@@ -71,37 +71,33 @@ const AnimatedNumber = ({ | |
{animateToNumber < 0 && ( | ||
<Text style={[fontStyle, {height: numberHeight}]}>{'-'}</Text> | ||
)} | ||
{numberStringToDigitsArray.map((n, index) => { | ||
return ( | ||
<View | ||
key={`${index.toString()}`} | ||
style={{height: numberHeight, overflow: 'hidden'}} | ||
> | ||
<Animated.View | ||
style={[ | ||
{Array.from(animateToNumberString, Number).map((_, index) => ( | ||
<View | ||
key={`${index.toString()}`} | ||
style={{height: numberHeight, overflow: 'hidden'}} | ||
> | ||
<Animated.View | ||
style={{ | ||
transform: [ | ||
{ | ||
transform: [ | ||
{ | ||
translateY: getTranslateY(index), | ||
}, | ||
], | ||
translateY: animations[index], | ||
}, | ||
]} | ||
> | ||
{NUMBERS.map((number, i) => ( | ||
<View | ||
style={{flexDirection: 'row'}} | ||
key={`${i.toString()}`} | ||
> | ||
<Text style={[fontStyle, {height: numberHeight}]}> | ||
{number} | ||
</Text> | ||
</View> | ||
))} | ||
</Animated.View> | ||
</View> | ||
); | ||
})} | ||
], | ||
}} | ||
> | ||
{NUMBERS.map((number, i) => ( | ||
<View | ||
key={`${i.toString()}`} | ||
style={{flexDirection: 'row'}} | ||
> | ||
<Text style={[fontStyle, {height: numberHeight}]}> | ||
{number} | ||
</Text> | ||
</View> | ||
))} | ||
</Animated.View> | ||
</View> | ||
))} | ||
</View> | ||
)} | ||
{numberHeight === 0 && | ||
|
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.
Q: would it be safer to return
just to protect from future regression?
Could transform.translateY: undefined
cause any issue if index is out of bounds due to animations being empty.
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.
Yes, but I think
numberStringToDigitsArray
is anumber
array and cannot be filled withValue
type. Maybemap
can work here to return the new array filled withAnimated.Value(0)
.