Skip to content

Commit

Permalink
feat(animations): slide
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrk committed Nov 29, 2020
1 parent ae20710 commit 833e907
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/components/Animations/Slide/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as React from 'react'
import { LayoutChangeEvent } from 'react-native'
import Animated, { Extrapolate, interpolate } from 'react-native-reanimated'
import { useTimingTransition } from 'react-native-redash/lib/module/v1'

import { SlideProps } from './types'

export const Slide: React.FC<SlideProps> = ({ style, initialOffset = 1000, inverted = false, show, ...rest }) => {
const [height, setHeight] = React.useState(initialOffset)
const value = useTimingTransition(show, { duration: 200 })

const onLayout = ({ nativeEvent: { layout } }: LayoutChangeEvent) => {
setHeight(layout.height)
}

const slidetyles = {
transform: [{
translateY: interpolate(value, {
inputRange: [0, 1],
outputRange: [inverted ? height : -height, 0],
extrapolate: Extrapolate.CLAMP,
}),
}],
}

return (
<Animated.View
style={[slidetyles, style]}
onLayout={onLayout}
{...rest}
/>
)
}
9 changes: 9 additions & 0 deletions src/components/Animations/Slide/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ViewProps } from 'react-native'

export interface SlideProps extends ViewProps {
/** show/hide */
show: boolean,
/** initial offset */
initialOffset?: number,
inverted: boolean,
}
1 change: 1 addition & 0 deletions src/components/Animations/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { Fade } from './Fade'
export { Slide } from './Slide'

0 comments on commit 833e907

Please sign in to comment.