Skip to content

Commit

Permalink
chore: use proper types for stack in example
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Sep 12, 2019
1 parent d9e1a5e commit 61e71ee
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 118 deletions.
2 changes: 1 addition & 1 deletion example/package.json
Expand Up @@ -24,7 +24,7 @@
"react-native-paper": "^2.15.2",
"react-navigation-drawer": "^2.0.1",
"react-navigation-header-buttons": "^3.0.2",
"react-navigation-stack": "^1.5.1",
"react-navigation-stack": "^1.7.2",
"react-navigation-tabs": "^1.2.0"
},
"devDependencies": {
Expand Down
21 changes: 10 additions & 11 deletions example/src/Drawer.tsx
Expand Up @@ -7,7 +7,10 @@ import {
NavigationScreenProp,
NavigationState,
} from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import {
createStackNavigator,
NavigationStackScreenProps,
} from 'react-navigation-stack';
import { createDrawerNavigator } from 'react-navigation-drawer';
import { Button } from './commonComponents/ButtonWithMargin';
import SampleText from './SampleText';
Expand Down Expand Up @@ -42,17 +45,13 @@ InboxScreen.navigationOptions = {
headerTitle: 'Inbox',
};

const EmailScreen = ({
navigation,
}: {
navigation: NavigationScreenProp<NavigationState>;
}) => <MyNavScreen banner="Email Screen" navigation={navigation} />;
const EmailScreen = ({ navigation }: NavigationStackScreenProps) => (
<MyNavScreen banner="Email Screen" navigation={navigation} />
);

const DraftsScreen = ({
navigation,
}: {
navigation: NavigationScreenProp<NavigationState>;
}) => <MyNavScreen banner="Drafts Screen" navigation={navigation} />;
const DraftsScreen = ({ navigation }: NavigationStackScreenProps) => (
<MyNavScreen banner="Drafts Screen" navigation={navigation} />
);
DraftsScreen.navigationOptions = {
headerTitle: 'Drafts',
};
Expand Down
18 changes: 9 additions & 9 deletions example/src/ModalStack.tsx
Expand Up @@ -6,7 +6,10 @@ import {
SafeAreaView,
NavigationState,
} from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import {
createStackNavigator,
NavigationStackScreenProps,
} from 'react-navigation-stack';
import { Button } from './commonComponents/ButtonWithMargin';
import SampleText from './SampleText';

Expand Down Expand Up @@ -95,16 +98,13 @@ const ProfileNavigator = createStackNavigator(
}
);

const MyHeaderTestScreen = ({
navigation,
}: {
navigation: NavigationScreenProp<NavigationState>;
}) => <MyNavScreen banner="Full screen view" navigation={navigation} />;
const MyHeaderTestScreen = ({ navigation }: NavigationStackScreenProps) => (
<MyNavScreen banner="Full screen view" navigation={navigation} />
);

MyHeaderTestScreen.navigationOptions = ({
navigation,
}: {
navigation: NavigationScreenProp<NavigationState>;
}) => {
}: NavigationStackScreenProps) => {
const headerVisible =
navigation.state.params && navigation.state.params.headerVisible;
return {
Expand Down
31 changes: 11 additions & 20 deletions example/src/SimpleStack.tsx
Expand Up @@ -5,29 +5,29 @@ import {
NavigationActions,
NavigationEventPayload,
NavigationEventSubscription,
NavigationScreenProp,
NavigationState,
NavigationStateRoute,
SafeAreaView,
StackActions,
Themed,
withNavigation,
} from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import {
createStackNavigator,
NavigationStackProp,
NavigationStackScreenProps,
} from 'react-navigation-stack';
import { Button } from './commonComponents/ButtonWithMargin';
import { HeaderButtons } from './commonComponents/HeaderButtons';
import SampleText from './SampleText';

const DEBUG = false;

interface MyNavScreenProps {
// TODO: satya164 - use stack's navigation type
navigation: any;
navigation: NavigationStackProp;
banner: React.ReactNode;
}

interface BackButtonProps {
navigation: NavigationScreenProp<NavigationStateRoute<any>>;
navigation: NavigationStackProp;
}

class MyBackButton extends React.Component<BackButtonProps, any> {
Expand Down Expand Up @@ -100,11 +100,7 @@ class MyNavScreen extends React.Component<MyNavScreenProps> {
}
}

interface MyHomeScreenProps {
navigation: NavigationScreenProp<NavigationState>;
}

class MyHomeScreen extends React.Component<MyHomeScreenProps> {
class MyHomeScreen extends React.Component<NavigationStackScreenProps> {
static navigationOptions = {
title: 'Welcome',
};
Expand Down Expand Up @@ -144,12 +140,7 @@ class MyHomeScreen extends React.Component<MyHomeScreenProps> {
}
}

interface MyPhotosScreenProps {
// TODO: satya164 - use stack's navigation type
navigation: any;
}

class MyPhotosScreen extends React.Component<MyPhotosScreenProps> {
class MyPhotosScreen extends React.Component<NavigationStackScreenProps> {
static navigationOptions = {
headerLeft: () => <MyBackButtonWithNavigation />,
title: 'Photos',
Expand Down Expand Up @@ -198,7 +189,7 @@ class MyPhotosScreen extends React.Component<MyPhotosScreenProps> {
const MyProfileScreen = ({
navigation,
}: {
navigation: NavigationScreenProp<NavigationState>;
navigation: NavigationStackProp;
}) => (
<MyNavScreen
banner={`${
Expand All @@ -208,7 +199,7 @@ const MyProfileScreen = ({
/>
);

MyProfileScreen.navigationOptions = (props: MyHomeScreenProps) => {
MyProfileScreen.navigationOptions = (props: NavigationStackScreenProps) => {
const { navigation } = props;
const { state, setParams } = navigation;
const { params } = state;
Expand Down
13 changes: 6 additions & 7 deletions example/src/StackWithCustomHeaderBackImage.tsx
Expand Up @@ -3,11 +3,13 @@ import { Button, Image, StyleSheet } from 'react-native';
import {
NavigationScreenProp,
NavigationState,
NavigationScreenConfigProps,
Themed,
SafeAreaView,
} from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import {
createStackNavigator,
NavigationStackScreenProps,
} from 'react-navigation-stack';
import SampleText from './SampleText';

interface MyNavScreenProps {
Expand Down Expand Up @@ -124,11 +126,8 @@ const StackWithCustomHeaderBackImage = createStackNavigator(
},
},
{
// TODO: satya164 - use stack's navigation type
defaultNavigationOptions: ({
theme,
}: NavigationScreenConfigProps<any>) => ({
headerBackImage: (
defaultNavigationOptions: ({ theme }: NavigationStackScreenProps) => ({
headerBackImage: () => (
<MyCustomHeaderBackImage
style={[
styles.myCustomHeaderBackImageAlt,
Expand Down
18 changes: 8 additions & 10 deletions example/src/StackWithHeaderPreset.tsx
@@ -1,15 +1,13 @@
import * as React from 'react';
import { SafeAreaView, Themed } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import {
createStackNavigator,
NavigationStackScreenProps,
} from 'react-navigation-stack';

import { Button } from './commonComponents/ButtonWithMargin';

interface NavScreenProps {
// TODO: satya164 - use stack's navigation type
navigation: any;
}

class HomeScreen extends React.Component<NavScreenProps> {
class HomeScreen extends React.Component<NavigationStackScreenProps> {
static navigationOptions = {
title: 'Welcome',
};
Expand All @@ -32,7 +30,7 @@ class HomeScreen extends React.Component<NavScreenProps> {
}
}

class OtherScreen extends React.Component<NavScreenProps> {
class OtherScreen extends React.Component<NavigationStackScreenProps> {
static navigationOptions = {
title: 'Your title here',
};
Expand All @@ -59,7 +57,7 @@ class OtherScreen extends React.Component<NavScreenProps> {
}
}

class ScreenWithLongTitle extends React.Component<NavScreenProps> {
class ScreenWithLongTitle extends React.Component<NavigationStackScreenProps> {
static navigationOptions = {
title: "Another title that's kind of long",
};
Expand All @@ -78,7 +76,7 @@ class ScreenWithLongTitle extends React.Component<NavScreenProps> {
}
}

class ScreenWithNoHeader extends React.Component<NavScreenProps> {
class ScreenWithNoHeader extends React.Component<NavigationStackScreenProps> {
static navigationOptions = {
header: null,
title: 'No Header',
Expand Down
17 changes: 8 additions & 9 deletions example/src/StackWithTranslucentHeader.tsx
Expand Up @@ -5,23 +5,22 @@ import { isIphoneX } from 'react-native-iphone-x-helper';
import {
NavigationEventPayload,
NavigationEventSubscription,
NavigationScreenProp,
NavigationState,
Themed,
SupportedThemes,
} from 'react-navigation';
import {
createStackNavigator,
Header,
HeaderStyleInterpolator,
NavigationStackScreenProps,
NavigationStackProp,
} from 'react-navigation-stack';
import { Button } from './commonComponents/ButtonWithMargin';
import { HeaderButtons } from './commonComponents/HeaderButtons';
import SampleText from './SampleText';

interface MyNavScreenProps {
// TODO: satya164 - use stack's navigation type
navigation: any;
navigation: NavigationStackProp;
banner: React.ReactNode;
}

Expand Down Expand Up @@ -82,7 +81,7 @@ class MyNavScreen extends React.Component<MyNavScreenProps> {
}

interface MyHomeScreenProps {
navigation: NavigationScreenProp<NavigationState>;
navigation: NavigationStackProp;
}

class MyHomeScreen extends React.Component<MyHomeScreenProps> {
Expand Down Expand Up @@ -126,7 +125,7 @@ class MyHomeScreen extends React.Component<MyHomeScreenProps> {
}

interface MyPhotosScreenProps {
navigation: NavigationScreenProp<NavigationState>;
navigation: NavigationStackProp;
}
class MyPhotosScreen extends React.Component<MyPhotosScreenProps> {
static navigationOptions = {
Expand Down Expand Up @@ -176,7 +175,7 @@ class MyPhotosScreen extends React.Component<MyPhotosScreenProps> {
const MyProfileScreen = ({
navigation,
}: {
navigation: NavigationScreenProp<NavigationState>;
navigation: NavigationStackProp;
}) => (
<MyNavScreen
banner={`${navigation.state.params!.mode === 'edit' ? 'Now Editing ' : ''}${
Expand All @@ -187,7 +186,7 @@ const MyProfileScreen = ({
);

MyProfileScreen.navigationOptions = (props: {
navigation: NavigationScreenProp<NavigationState>;
navigation: NavigationStackProp;
theme: SupportedThemes;
}) => {
const { navigation, theme } = props;
Expand Down Expand Up @@ -227,7 +226,7 @@ const StackWithTranslucentHeader = createStackNavigator(
},
},
{
defaultNavigationOptions: ({ theme }: { theme: SupportedThemes }) => ({
defaultNavigationOptions: ({ theme }: NavigationStackScreenProps) => ({
headerBackground:
Platform.OS === 'ios' ? (
<BlurView
Expand Down
24 changes: 11 additions & 13 deletions example/src/StacksAndKeys.tsx
@@ -1,18 +1,13 @@
import React from 'react';
import { Text, View } from 'react-native';
import { Themed } from 'react-navigation';
import {
NavigationScreenProp,
NavigationState,
Themed,
} from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
createStackNavigator,
NavigationStackScreenProps,
} from 'react-navigation-stack';
import { Button } from './commonComponents/ButtonWithMargin';

interface Props {
navigation: NavigationScreenProp<NavigationState & any>;
}

class HomeScreen extends React.Component<Props, any> {
class HomeScreen extends React.Component<NavigationStackScreenProps> {
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
Expand All @@ -37,9 +32,12 @@ class HomeScreen extends React.Component<Props, any> {
}
}

class ProfileScreen extends React.Component<any, any> {
class ProfileScreen extends React.Component<
NavigationStackScreenProps<{ homeKey: string }>
> {
render() {
const { homeKey } = this.props.navigation.state.params;
const homeKey = this.props.navigation.getParam('homeKey');

return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Profile</Text>
Expand All @@ -64,7 +62,7 @@ class ProfileScreen extends React.Component<any, any> {
}
}

class SettingsScreen extends React.Component<Props, any> {
class SettingsScreen extends React.Component<NavigationStackScreenProps> {
render() {
const { homeKey } = this.props.navigation.state.params!;

Expand Down
14 changes: 7 additions & 7 deletions example/src/StacksInTabs.tsx
Expand Up @@ -7,7 +7,11 @@ import {
SafeAreaView,
ScrollView,
} from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import {
createStackNavigator,
NavigationStackScreenProps,
NavigationStackProp,
} from 'react-navigation-stack';
import { createBottomTabNavigator } from 'react-navigation-tabs';
import { Ionicons } from '@expo/vector-icons';
import { Button } from './commonComponents/ButtonWithMargin';
Expand All @@ -19,7 +23,7 @@ Nulla convallis pulvinar hendrerit. Nulla mattis sem et aliquam ultrices. Nam eg
Praesent lobortis elit sit amet mauris pulvinar, viverra condimentum massa pellentesque. Curabitur massa ex, dignissim eget neque at, fringilla consectetur justo. Cras sollicitudin vel ligula sed cursus. Aliquam porta sem hendrerit diam porta ultricies. Sed eu mi erat. Curabitur id justo vel tortor hendrerit vestibulum id eget est. Morbi eros magna, placerat id diam ut, varius sollicitudin mi. Curabitur pretium finibus accumsan.`;

interface Props {
navigation: NavigationScreenProp<NavigationState>;
navigation: NavigationStackProp;
banner: string;
}

Expand Down Expand Up @@ -59,11 +63,7 @@ class MyNavScreen extends React.Component<Props> {
}
}

const MyProfileScreen = ({
navigation,
}: {
navigation: NavigationScreenProp<NavigationState>;
}) => (
const MyProfileScreen = ({ navigation }: NavigationStackScreenProps) => (
<MyNavScreen
banner={`${navigation.state.params!.name}s Profile`}
navigation={navigation}
Expand Down

0 comments on commit 61e71ee

Please sign in to comment.