Skip to content

Commit

Permalink
#600 revisited, revisited
Browse files Browse the repository at this point in the history
  • Loading branch information
duogenesis committed Jan 27, 2025
1 parent b9a6885 commit 5260b32
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions components/button/centered-text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ const ButtonWithCenteredText = (props) => {

const fade = (callback?: () => void) => {
animatedOpacity.stopAnimation(() =>
animatedOpacity.setValue(opacityLo)
Animated.timing(animatedOpacity, {
toValue: opacityLo,
duration: 0,
useNativeDriver: true,
}).start((result) => result.finished && callback?.())
);
callback && callback();
};

const unfade = (callback?: () => void) => {
Expand All @@ -46,22 +49,21 @@ const ButtonWithCenteredText = (props) => {
toValue: opacityHi,
duration: 1000,
useNativeDriver: true,
}).start((result) => result.finished && callback && callback())
}).start((result) => result.finished && callback?.())
);
};

class Api {
isEnabled(value: boolean) {
const previousValue = isEnabledRef.current;

isEnabledRef.current = value;

if (value === previousValue) return;
if (value) {
if (value === isEnabledRef.current) {
;
} else if (value) {
unfade();
} else {
fade();
}

isEnabledRef.current = value;
}

doPressAnimation() {
Expand All @@ -82,19 +84,9 @@ const ButtonWithCenteredText = (props) => {
height: 50,
...containerStyle,
}}
onPressIn={() => {
if (isEnabledRef.current) {
fade();
}
}}
onPress={() => {
if (isEnabledRef.current) {
unfade();
}
if (isEnabledRef.current && !loading && onPress) {
onPress();
}
}}
onPressIn={() => isEnabledRef.current && fade()}
onPressOut={() => isEnabledRef.current && unfade()}
onPress={() => isEnabledRef.current && !loading && onPress?.()}
>
<Animated.View
style={{
Expand Down

0 comments on commit 5260b32

Please sign in to comment.