Skip to content

Commit

Permalink
removing the onLayout in AnimatedSettlementButton
Browse files Browse the repository at this point in the history
  • Loading branch information
abzokhattab committed Dec 24, 2024
1 parent d96bd06 commit 21ddf32
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions src/components/SettlementButton/AnimatedSettlementButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, {useCallback, useEffect, useState} from 'react';
import {LayoutChangeEvent} from 'react-native';
import Animated, {runOnJS, useAnimatedStyle, useSharedValue, withDelay, withTiming} from 'react-native-reanimated';
import Button from '@components/Button';
import * as Expensicons from '@components/Icon/Expensicons';
Expand All @@ -22,7 +21,6 @@ function AnimatedSettlementButton({isPaidAnimationRunning, onAnimationFinish, is
const buttonScale = useSharedValue(1);
const buttonOpacity = useSharedValue(1);
const [isLoading, setIsLoading] = useState(false);
const [buttonWidth, setButtonWidth] = useState<number | undefined>(undefined);

const buttonStyles = useAnimatedStyle(() => ({
transform: [{scale: buttonScale.get()}],
Expand Down Expand Up @@ -74,33 +72,20 @@ function AnimatedSettlementButton({isPaidAnimationRunning, onAnimationFinish, is
};
}, [isPaidAnimationRunning, onAnimationFinish, buttonScale, buttonOpacity, resetAnimation, isApprovedAnimationRunning]);

const handleLayout = useCallback(
(event: LayoutChangeEvent) => {
const newWidth = event.nativeEvent.layout.width;
if (newWidth !== buttonWidth) {
setButtonWidth(newWidth);
}
},
[buttonWidth],
);

return (
<Animated.View style={containerStyles}>
{isPaidAnimationRunning || isApprovedAnimationRunning ? (
<Animated.View style={buttonStyles}>
<Button
style={[styles.buttonMediumText, {width: buttonWidth}]}
style={[styles.buttonMediumText]}
text={isPaidAnimationRunning ? translate('iou.paymentComplete') : translate('iou.approved')}
isLoading={isLoading}
success
icon={!isLoading ? Expensicons.Checkmark : undefined}
/>
</Animated.View>
) : (
<Animated.View
style={buttonStyles}
onLayout={handleLayout}
>
<Animated.View style={buttonStyles}>
<SettlementButton
// eslint-disable-next-line react/jsx-props-no-spreading
{...settlementButtonProps}
Expand Down

0 comments on commit 21ddf32

Please sign in to comment.