Skip to content

Commit

Permalink
new reanimated api instead of .value
Browse files Browse the repository at this point in the history
  • Loading branch information
sumo-slonik committed Nov 29, 2024
1 parent 9f8a42b commit daf4697
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/components/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ function Switch({isOn, onToggle, accessibilityLabel, disabled, showLockIcon, dis
disabledAction?.();
return;
}
offsetX.value = withTiming(isOn ? OFFSET_X.OFF : OFFSET_X.ON, {duration: 300});
offsetX.set(withTiming(isOn ? OFFSET_X.OFF : OFFSET_X.ON, {duration: 300}));
onToggle(!isOn);
});
};

const animatedThumbStyle = useAnimatedStyle(() => ({
transform: [{translateX: offsetX.value}],
transform: [{translateX: offsetX.get()}],
}));

const animatedSwitchTrackStyle = useAnimatedStyle(() => ({
backgroundColor: interpolateColor(offsetX.value, [OFFSET_X.OFF, OFFSET_X.ON], [theme.icon, theme.success]),
backgroundColor: interpolateColor(offsetX.get(), [OFFSET_X.OFF, OFFSET_X.ON], [theme.icon, theme.success]),
}));

return (
Expand Down
38 changes: 20 additions & 18 deletions src/components/Tooltip/GenericTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,21 @@ function GenericTooltip({

// When TooltipSense is active, immediately show the tooltip
if (TooltipSense.isActive() && !shouldForceAnimate) {
animation.value = 1;
animation.set(1);
} else {
isTooltipSenseInitiator.value = true;
animation.value = withDelay(
500,
withTiming(
1,
{
duration: 140,
},
(finished) => {
isAnimationCanceled.value = !finished;
},
isTooltipSenseInitiator.set(true);
animation.set(
withDelay(
500,
withTiming(
1,
{
duration: 140,
},
(finished) => {
isAnimationCanceled.set(!finished);
},
),
),
);
}
Expand All @@ -105,8 +107,8 @@ function GenericTooltip({
useEffect(() => {
// if the tooltip text changed before the initial animation was finished, then the tooltip won't be shown
// we need to show the tooltip again
if (isVisible && isAnimationCanceled.value && text && prevText !== text) {
isAnimationCanceled.value = false;
if (isVisible && isAnimationCanceled.get() && text && prevText !== text) {
isAnimationCanceled.set(false);
showTooltip();
}
}, [isVisible, text, prevText, showTooltip, isAnimationCanceled]);
Expand All @@ -130,13 +132,13 @@ function GenericTooltip({
const hideTooltip = useCallback(() => {
cancelAnimation(animation);

if (TooltipSense.isActive() && !isTooltipSenseInitiator.value) {
if (TooltipSense.isActive() && !isTooltipSenseInitiator.get()) {
// eslint-disable-next-line react-compiler/react-compiler
animation.value = 0;
animation.set(0);
} else {
// Hide the first tooltip which initiated the TooltipSense with animation
isTooltipSenseInitiator.value = false;
animation.value = 0;
isTooltipSenseInitiator.set(false);
animation.set(0);
}
TooltipSense.deactivate();
setIsVisible(false);
Expand Down
2 changes: 1 addition & 1 deletion src/styles/utils/generators/TooltipStyleUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ const createTooltipStyleUtils: StyleUtilGenerator<GetTooltipStylesStyleUtil> = (
const isTooltipSizeReady = tooltipWidth !== undefined && props.tooltipWrapperHeight !== undefined;
let scale = 1;
if (isTooltipSizeReady) {
scale = props.currentSize.value;
scale = props.currentSize.get();
}
return {
transform: [{scale}],
Expand Down

0 comments on commit daf4697

Please sign in to comment.