Skip to content

Commit 1fe28e1

Browse files
committed
Refactor components to use Animated API and improve layout transitions
1 parent a3772f0 commit 1fe28e1

File tree

6 files changed

+35
-19
lines changed

6 files changed

+35
-19
lines changed

src/components/Settings/SettGroup.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { Colors } from '@utils/colors'
22
import { SemiBold } from '@utils/fonts'
3-
import { cn } from '@utils/utils'
3+
import { cn, layout } from '@utils/utils'
44
import { View, ViewProps } from 'react-native'
5+
import Animated from 'react-native-reanimated'
56

67
type SettGroupProps = ViewProps & {
78
title?: string
89
accent?: string
910
}
1011
export default function SettGroup({ children, title, className, accent = Colors.accent, ...rest }: SettGroupProps) {
1112
return (
12-
<View className={cn('bg-white py-3 dark:bg-zinc-950', className)} {...rest}>
13+
<Animated.View className={cn('bg-white py-3 dark:bg-zinc-950', className)} layout={layout} {...rest}>
1314
{title && (
1415
<SemiBold
1516
className={'px-6 pb-1.5 pt-0.5 text-accent'}
@@ -19,6 +20,6 @@ export default function SettGroup({ children, title, className, accent = Colors.
1920
</SemiBold>
2021
)}
2122
<View style={{ gap: 8 }}>{children}</View>
22-
</View>
23+
</Animated.View>
2324
)
2425
}

src/screens/Animations.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default function Home({ navigation }: { navigation: StackNav }) {
3333
className='items-center justify-center'
3434
activeOpacity={0.9}
3535
onPress={() => {
36-
navigation.navigate('Animations')
36+
// navigation.navigate('Animations')
3737
}}
3838
>
3939
{/* <Animated.Image source={Images.app_icon} style={[styles.icon, animatedStyle]} /> */}

src/screens/DeveloperOptions/MMKVDataList.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { useIsFocused } from '@react-navigation/native'
1313
import { Colors } from '@utils/colors'
1414
import { ls, type StorageKeys } from '@utils/storage'
1515
import type { NavProp } from '@utils/types'
16-
import { delayedFadeAnimationSearch } from '@utils/utils'
16+
import { delayedFadeAnimationSearch, exiting, layout } from '@utils/utils'
1717
import React, { useEffect } from 'react'
1818
import { View } from 'react-native'
1919
import Animated from 'react-native-reanimated'
@@ -64,7 +64,12 @@ export default function MMKVDataList({ navigation }: NavProp) {
6464

6565
<SettGroup title='Stored keys' className='pb-4'>
6666
{searchResults?.map((item, i) => (
67-
<Animated.View key={item} entering={delayedFadeAnimationSearch(search, i)}>
67+
<Animated.View
68+
key={item}
69+
entering={delayedFadeAnimationSearch(search, i)}
70+
exiting={exiting}
71+
layout={layout}
72+
>
6873
<SettOption
6974
title={item}
7075
arrow

src/screens/Try/TyrItOut.tsx

+15-10
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ import { Group } from '@shopify/react-native-skia'
2828
import { Colors } from '@utils/colors'
2929
import { Bold } from '@utils/fonts'
3030
import type { NavProp } from '@utils/types'
31+
import { delayedFadeAnimationSearch, exiting, layout } from '@utils/utils'
3132
import type { RootStackParamList } from 'App'
3233
import React, { useMemo } from 'react'
3334
import { View, useColorScheme } from 'react-native'
3435
import { TouchableOpacity } from 'react-native-gesture-handler'
35-
import { FadeIn } from 'react-native-reanimated'
36+
import Animated, { FadeIn } from 'react-native-reanimated'
3637
import type { SvgProps } from 'react-native-svg'
3738

3839
type Tool = {
@@ -130,16 +131,20 @@ export default function TyrItOut({ navigation }: NavProp) {
130131
{group.startText && <SettText>{group.startText}</SettText>}
131132
<SettGroup title={group.title}>
132133
{group.tools.map((tool, i) => (
133-
// <Animated.View key={i} entering={delayedFadeAnimation(search, i)}>
134-
<SettOption
134+
<Animated.View
135135
key={i}
136-
title={tool.title}
137-
Icon={<RoundedIcon Icon={tool.Icon} className={tool.className} />}
138-
arrow={tool.arrow ?? true}
139-
// Update onPress handlers to correctly navigate using the 'to' property
140-
onPress={() => tool.to && navigation.navigate(tool.to as any)}
141-
/>
142-
// </Animated.View>
136+
entering={delayedFadeAnimationSearch(search, i)}
137+
exiting={exiting}
138+
layout={layout}
139+
>
140+
<SettOption
141+
title={tool.title}
142+
Icon={<RoundedIcon Icon={tool.Icon} className={tool.className} />}
143+
arrow={tool.arrow ?? true}
144+
// Update onPress handlers to correctly navigate using the 'to' property
145+
onPress={() => tool.to && navigation.navigate(tool.to as any)}
146+
/>
147+
</Animated.View>
143148
))}
144149
</SettGroup>
145150
{group.endText && <SettText>{group.endText}</SettText>}

src/utils/fonts.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { StyleSheet, Text, type TextProps } from 'react-native'
2+
import Animated from 'react-native-reanimated'
3+
import { layout } from './utils'
24

35
export const REGULAR = {
46
fontFamily: 'JosefinSans-Regular',
@@ -18,9 +20,9 @@ export const LIGHT = {
1820

1921
export function Medium({ children, style, ...props }: TextProps) {
2022
return (
21-
<Text style={[MEDIUM, style]} {...props}>
23+
<Animated.Text style={[MEDIUM, style]} {...props} layout={layout}>
2224
{children}
23-
</Text>
25+
</Animated.Text>
2426
)
2527
}
2628

src/utils/utils.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { DistanceUnit, TemperatureUnit, TimeFormat } from '@/zustand/weathe
22
import { ls } from '@utils/storage'
33
import { clsx, type ClassValue } from 'clsx'
44
import { Alert, Share } from 'react-native'
5-
import { FadeIn } from 'react-native-reanimated'
5+
import { FadeIn, FadeOut, LinearTransition } from 'react-native-reanimated'
66
import { twMerge } from 'tailwind-merge'
77
import { SCREEN_TRANSITION } from './constants'
88

@@ -242,3 +242,6 @@ export function delayedFadeAnimation(i: number) {
242242
export function cn(...inputs: ClassValue[]) {
243243
return twMerge(clsx(inputs))
244244
}
245+
246+
export const exiting = FadeOut.duration(250)
247+
export const layout = LinearTransition.duration(250)

0 commit comments

Comments
 (0)