Repository navigation
feat(motion): adopt spring tokens and add shared CSS-transition helper #5112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1d75730
b72a8d3
ece44d4
dc639e3
cea214b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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] | ||
| ); | ||
|
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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The check animation runs on a shared value with |
||
| }, [checked, checkScale, checkSpringConfig, showSelectedCheck]); | ||
|
|
||
| const checkAnimatedStyle = useAnimatedStyle(() => ({ | ||
| transform: [{ scale: checkScale.value }], | ||
|
|
||
There was a problem hiding this comment.
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 inCheckbox.tsx?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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 toCSSStyle<TextStyle>.