Skip to content

Commit 172f424

Browse files
committed
feat(animation): replaces Animatable.View with Animated.View
1 parent 16c3a16 commit 172f424

File tree

2 files changed

+27
-29
lines changed

2 files changed

+27
-29
lines changed

src/Dropdown.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React, { memo, useMemo } from 'react'
22
import type { ListRenderItem } from 'react-native'
33
import { StyleSheet, FlatList, View, useColorScheme } from 'react-native'
4-
import * as Animatable from 'react-native-animatable'
5-
import { fadeInDownShort, fadeInUpShort } from './helpers'
4+
import Animated from 'react-native-reanimated'
65
import { theme as defaultTheme } from './theme'
76
import type { AutocompleteDropdownItem, IAutocompleteDropdownProps } from './types'
7+
import { FadeInDown, FadeInUp, FadeOutDown, FadeOutUp } from './helpers'
88
interface DropdownProps extends Omit<IAutocompleteDropdownProps, 'renderItem' | 'ref'> {
99
ListEmptyComponent: React.ReactElement
1010
renderItem: ListRenderItem<AutocompleteDropdownItem>
@@ -30,12 +30,9 @@ export const Dropdown = memo((props: DropdownProps) => {
3030
}, [styles.itemSeparator])
3131

3232
return (
33-
<Animatable.View
34-
useNativeDriver
35-
animation={direction === 'up' ? fadeInUpShort : fadeInDownShort}
36-
easing="ease-out-quad"
37-
delay={direction === 'up' ? 150 : 0}
38-
duration={150}
33+
<Animated.View
34+
entering={direction === 'up' ? FadeInUp : FadeInDown}
35+
exiting={direction === 'up' ? FadeOutUp : FadeOutDown}
3936
style={{
4037
...styles.listContainer,
4138
...(rest.suggestionsListContainerStyle as object),
@@ -52,7 +49,7 @@ export const Dropdown = memo((props: DropdownProps) => {
5249
ItemSeparatorComponent={ItemSeparatorComponent ?? defaultItemSeparator}
5350
{...rest.flatListProps}
5451
/>
55-
</Animatable.View>
52+
</Animated.View>
5653
)
5754
})
5855

src/helpers.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
export const fadeInDownShort = {
2-
0: {
3-
opacity: 0,
4-
transform: [{ translateY: -20 }],
5-
},
6-
1: {
7-
opacity: 1,
8-
transform: [{ translateY: 0 }],
9-
},
10-
}
1+
import {
2+
Easing,
3+
FadeInDown as RNRFadeInDown,
4+
FadeInUp as RNRFadeInUp,
5+
FadeOutDown as RNRFadeOutDown,
6+
FadeOutUp as RNRFadeOutUp,
7+
} from 'react-native-reanimated'
118

12-
export const fadeInUpShort = {
13-
0: {
14-
opacity: 0,
15-
transform: [{ translateY: 20 }],
16-
},
17-
1: {
18-
opacity: 1,
19-
transform: [{ translateY: 0 }],
20-
},
21-
}
9+
const ANIMATION_DURATION = 150
10+
const ANIMATION_EASING = Easing.quad
11+
export const FadeInUp = RNRFadeInUp.duration(ANIMATION_DURATION)
12+
.easing(ANIMATION_EASING)
13+
.withInitialValues({ transform: [{ translateY: -20 }] })
14+
export const FadeOutUp = RNRFadeOutUp.duration(ANIMATION_DURATION)
15+
.easing(ANIMATION_EASING)
16+
.withInitialValues({ transform: [{ translateY: 0 }] })
17+
export const FadeInDown = RNRFadeInDown.duration(ANIMATION_DURATION)
18+
.easing(ANIMATION_EASING)
19+
.withInitialValues({ transform: [{ translateY: 20 }] })
20+
export const FadeOutDown = RNRFadeOutDown.duration(ANIMATION_DURATION)
21+
.easing(ANIMATION_EASING)
22+
.withInitialValues({ transform: [{ translateY: 0 }] })

0 commit comments

Comments
 (0)