Skip to content

Commit

Permalink
Animate header color
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Nov 30, 2024
1 parent 4c430b0 commit c69d7e7
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/view/com/pager/TabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Animated, {
interpolate,
runOnUI,
scrollTo,
SharedValue,
useAnimatedReaction,
useAnimatedRef,
useAnimatedStyle,
Expand Down Expand Up @@ -189,7 +190,7 @@ export function TabBar({
<TabBarItem
index={i}
testID={testID}
selected={i === selectedPage}
dragProgress={dragProgress}
item={item}
onPressItem={onPressItem}
/>
Expand Down Expand Up @@ -221,33 +222,41 @@ export function TabBar({
function TabBarItem({
index,
testID,
selected,
dragProgress,
item,
onPressItem,
}: {
index: number
testID: string | undefined
selected: boolean
dragProgress: SharedValue<number>
item: string
onPressItem: (index: number) => void
}) {
const pal = usePalette('default')
const style = useAnimatedStyle(() => ({
opacity: interpolate(
dragProgress.get(),
[index - 1, index, index + 1],
[0.7, 1, 0.7],
'clamp',
),
}))
return (
<PressableWithHover
testID={`${testID}-selector-${index}`}
style={styles.item}
hoverStyle={pal.viewLight}
onPress={() => onPressItem(index)}
accessibilityRole="tab">
<View style={[styles.itemInner]}>
<Animated.View style={[style, styles.itemInner]}>
<Text
emoji
type="lg-bold"
testID={testID ? `${testID}-${item}` : undefined}
style={[selected ? pal.text : pal.textLight, {lineHeight: 20}]}>
style={[pal.text, {lineHeight: 20}]}>
{item}
</Text>
</View>
</Animated.View>
</PressableWithHover>
)
}
Expand Down

0 comments on commit c69d7e7

Please sign in to comment.