Skip to content

Commit 7d1b1bc

Browse files
refactor: tweak cookbook (#1636)
* refactor: move files around * refactor: simplify * chore: remove custom fonts * chore: tweak eslint * chore: update yarn.lock
1 parent 10bda69 commit 7d1b1bc

File tree

19 files changed

+71
-73
lines changed

19 files changed

+71
-73
lines changed

examples/cookbook/.eslintrc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
{
2-
"extends": "@callstack"
2+
"extends": "@callstack",
3+
"rules": {
4+
"react-native-a11y/has-valid-accessibility-ignores-invert-colors": "off",
5+
"react-native/no-color-literals": "off",
6+
"react-native-a11y/has-valid-accessibility-descriptors": "off",
7+
}
38
}

examples/cookbook/app.json

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
"updates": {
1616
"fallbackToCacheTimeout": 0
1717
},
18-
"assetBundlePatterns": [
19-
"**/*"
20-
],
18+
"assetBundlePatterns": ["**/*"],
2119
"ios": {
2220
"supportsTablet": true
2321
},
@@ -30,17 +28,6 @@
3028
"web": {
3129
"favicon": "./assets/favicon.png"
3230
},
33-
"plugins": [
34-
"expo-router",
35-
[
36-
"expo-font",
37-
{
38-
"fonts": [
39-
"./assets/fonts/OpenSans-Regular.ttf",
40-
"./assets/fonts/OpenSans-Bold.ttf"
41-
]
42-
}
43-
]
44-
]
31+
"plugins": ["expo-router"]
4532
}
4633
}

examples/cookbook/app/_layout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as React from 'react';
12
import { Stack } from 'expo-router';
23
import theme from '../theme';
34

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as React from 'react';
2+
import { StyleSheet, Text, View } from 'react-native';
3+
import { useUser } from './providers/user-provider';
4+
import { useTheme } from './providers/theme-provider';
5+
6+
export default function WelcomeScreen() {
7+
const theme = useTheme();
8+
const user = useUser();
9+
10+
return (
11+
<View style={styles.container}>
12+
<Text>Hello {user ? user.name : 'Stranger'}</Text>
13+
<Text>Theme: {theme}</Text>
14+
</View>
15+
);
16+
}
17+
18+
const styles = StyleSheet.create({
19+
container: {
20+
flex: 1,
21+
justifyContent: 'center',
22+
alignItems: 'center',
23+
},
24+
});

examples/cookbook/__tests__/app/custom-render/index.test.tsx renamed to examples/cookbook/app/custom-render/__tests__/index.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { screen } from '@testing-library/react-native';
3+
import WelcomeScreen from '../WelcomeScreen';
34
import { renderWithProviders } from './test-utils';
4-
import WelcomeScreen from "../../../app/custom-render";
55

66
test('renders WelcomeScreen in light theme', () => {
77
renderWithProviders(<WelcomeScreen />, { theme: 'light' });

examples/cookbook/app/custom-render/_layout.tsx

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import * as React from 'react';
2-
import { Text, View } from 'react-native';
3-
import { useUser } from './providers/user-provider';
4-
import { useTheme } from './providers/theme-provider';
5-
6-
export default function WelcomeScreen() {
7-
const theme = useTheme();
8-
const user = useUser();
2+
import { UserProvider } from './providers/user-provider';
3+
import { ThemeProvider } from './providers/theme-provider';
4+
import WelcomeScreen from './WelcomeScreen';
95

6+
export default function Example() {
107
return (
11-
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
12-
<Text>Hello {user ? user.name : 'Stranger'}</Text>
13-
<Text>Theme: {theme}</Text>
14-
</View>
8+
<UserProvider.Provider value={null}>
9+
<ThemeProvider.Provider value={'light'}>
10+
<WelcomeScreen />
11+
</ThemeProvider.Provider>
12+
</UserProvider.Provider>
1513
);
1614
}

examples/cookbook/app/index.tsx

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,16 @@
1-
import React, {useCallback, useEffect} from 'react';
1+
import React from 'react';
22
import { FlatList, Image, Pressable, StyleSheet, Text, View } from 'react-native';
33
import { useRouter } from 'expo-router';
4-
import * as SplashScreen from 'expo-splash-screen';
5-
import { useFonts } from 'expo-font';
64
import theme from '../theme';
75

8-
void SplashScreen.preventAutoHideAsync();
9-
106
export default function Home() {
117
const router = useRouter();
12-
const [loaded, error] = useFonts({
13-
'OpenSans-Bold': require('../assets/fonts/OpenSans-Bold.ttf'),
14-
'OpenSans-Regular': require('../assets/fonts/OpenSans-Regular.ttf'),
15-
});
16-
17-
useEffect(() => {
18-
if (loaded || error) {
19-
void SplashScreen.hideAsync();
20-
}
21-
}, [loaded, error]);
228

23-
if (!loaded && !error) {
24-
return null;
25-
}
26-
const renderItem = useCallback(({ item }: {item: Recipe}) => (
27-
<Pressable style={styles.pressable} onPress={() => router.push(item.path)}>
9+
const renderItem = ({ item }: { item: Recipe }) => (
10+
<Pressable role="listitem" style={styles.pressable} onPress={() => router.push(item.path)}>
2811
<Text style={styles.pressableText}>{item.title}</Text>
2912
</Pressable>
30-
),[]);
13+
);
3114

3215
return (
3316
<View style={styles.container}>
@@ -41,6 +24,7 @@ export default function Home() {
4124
<Text style={styles.title}>Testing Library</Text>
4225
<Text style={styles.subTitle}>Cookbook App</Text>
4326
</View>
27+
4428
<FlatList<Recipe>
4529
data={recipes}
4630
renderItem={renderItem}
@@ -64,12 +48,10 @@ const styles = StyleSheet.create({
6448
},
6549
title: {
6650
fontSize: 20,
67-
fontFamily: 'OpenSans-Bold',
6851
color: theme.colors.black,
6952
},
7053
subTitle: {
7154
fontSize: 14,
72-
fontFamily: 'OpenSans-Regular',
7355
color: theme.colors.gray,
7456
},
7557
banner: {
@@ -89,7 +71,6 @@ const styles = StyleSheet.create({
8971
pressableText: {
9072
color: '#fff',
9173
fontSize: 14,
92-
fontFamily: 'OpenSans-Bold',
9374
textAlign: 'center',
9475
},
9576
});
@@ -99,6 +80,7 @@ type Recipe = {
9980
title: string;
10081
path: string;
10182
};
83+
10284
const recipes: Recipe[] = [
10385
{ id: 2, title: 'Welcome Screen with Custom Render', path: 'custom-render/' },
10486
{ id: 1, title: 'Task List with Jotai', path: 'jotai/' },

examples/cookbook/app/jotai/index.tsx renamed to examples/cookbook/app/state-management/jotai/TaskList.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import 'react-native-get-random-values';
22
import { nanoid } from 'nanoid';
33
import * as React from 'react';
4-
import { Pressable, Text, TextInput, View } from 'react-native';
4+
import { Pressable, StyleSheet, Text, TextInput, View } from 'react-native';
55
import { useAtom } from 'jotai';
66
import { newTaskTitleAtom, tasksAtom } from './state';
77

8-
export default function TaskList() {
8+
export function TaskList() {
99
const [tasks, setTasks] = useAtom(tasksAtom);
1010
const [newTaskTitle, setNewTaskTitle] = useAtom(newTaskTitleAtom);
1111

@@ -21,7 +21,7 @@ export default function TaskList() {
2121
};
2222

2323
return (
24-
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
24+
<View style={styles.container}>
2525
{tasks.map((task) => (
2626
<Text key={task.id} testID="task-item">
2727
{task.title}
@@ -43,3 +43,11 @@ export default function TaskList() {
4343
</View>
4444
);
4545
}
46+
47+
const styles = StyleSheet.create({
48+
container: {
49+
flex: 1,
50+
justifyContent: 'center',
51+
alignItems: 'center',
52+
},
53+
});

examples/cookbook/__tests__/app/jotai/index.test.tsx renamed to examples/cookbook/app/state-management/jotai/__tests__/TaskList.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as React from 'react';
22
import { render, screen, userEvent } from '@testing-library/react-native';
3-
import TaskList from '../../../app/jotai';
3+
import { TaskList } from '../TaskList';
4+
import { Task } from '../types';
5+
import { addTask, getAllTasks, newTaskTitleAtom, store, tasksAtom } from '../state';
46
import { renderWithAtoms } from './test-utils';
5-
import { Task } from '../../../app/jotai/types';
6-
import { addTask, getAllTasks, newTaskTitleAtom, store, tasksAtom } from '../../../app/jotai/state';
77

88
jest.useFakeTimers();
99

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as React from 'react';
2+
import { TaskList } from './TaskList';
3+
4+
export default function Example() {
5+
return <TaskList />;
6+
}
-128 KB
Binary file not shown.
Binary file not shown.

examples/cookbook/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"dependencies": {
1414
"expo": "^50.0.4",
1515
"expo-constants": "~15.4.6",
16-
"expo-font": "~11.10.3",
1716
"expo-linking": "~6.2.2",
1817
"expo-router": "~3.4.10",
18+
"expo-splash-screen": "~0.26.5",
1919
"expo-status-bar": "~1.11.1",
2020
"jotai": "^2.8.4",
2121
"nanoid": "^3.3.7",

examples/cookbook/yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10316,9 +10316,9 @@ __metadata:
1031610316
eslint: "npm:^8.57.0"
1031710317
expo: "npm:^50.0.4"
1031810318
expo-constants: "npm:~15.4.6"
10319-
expo-font: "npm:~11.10.3"
1032010319
expo-linking: "npm:~6.2.2"
1032110320
expo-router: "npm:~3.4.10"
10321+
expo-splash-screen: "npm:~0.26.5"
1032210322
expo-status-bar: "npm:~1.11.1"
1032310323
jest: "npm:^29.7.0"
1032410324
jotai: "npm:^2.8.4"

0 commit comments

Comments
 (0)