Skip to content

Commit

Permalink
chore: add some more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Jan 20, 2020
1 parent 321fa65 commit 65e5147
Show file tree
Hide file tree
Showing 14 changed files with 279 additions and 27 deletions.
1 change: 1 addition & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"color": "^3.1.2",
"expo": "^36.0.2",
"expo-asset": "~8.0.0",
"expo-blur": "^8.0.0",
"react": "~16.9.0",
"react-dom": "~16.9.0",
"react-native": "~0.61.5",
Expand Down
56 changes: 56 additions & 0 deletions example/src/Screens/DynamicTabs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import * as React from 'react';
import { View, StyleSheet } from 'react-native';
import { Title, Button } from 'react-native-paper';
import { Feather } from '@expo/vector-icons';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';

type BottomTabParams = {
[key: string]: undefined;
};

const BottomTabs = createBottomTabNavigator<BottomTabParams>();

export default function BottomTabsScreen() {
const [tabs, setTabs] = React.useState([0, 1]);

return (
<BottomTabs.Navigator>
{tabs.map(i => (
<BottomTabs.Screen
key={i}
name={`tab-${i}`}
options={{
title: `Tab ${i}`,
tabBarIcon: ({ color, size }) => (
<Feather name="octagon" color={color} size={size} />
),
}}
>
{() => (
<View style={styles.container}>
<Title>Tab {i}</Title>
<Button onPress={() => setTabs(tabs => [...tabs, tabs.length])}>
Add a tab
</Button>
<Button
onPress={() =>
setTabs(tabs => (tabs.length > 1 ? tabs.slice(0, -1) : tabs))
}
>
Remove a tab
</Button>
</View>
)}
</BottomTabs.Screen>
))}
</BottomTabs.Navigator>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
});
14 changes: 7 additions & 7 deletions example/src/Screens/ModalPresentationStack.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { View, StyleSheet } from 'react-native';
import { View, StyleSheet, ScrollView } from 'react-native';
import { Button } from 'react-native-paper';
import { RouteProp, ParamListBase } from '@react-navigation/native';
import {
Expand All @@ -25,7 +25,7 @@ const ArticleScreen = ({
route: RouteProp<ModalStackParams, 'Article'>;
}) => {
return (
<React.Fragment>
<ScrollView>
<View style={styles.buttons}>
<Button
mode="contained"
Expand All @@ -42,14 +42,14 @@ const ArticleScreen = ({
Go back
</Button>
</View>
<Article author={{ name: route.params.author }} />
</React.Fragment>
<Article author={{ name: route.params.author }} scrollEnabled={false} />
</ScrollView>
);
};

const AlbumsScreen = ({ navigation }: { navigation: ModalStackNavigation }) => {
return (
<React.Fragment>
<ScrollView>
<View style={styles.buttons}>
<Button
mode="contained"
Expand All @@ -66,8 +66,8 @@ const AlbumsScreen = ({ navigation }: { navigation: ModalStackNavigation }) => {
Go back
</Button>
</View>
<Albums />
</React.Fragment>
<Albums scrollEnabled={false} />
</ScrollView>
);
};

Expand Down
6 changes: 3 additions & 3 deletions example/src/Screens/NativeStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const AlbumsScreen = ({
}: {
navigation: NativeStackNavigation;
}) => (
<React.Fragment>
<ScrollView>
<View style={styles.buttons}>
<Button
mode="contained"
Expand All @@ -154,8 +154,8 @@ const AlbumsScreen = ({
Go back
</Button>
</View>
<Albums />
</React.Fragment>
<Albums scrollEnabled={false} />
</ScrollView>
);

const NativeStack = createNativeStackNavigator<NativeStackParams>();
Expand Down
14 changes: 7 additions & 7 deletions example/src/Screens/SimpleStack.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { View, StyleSheet } from 'react-native';
import { View, StyleSheet, ScrollView } from 'react-native';
import { Button } from 'react-native-paper';
import { RouteProp, ParamListBase } from '@react-navigation/native';
import {
Expand All @@ -24,7 +24,7 @@ const ArticleScreen = ({
route: RouteProp<SimpleStackParams, 'Article'>;
}) => {
return (
<React.Fragment>
<ScrollView>
<View style={styles.buttons}>
<Button
mode="contained"
Expand All @@ -41,8 +41,8 @@ const ArticleScreen = ({
Go back
</Button>
</View>
<Article author={{ name: route.params.author }} />
</React.Fragment>
<Article author={{ name: route.params.author }} scrollEnabled={false} />
</ScrollView>
);
};

Expand All @@ -52,7 +52,7 @@ const AlbumsScreen = ({
navigation: SimpleStackNavigation;
}) => {
return (
<React.Fragment>
<ScrollView>
<View style={styles.buttons}>
<Button
mode="contained"
Expand All @@ -69,8 +69,8 @@ const AlbumsScreen = ({
Go back
</Button>
</View>
<Albums />
</React.Fragment>
<Albums scrollEnabled={false} />
</ScrollView>
);
};

Expand Down
158 changes: 158 additions & 0 deletions example/src/Screens/StackHeaderCustomization.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import * as React from 'react';
import { View, StyleSheet, ScrollView, Alert, Platform } from 'react-native';
import { Button, Appbar } from 'react-native-paper';
import { BlurView } from 'expo-blur';
import { MaterialCommunityIcons } from '@expo/vector-icons';
import { RouteProp, ParamListBase } from '@react-navigation/native';
import {
createStackNavigator,
StackNavigationProp,
HeaderBackground,
useHeaderHeight,
} from '@react-navigation/stack';
import Article from '../Shared/Article';
import Albums from '../Shared/Albums';

type SimpleStackParams = {
Article: { author: string };
Album: undefined;
};

type SimpleStackNavigation = StackNavigationProp<SimpleStackParams>;

const ArticleScreen = ({
navigation,
route,
}: {
navigation: SimpleStackNavigation;
route: RouteProp<SimpleStackParams, 'Article'>;
}) => {
return (
<ScrollView>
<View style={styles.buttons}>
<Button
mode="contained"
onPress={() => navigation.push('Album')}
style={styles.button}
>
Push album
</Button>
<Button
mode="outlined"
onPress={() => navigation.goBack()}
style={styles.button}
>
Go back
</Button>
</View>
<Article author={{ name: route.params.author }} scrollEnabled={false} />
</ScrollView>
);
};

const AlbumsScreen = ({
navigation,
}: {
navigation: SimpleStackNavigation;
}) => {
const headerHeight = useHeaderHeight();

return (
<ScrollView contentContainerStyle={{ paddingTop: headerHeight }}>
<View style={styles.buttons}>
<Button
mode="contained"
onPress={() => navigation.push('Article', { author: 'Babel fish' })}
style={styles.button}
>
Push article
</Button>
<Button
mode="outlined"
onPress={() => navigation.goBack()}
style={styles.button}
>
Go back
</Button>
</View>
<Albums scrollEnabled={false} />
</ScrollView>
);
};

const SimpleStack = createStackNavigator<SimpleStackParams>();

type Props = Partial<React.ComponentProps<typeof SimpleStack.Navigator>> & {
navigation: StackNavigationProp<ParamListBase>;
};

export default function SimpleStackScreen({ navigation, ...rest }: Props) {
navigation.setOptions({
headerShown: false,
});

return (
<SimpleStack.Navigator {...rest}>
<SimpleStack.Screen
name="Article"
component={ArticleScreen}
options={({ route }) => ({
title: `Article by ${route.params?.author}`,
headerTintColor: '#fff',
headerStyle: { backgroundColor: '#ff005d' },
headerBackTitleVisible: false,
headerTitleAlign: 'center',
headerBackImage: ({ tintColor }) => (
<MaterialCommunityIcons
name="arrow-left-circle-outline"
color={tintColor}
size={24}
style={{ marginHorizontal: Platform.OS === 'ios' ? 8 : 0 }}
/>
),
headerRight: ({ tintColor }) => (
<Appbar.Action
color={tintColor}
icon="dots-horizontal-circle-outline"
onPress={() =>
Alert.alert(
'Never gonna give you up!',
'Never gonna let you down! Never gonna run around and desert you!'
)
}
/>
),
})}
initialParams={{ author: 'Gandalf' }}
/>
<SimpleStack.Screen
name="Album"
component={AlbumsScreen}
options={{
title: 'Album',
headerBackTitle: 'Back',
headerTransparent: true,
headerBackground: () => (
<HeaderBackground style={{ backgroundColor: 'transparent' }}>
<BlurView
tint="light"
intensity={75}
style={StyleSheet.absoluteFill}
/>
</HeaderBackground>
),
}}
/>
</SimpleStack.Navigator>
);
}

const styles = StyleSheet.create({
buttons: {
flexDirection: 'row',
padding: 8,
},
button: {
margin: 8,
},
});
11 changes: 9 additions & 2 deletions example/src/Shared/Albums.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/* eslint-disable import/no-commonjs */

import * as React from 'react';
import { Image, Dimensions, ScrollView, StyleSheet } from 'react-native';
import {
Image,
Dimensions,
ScrollView,
StyleSheet,
ScrollViewProps,
} from 'react-native';
import { useScrollToTop } from '@react-navigation/native';

const COVERS = [
Expand All @@ -15,7 +21,7 @@ const COVERS = [
require('../../assets/album-art-8.jpg'),
];

export default function Albums() {
export default function Albums(props: Partial<ScrollViewProps>) {
const ref = React.useRef<ScrollView>(null);

useScrollToTop(ref);
Expand All @@ -25,6 +31,7 @@ export default function Albums() {
ref={ref}
style={styles.container}
contentContainerStyle={styles.content}
{...props}
>
{COVERS.map((source, i) => (
// eslint-disable-next-line react/no-array-index-key
Expand Down
Loading

0 comments on commit 65e5147

Please sign in to comment.