Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05c59e7
commit c69c70c
Showing
4 changed files
with
200 additions
and
130 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
code-examples/introduction-to-react-native-reanimated/Header.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import * as React from "react" | ||
import { Text } from "react-native" | ||
import Animated from "react-native-reanimated" | ||
|
||
const HEADER_HEIGHT = 60 | ||
const { diffClamp, interpolate } = Animated | ||
|
||
export const Header = props => { | ||
const diffClampY = diffClamp(props.y, 0, HEADER_HEIGHT) | ||
const translateY = interpolate(diffClampY, { | ||
inputRange: [0, HEADER_HEIGHT], | ||
outputRange: [0, -HEADER_HEIGHT], | ||
}) | ||
return ( | ||
<Animated.View | ||
style={{ | ||
height: HEADER_HEIGHT, | ||
position: "absolute", | ||
top: 0, | ||
width: "100%", | ||
zIndex: 2, | ||
backgroundColor: "#ffb74d", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
transform: [{ translateY: translateY }], | ||
}} | ||
> | ||
<Text>Header</Text> | ||
</Animated.View> | ||
) | ||
} | ||
|
23 changes: 23 additions & 0 deletions
23
code-examples/introduction-to-react-native-reanimated/List.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as React from "react" | ||
import { Image } from "react-native" | ||
import { onScroll } from "react-native-redash" | ||
import Animated from "react-native-reanimated" | ||
|
||
export const List = props => { | ||
return ( | ||
// Use onScroll to update the y value | ||
<Animated.ScrollView | ||
onScroll={onScroll({ y: props.y })} | ||
scrollEventThrottle={16} | ||
contentContainerStyle={{ paddingTop: 50 }} | ||
> | ||
{Array.from({ length: 10 }, (v, k) => ( | ||
<Image | ||
style={{ width: "100%", height: 200, marginTop: 50 }} | ||
key={k + ""} | ||
source={{ uri: "https://picsum.photos/200/300" }} | ||
/> | ||
))} | ||
</Animated.ScrollView> | ||
) | ||
} |
17 changes: 17 additions & 0 deletions
17
code-examples/introduction-to-react-native-reanimated/Parent.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as React from "react" | ||
import { View } from "react-native" | ||
import { Header } from "./Header" | ||
import { List } from "./List" | ||
import Animated from "react-native-reanimated" | ||
|
||
export const Parent = () => { | ||
// Create an "y" animated value and pass it down to the children | ||
const y = new Animated.Value(0) | ||
|
||
return ( | ||
<View> | ||
<Header y={y} /> | ||
<List y={y} /> | ||
</View> | ||
) | ||
} |
Oops, something went wrong.