Skip to content

Commit

Permalink
refactor(#1): change types and routes
Browse files Browse the repository at this point in the history
  • Loading branch information
razvangeangu committed Apr 13, 2021
1 parent c291cdb commit 051e032
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.stylelint": false,
// "source.organizeImports": true,
"source.organizeImports": true,
"source.fixAll": true
},
"git.autofetch": true,
Expand Down
2 changes: 1 addition & 1 deletion ios/Chase/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>17</string>
<string>19</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
Expand Down
6 changes: 4 additions & 2 deletions src/app/components/FilledButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import React from 'react';
import { TouchableOpacity } from 'react-native-gesture-handler';
import styled from 'styled-components/native';

type ExtractProps<P> = P extends React.ComponentType<infer T> ? T : never;
export interface FilledButtonProps
extends Pick<ExtractProps<typeof TouchableOpacity>, 'onPress'> {
extends Pick<
typeof TouchableOpacity extends React.ComponentType<infer T> ? T : never,
'onPress'
> {
title: string;
}

Expand Down
6 changes: 4 additions & 2 deletions src/app/components/FlatButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import React from 'react';
import { TouchableOpacity } from 'react-native-gesture-handler';
import styled from 'styled-components/native';

type ExtractProps<P> = P extends React.ComponentType<infer T> ? T : never;
export interface FlatButtonProps
extends Pick<ExtractProps<typeof TouchableOpacity>, 'onPress'> {
extends Pick<
typeof TouchableOpacity extends React.ComponentType<infer T> ? T : never,
'onPress'
> {
title: string;
}

Expand Down
13 changes: 4 additions & 9 deletions src/app/pages/HomePage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { StackNavigationProp } from '@react-navigation/stack';
import moment from 'moment';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
Expand All @@ -15,6 +14,7 @@ import BottomSheet from 'reanimated-bottom-sheet';
import styled, { useTheme } from 'styled-components/native';
import { translations } from '../../../locales/translations';
import StyledText from '../../components/StyledText';
import NavigationProps from '../../router';
import CardPage from '../CardPage';
import ChaseLogo from './assets/chase-logo.svg';
import Settings from './assets/settings.svg';
Expand All @@ -23,14 +23,9 @@ const { width, height } = Dimensions.get('window');

const logoHeight = width / 14;

export interface HomePageProps {
navigation: StackNavigationProp<
{ Home: undefined; Settings: undefined },
'Home'
>;
}
export interface HomePageProps extends NavigationProps<'Home'> {}

export default function HomePage({ navigation }: HomePageProps) {
export default function HomePage({ navigation: { navigate } }: HomePageProps) {
const { i18n, t } = useTranslation();

const insets = useSafeAreaInsets();
Expand Down Expand Up @@ -77,7 +72,7 @@ export default function HomePage({ navigation }: HomePageProps) {
};

const handlePressSettings = () => {
navigation.navigate('Settings');
navigate('Settings');
};

return (
Expand Down
2 changes: 2 additions & 0 deletions src/app/pages/SettingsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { translations } from '../../../locales/translations';
import AuthContext from '../../../utils/auth-context';
import FilledButton from '../../components/FilledButton';

export interface SettingsPageProps {}

export default function SettingsPage() {
const theme = useTheme();

Expand Down
17 changes: 17 additions & 0 deletions src/app/router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { StackScreenProps } from '@react-navigation/stack';
import { HomePageProps } from './pages/HomePage/index';
import { SettingsPageProps } from './pages/SettingsPage';
import { TransactionsProps } from './pages/TransactionsPage';

type ParamList = {
Home?: HomePageProps;
Settings?: SettingsPageProps;
Transactions?: TransactionsProps;
};

type NavigationProps<RouteName extends keyof ParamList> = StackScreenProps<
ParamList,
RouteName
>;

export default NavigationProps;
8 changes: 3 additions & 5 deletions src/styles/StyledNavigationContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import React from 'react';
import { useColorScheme } from 'react-native';
import { useTheme } from 'styled-components/native';

type ExtractProps<P> = P extends React.ForwardRefExoticComponent<infer T>
? T
: never;

const StyledNavigationContainer: React.FC<
ExtractProps<typeof NavigationContainer>
typeof NavigationContainer extends React.ForwardRefExoticComponent<infer T>
? T
: never
> = props => {
const theme = useTheme();

Expand Down

0 comments on commit 051e032

Please sign in to comment.