Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/components/Badge.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import type { StyleProp, TextProps, TextStyle } from 'react-native';
import { StyleSheet } from 'react-native';

import Animated, { type AnimatedStyle } from 'react-native-reanimated';
import Animated, {
type AnimatedStyle,
type CSSStyle,
} from 'react-native-reanimated';

import { useInternalTheme } from '../core/theming';
import { useReduceMotion } from '../theme/accessibility/ReduceMotionContext';
import { getTransition } from '../theme/tokens/sys/motion';
import { cornerFull } from '../theme/tokens/sys/shape';
import type { ThemeProp } from '../theme/types';

Expand Down Expand Up @@ -56,21 +61,23 @@ const Badge = ({
...rest
}: Props) => {
const theme = useInternalTheme(themeOverrides);

const {
animation: { scale },
} = theme;
const reduceMotion = useReduceMotion();

const textColor = theme.colors.onError;

const isLarge = children != null;
const badgeSize = isLarge ? LARGE_SIZE : SMALL_SIZE;
const labelFont = theme.fonts.labelSmall;

const transitionStyle = {
const transitionStyle: CSSStyle<TextStyle> = {
opacity: visible ? 1 : 0,
transitionDuration: 150 * scale,
transitionProperty: 'opacity',
...getTransition<TextStyle>(
theme,
'opacity',
'short3',
'standard',
reduceMotion
),
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered typing this style as CSSStyle<ViewStyle> like in Checkbox.tsx?

@rjmreis rjmreis Sep 15, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, done! Badge renders Animated.Text, so I've updated it to CSSStyle<TextStyle>.


return (
Expand Down
39 changes: 17 additions & 22 deletions src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import type {
ViewStyle,
} from 'react-native';

import Animated, { cubicBezier, type CSSStyle } from 'react-native-reanimated';
import Animated, { type CSSStyle } from 'react-native-reanimated';

import { CheckboxTokens } from './tokens';
import { getSelectionVisualState } from './utils';
import { useLocale } from '../../core/locale';
import { useInternalTheme } from '../../core/theming';
import { useReduceMotion } from '../../theme/accessibility/ReduceMotionContext';
import { tokens } from '../../theme/tokens';
import { getTransition } from '../../theme/tokens/sys/motion';
import type { ThemeProp } from '../../theme/types';
import { isKeyboardFocusEvent } from '../../utils/isKeyboardFocusEvent';
import TouchableRipple from '../TouchableRipple/TouchableRipple';
Expand Down Expand Up @@ -144,44 +145,38 @@ const Checkbox = ({
customUncheckedColor: uncheckedColor,
});

const fillTransitionTimingFunction = cubicBezier(
...theme.motion.easing.standard
const fillTransition = getTransition<ViewStyle>(
theme,
['opacity'],
'short2',
'standard',
reduceMotion
);

const fillTransitionDuration = reduceMotion
? 0
: theme.motion.duration.short2;

const checkTransitionDuration = reduceMotion
? 0
: theme.motion.duration.short3;

const checkTransitionTimingFunction = cubicBezier(
...theme.motion.easing.standard
const checkTransition = getTransition<ViewStyle>(
theme,
['width', 'opacity'],
'short3',
'standard',
reduceMotion
);

const outlineStyle: CSSStyle<ViewStyle> = {
borderColor: visual.outlineColor,
opacity: selected ? 0 : 1,
transitionDuration: fillTransitionDuration,
transitionProperty: ['opacity'],
transitionTimingFunction: fillTransitionTimingFunction,
...fillTransition,
};

const fillStyle: CSSStyle<ViewStyle> = {
backgroundColor: visual.containerColor,
opacity: selected ? 1 : 0,
transitionDuration: fillTransitionDuration,
transitionProperty: ['opacity'],
transitionTimingFunction: fillTransitionTimingFunction,
...fillTransition,
};

const maskStyle: CSSStyle<ViewStyle> = {
width: selected ? CONTAINER_SIZE : 0,
opacity: selected ? 1 : 0,
transitionDuration: checkTransitionDuration,
transitionProperty: ['width', 'opacity'],
transitionTimingFunction: checkTransitionTimingFunction,
...checkTransition,
};

// Remember the last drawn glyph so the reveal-mask can finish collapsing
Expand Down
22 changes: 11 additions & 11 deletions src/components/SegmentedButtons/SegmentedButtonItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,14 @@ import {
} from './utils';
import { useInternalTheme } from '../../core/theming';
import { useReduceMotion } from '../../theme/accessibility/ReduceMotionContext';
import { toRawSpring } from '../../theme/tokens/sys/motion';
import type { ThemeProp } from '../../theme/types';
import type { IconSource } from '../Icon';
import Icon from '../Icon';
import TouchableRipple from '../TouchableRipple/TouchableRipple';
import type { Props as TouchableRippleProps } from '../TouchableRipple/TouchableRipple';
import Text from '../Typography/Text';

const CHECK_SPRING_CONFIG = {
stiffness: 230.2,
damping: 22,
mass: 1,
};

export type Props = {
/**
* Whether the segmented button is checked
Expand Down Expand Up @@ -139,16 +134,21 @@ const SegmentedButtonItem = ({

const checkScale = useSharedValue(0);

const checkSpringConfig = React.useMemo(
() => ({
...toRawSpring(theme.motion.spring.fast.spatial),
reduceMotion: reduceMotion ? ReduceMotion.Always : ReduceMotion.Never,
}),
[theme.motion.spring.fast.spatial, reduceMotion]
);
Comment thread
rjmreis marked this conversation as resolved.

React.useEffect(() => {
if (!showSelectedCheck) {
return;
}

checkScale.value = withSpring(checked ? 1 : 0, {
...CHECK_SPRING_CONFIG,
reduceMotion: reduceMotion ? ReduceMotion.Always : ReduceMotion.Never,
});
}, [checked, checkScale, reduceMotion, showSelectedCheck]);
checkScale.value = withSpring(checked ? 1 : 0, checkSpringConfig);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check animation runs on a shared value with withSpring, but it is driven by the checked prop and not by a gesture or scroll. The project rule is to use Reanimated CSS transitions (transitionProperty and transitionDuration, as in Badge.tsx and Checkbox.tsx) for state changes, and to keep shared values for gesture or scroll driven motion. Please move the check scale and the icon scale to CSS transitions on transform. Reanimated 4.3 exports linear(...), so you can keep the fast.spatial spring shape by sampling it into linear() points for transitionTimingFunction. With that change, the useMemo and the effect go away. (via Claude, verify if it makes sense)

}, [checked, checkScale, checkSpringConfig, showSelectedCheck]);

const checkAnimatedStyle = useAnimatedStyle(() => ({
transform: [{ scale: checkScale.value }],
Expand Down
6 changes: 0 additions & 6 deletions src/components/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ export type TextInputAnimationState = {
animatedActiveOutlineStyle?: StyleProp<AnimatedStyle<StyleProp<ViewStyle>>>;
};

export type TextInputAnimationHandlers = {
runFocusAnimation: (hasText: boolean) => void;
runBlurAnimation: (hasText: boolean) => void;
syncFloatToValue: (hasText: boolean) => void;
};

export type TextInputFlags = {
isRTL: boolean;
isDisabled: boolean;
Expand Down
10 changes: 0 additions & 10 deletions src/components/TextInput/constants.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { PixelRatio } from 'react-native';

import { Easing } from 'react-native-reanimated';

import { tokens } from '../../theme/tokens';
import { motionDuration, motionEasing } from '../../theme/tokens/sys/motion';
import { defaultShapes } from '../../theme/tokens/sys/shape';

export const fontScale = PixelRatio.getFontScale();
Expand Down Expand Up @@ -46,16 +43,9 @@ export const SUPPORTING_TEXT_FONT_SIZE =

export const SUPPORTING_TEXT_MARGIN_TOP = 4;

export const ANIMATION_DURATION_MS = motionDuration.short3;

export const ACTIVE_INDICATOR_SIZE = 2;
export const INACTIVE_INDICATOR_SIZE = 1;

export const TIMING_CONFIG = {
duration: ANIMATION_DURATION_MS,
easing: Easing.bezier(...motionEasing.standard),
} as const;

/**
* Constants for the filled variant.
*/
Expand Down
Loading
Loading