Skip to content

Commit 1da94d6

Browse files
committed
feat: 🔖 update react native deps and improve code structure
1 parent c8a1a3f commit 1da94d6

File tree

19 files changed

+204
-103
lines changed

19 files changed

+204
-103
lines changed

template/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { MMKV } from 'react-native-mmkv';
44

55
import { ThemeProvider } from '@/theme';
66

7-
import ApplicationNavigator from './navigators/Application';
7+
import ApplicationNavigator from '@/navigations/Application';
88
import './translations';
99

1010
export const queryClient = new QueryClient();
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {createStackNavigator} from '@react-navigation/stack';
2+
import {NavigationContainer} from '@react-navigation/native';
3+
import {SafeAreaProvider} from 'react-native-safe-area-context';
4+
5+
import {Example, Startup} from '@/screens';
6+
import {useTheme} from '@/theme';
7+
import {RootStackParamList} from "@/navigations/types";
8+
import {Paths} from "@/navigations/paths";
9+
10+
const Stack = createStackNavigator<RootStackParamList>();
11+
12+
function ApplicationNavigator() {
13+
const { variant, navigationTheme } = useTheme();
14+
15+
return (
16+
<SafeAreaProvider>
17+
<NavigationContainer theme={navigationTheme}>
18+
<Stack.Navigator key={variant} screenOptions={{ headerShown: false }}>
19+
<Stack.Screen name={Paths.Startup} component={Startup} />
20+
<Stack.Screen name={Paths.Example} component={Example} />
21+
</Stack.Navigator>
22+
</NavigationContainer>
23+
</SafeAreaProvider>
24+
);
25+
}
26+
27+
export default ApplicationNavigator;

template/src/navigations/paths.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum Paths {
2+
Startup = 'startup',
3+
Example = 'example'
4+
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import type { StackScreenProps } from '@react-navigation/stack';
2+
import {Paths} from "@/navigations/paths";
23

34
export type RootStackParamList = {
4-
Startup: undefined;
5-
Example: undefined;
5+
[Paths.Startup]: undefined;
6+
[Paths.Example]: undefined;
67
};
78

89
export type RootScreenProps<
9-
S extends keyof RootStackParamList = keyof RootStackParamList,
10+
S extends keyof RootStackParamList = keyof RootStackParamList,
1011
> = StackScreenProps<RootStackParamList, S>;

template/src/navigators/Application.tsx

Lines changed: 0 additions & 27 deletions
This file was deleted.

template/src/services/userService.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {instance} from "@/services/instance";
2+
import {userSchema} from "@/types/schemas/user";
3+
4+
export const UserServices = {
5+
fetchOne: async (id: number) => {
6+
const response = await instance.get(`users/${id}`).json();
7+
return userSchema.parse(response);
8+
}
9+
}

template/src/services/users/fetchOne.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

template/src/services/users/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

template/src/theme/ThemeProvider/ThemeProvider.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ import {
1616
generateBorderColors,
1717
generateBorderRadius,
1818
generateBorderWidths,
19+
staticBorderStyles
1920
} from '@/theme/borders';
2021
import layout from '@/theme/layout';
2122
import componentsGenerator from '@/theme/components';
22-
import { generateBackgrounds } from '@/theme/backgrounds';
23-
import { generateGutters } from '@/theme/gutters';
23+
import { generateBackgrounds, staticBackgroundStyles } from '@/theme/backgrounds';
24+
import { generateGutters, staticGutterStyles } from '@/theme/gutters';
2425
import generateConfig from '@/theme/ThemeProvider/generateConfig';
2526

2627
import type { MMKV } from 'react-native-mmkv';
@@ -76,14 +77,25 @@ function ThemeProvider({ children = false, storage }: Props) {
7677
}, [fullConfig]);
7778

7879
const backgrounds = useMemo(() => {
79-
return generateBackgrounds(fullConfig);
80+
return {
81+
...generateBackgrounds(fullConfig),
82+
...staticBackgroundStyles
83+
};
84+
}, [fullConfig]);
85+
86+
const gutters = useMemo(() => {
87+
return {
88+
...generateGutters(fullConfig),
89+
...staticGutterStyles
90+
};
8091
}, [fullConfig]);
8192

8293
const borders = useMemo(() => {
8394
return {
8495
...generateBorderColors(fullConfig),
8596
...generateBorderRadius(),
8697
...generateBorderWidths(),
98+
...staticBorderStyles,
8799
};
88100
}, [fullConfig]);
89101

@@ -98,7 +110,7 @@ function ThemeProvider({ children = false, storage }: Props) {
98110
return {
99111
colors: fullConfig.colors,
100112
variant,
101-
gutters: generateGutters(),
113+
gutters,
102114
layout,
103115
fonts,
104116
backgrounds,

template/src/theme/ThemeProvider/generateConfig.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
11
import { config } from '@/theme/_config';
2-
import { hasProperty } from '@/types/guards/theme';
32

43
import type {
54
FulfilledThemeConfiguration,
65
Variant,
76
} from '@/types/theme/config';
87

8+
import type { HasProperty } from '@/types/theme/common';
9+
10+
function hasProperty<Config, KeyPath extends string>(
11+
configuration: Config,
12+
property: KeyPath,
13+
): configuration is HasProperty<Config, KeyPath> & Config {
14+
const parts = property.split('.');
15+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
16+
let currentObj: any = configuration;
17+
18+
for (let i = 0; i < parts.length; i += 1) {
19+
const part = parts[i];
20+
if (!(part in currentObj)) {
21+
return false;
22+
}
23+
24+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
25+
currentObj = currentObj[part];
26+
}
27+
28+
return true;
29+
}
30+
931
export default (variant: Variant) => {
1032
const { variants, ...defaultConfig } = config;
1133
const variantConfig = variant !== 'default' ? variants[variant] : null;

0 commit comments

Comments
 (0)