Skip to content

Commit

Permalink
Merge pull request #53379 from software-mansion-labs/migrate/animate-…
Browse files Browse the repository at this point in the history
…reanimate-bugfixs

[CP Staging] Fix problem with non-worklet tooltip and switch with update modal

(cherry picked from commit 4195ffc)

(CP triggered by mountiny)
  • Loading branch information
mountiny authored and OSBotify committed Dec 3, 2024
1 parent 03a695f commit 0a896a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/components/Switch.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {useEffect} from 'react';
import {InteractionManager} from 'react-native';
import Animated, {interpolateColor, useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated';
import useTheme from '@hooks/useTheme';
Expand Down Expand Up @@ -38,13 +38,16 @@ function Switch({isOn, onToggle, accessibilityLabel, disabled, showLockIcon, dis
const offsetX = useSharedValue(isOn ? OFFSET_X.ON : OFFSET_X.OFF);
const theme = useTheme();

useEffect(() => {
offsetX.set(withTiming(isOn ? OFFSET_X.ON : OFFSET_X.OFF, {duration: 300}));
}, [isOn, offsetX]);

const handleSwitchPress = () => {
InteractionManager.runAfterInteractions(() => {
if (disabled) {
disabledAction?.();
return;
}
offsetX.set(withTiming(isOn ? OFFSET_X.OFF : OFFSET_X.ON, {duration: 300}));
onToggle(!isOn);
});
};
Expand Down
2 changes: 2 additions & 0 deletions src/styles/utils/generators/TooltipStyleUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ const createTooltipStyleUtils: StyleUtilGenerator<GetTooltipStylesStyleUtil> = (

/** Utility function to create and manage scale animations with React Native Reanimated */
getTooltipAnimatedStyles: (props: TooltipAnimationProps) => {
'worklet';

const tooltipHorizontalPadding = spacing.ph2.paddingHorizontal * 2;
const tooltipWidth = props.tooltipContentWidth && props.tooltipContentWidth + tooltipHorizontalPadding + 1;
const isTooltipSizeReady = tooltipWidth !== undefined && props.tooltipWrapperHeight !== undefined;
Expand Down

0 comments on commit 0a896a3

Please sign in to comment.