This repository has been archived by the owner on Feb 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose stack transition values via context (#265)
- Loading branch information
1 parent
35cc5b8
commit 1339364
Showing
7 changed files
with
147 additions
and
2 deletions.
There are no files selected for viewing
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
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,104 @@ | ||
import * as React from 'react'; | ||
import { Button, View } from 'react-native'; | ||
import Animated from 'react-native-reanimated'; | ||
import { | ||
createStackNavigator, | ||
NavigationStackScreenProps, | ||
StackAnimationProgressContext, | ||
StackAnimationIsSwipingContext, | ||
StackAnimationIsClosingContext, | ||
} from 'react-navigation-stack'; | ||
|
||
const ListScreen = (props: NavigationStackScreenProps) => ( | ||
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}> | ||
<Button | ||
title="Push to another screen" | ||
onPress={() => props.navigation.push('Another')} | ||
/> | ||
<Button | ||
title="Push to yet another screen" | ||
onPress={() => props.navigation.push('YetAnother')} | ||
/> | ||
<Button | ||
title="Go back to all examples" | ||
onPress={() => props.navigation.navigate('Home')} | ||
/> | ||
</View> | ||
); | ||
|
||
const AnotherScreen = () => ( | ||
<StackAnimationProgressContext.Consumer> | ||
{progress => { | ||
const fontSize = Animated.interpolate(progress, { | ||
inputRange: [0, 1], | ||
outputRange: [8, 32], | ||
}); | ||
|
||
return ( | ||
<View | ||
style={{ | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
backgroundColor: 'honeydew', | ||
}} | ||
> | ||
<Animated.Text style={{ fontSize, opacity: progress }}> | ||
Animates on progress | ||
</Animated.Text> | ||
</View> | ||
); | ||
}} | ||
</StackAnimationProgressContext.Consumer> | ||
); | ||
|
||
const YetAnotherScreen = () => ( | ||
<View | ||
style={{ | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
backgroundColor: 'papayawhip', | ||
}} | ||
> | ||
<StackAnimationIsSwipingContext.Consumer> | ||
{isSwiping => ( | ||
<Animated.Text | ||
style={{ | ||
fontSize: 24, | ||
opacity: Animated.interpolate(isSwiping, { | ||
inputRange: [0, 1], | ||
outputRange: [1, 0], | ||
}), | ||
}} | ||
> | ||
Disappears when swiping | ||
</Animated.Text> | ||
)} | ||
</StackAnimationIsSwipingContext.Consumer> | ||
<StackAnimationIsClosingContext.Consumer> | ||
{isClosing => ( | ||
<Animated.Text | ||
style={{ | ||
fontSize: 24, | ||
opacity: Animated.interpolate(isClosing, { | ||
inputRange: [0, 1], | ||
outputRange: [1, 0], | ||
}), | ||
}} | ||
> | ||
Disappears only when closing | ||
</Animated.Text> | ||
)} | ||
</StackAnimationIsClosingContext.Consumer> | ||
</View> | ||
); | ||
|
||
export default createStackNavigator( | ||
{ | ||
List: ListScreen, | ||
Another: AnotherScreen, | ||
YetAnother: YetAnotherScreen, | ||
}, | ||
{ initialRouteName: 'List' } | ||
); |
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
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,4 @@ | ||
import * as React from 'react'; | ||
import Animated from 'react-native-reanimated'; | ||
|
||
export default React.createContext<Animated.Node<0 | 1>>(new Animated.Value(0)); |
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,4 @@ | ||
import * as React from 'react'; | ||
import Animated from 'react-native-reanimated'; | ||
|
||
export default React.createContext<Animated.Node<0 | 1>>(new Animated.Value(0)); |
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,6 @@ | ||
import * as React from 'react'; | ||
import Animated from 'react-native-reanimated'; | ||
|
||
export default React.createContext<Animated.Value<number>>( | ||
new Animated.Value(0) | ||
); |
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