@highbeek/create-rnstarterkit 1.0.2-beta.2 → 1.0.2-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/dist/bin/create-rnstarterkit.js +6 -0
  2. package/dist/src/generators/appGenerator.js +3 -1
  3. package/dist/templates/cli-base/.bundle/config +2 -0
  4. package/dist/templates/cli-base/.eslintrc.js +4 -0
  5. package/dist/templates/cli-base/.prettierrc.js +5 -0
  6. package/dist/templates/cli-base/.watchmanconfig +1 -0
  7. package/dist/templates/cli-base/App.tsx +45 -0
  8. package/dist/templates/cli-base/Gemfile +16 -0
  9. package/dist/templates/cli-base/Gemfile.lock +169 -0
  10. package/dist/templates/cli-base/README.md +97 -0
  11. package/dist/templates/cli-base/__tests__/App.test.tsx +13 -0
  12. package/dist/templates/cli-base/android/app/build.gradle +119 -0
  13. package/dist/templates/cli-base/android/app/debug.keystore +0 -0
  14. package/dist/templates/cli-base/android/app/proguard-rules.pro +10 -0
  15. package/dist/templates/cli-base/android/app/src/main/AndroidManifest.xml +27 -0
  16. package/dist/templates/cli-base/android/app/src/main/java/com/baseapp/MainActivity.kt +22 -0
  17. package/dist/templates/cli-base/android/app/src/main/java/com/baseapp/MainApplication.kt +27 -0
  18. package/dist/templates/cli-base/android/app/src/main/res/drawable/rn_edit_text_material.xml +37 -0
  19. package/dist/templates/cli-base/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  20. package/dist/templates/cli-base/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  21. package/dist/templates/cli-base/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  22. package/dist/templates/cli-base/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  23. package/dist/templates/cli-base/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  24. package/dist/templates/cli-base/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  25. package/dist/templates/cli-base/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  26. package/dist/templates/cli-base/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  27. package/dist/templates/cli-base/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  28. package/dist/templates/cli-base/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  29. package/dist/templates/cli-base/android/app/src/main/res/values/strings.xml +3 -0
  30. package/dist/templates/cli-base/android/app/src/main/res/values/styles.xml +9 -0
  31. package/dist/templates/cli-base/android/build.gradle +21 -0
  32. package/dist/templates/cli-base/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  33. package/dist/templates/cli-base/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  34. package/dist/templates/cli-base/android/gradle.properties +44 -0
  35. package/dist/templates/cli-base/android/gradlew +251 -0
  36. package/dist/templates/cli-base/android/gradlew.bat +99 -0
  37. package/dist/templates/cli-base/android/settings.gradle +6 -0
  38. package/dist/templates/cli-base/app.json +4 -0
  39. package/dist/templates/cli-base/babel.config.js +3 -0
  40. package/dist/templates/cli-base/index.js +9 -0
  41. package/dist/templates/cli-base/ios/.xcode.env +11 -0
  42. package/dist/templates/cli-base/ios/BaseApp/AppDelegate.swift +48 -0
  43. package/dist/templates/cli-base/ios/BaseApp/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
  44. package/dist/templates/cli-base/ios/BaseApp/Images.xcassets/Contents.json +6 -0
  45. package/dist/templates/cli-base/ios/BaseApp/Info.plist +60 -0
  46. package/dist/templates/cli-base/ios/BaseApp/LaunchScreen.storyboard +47 -0
  47. package/dist/templates/cli-base/ios/BaseApp/PrivacyInfo.xcprivacy +37 -0
  48. package/dist/templates/cli-base/ios/BaseApp.xcodeproj/project.pbxproj +494 -0
  49. package/dist/templates/cli-base/ios/BaseApp.xcodeproj/xcshareddata/xcschemes/BaseApp.xcscheme +88 -0
  50. package/dist/templates/cli-base/ios/BaseApp.xcworkspace/contents.xcworkspacedata +10 -0
  51. package/dist/templates/cli-base/ios/Podfile +34 -0
  52. package/dist/templates/cli-base/ios/Podfile.lock +2165 -0
  53. package/dist/templates/cli-base/jest.config.js +3 -0
  54. package/dist/templates/cli-base/metro.config.js +11 -0
  55. package/dist/templates/cli-base/package-lock.json +11859 -0
  56. package/dist/templates/cli-base/package.json +41 -0
  57. package/dist/templates/cli-base/tsconfig.json +8 -0
  58. package/dist/templates/expo-base/.vscode/extensions.json +1 -0
  59. package/dist/templates/expo-base/.vscode/settings.json +7 -0
  60. package/dist/templates/expo-base/README.md +50 -0
  61. package/dist/templates/expo-base/app/(tabs)/_layout.tsx +35 -0
  62. package/dist/templates/expo-base/app/(tabs)/explore.tsx +112 -0
  63. package/dist/templates/expo-base/app/(tabs)/index.tsx +98 -0
  64. package/dist/templates/expo-base/app/_layout.tsx +24 -0
  65. package/dist/templates/expo-base/app/modal.tsx +29 -0
  66. package/dist/templates/expo-base/app.json +48 -0
  67. package/dist/templates/expo-base/assets/images/android-icon-background.png +0 -0
  68. package/dist/templates/expo-base/assets/images/android-icon-foreground.png +0 -0
  69. package/dist/templates/expo-base/assets/images/android-icon-monochrome.png +0 -0
  70. package/dist/templates/expo-base/assets/images/favicon.png +0 -0
  71. package/dist/templates/expo-base/assets/images/icon.png +0 -0
  72. package/dist/templates/expo-base/assets/images/partial-react-logo.png +0 -0
  73. package/dist/templates/expo-base/assets/images/react-logo.png +0 -0
  74. package/dist/templates/expo-base/assets/images/react-logo@2x.png +0 -0
  75. package/dist/templates/expo-base/assets/images/react-logo@3x.png +0 -0
  76. package/dist/templates/expo-base/assets/images/splash-icon.png +0 -0
  77. package/dist/templates/expo-base/components/external-link.tsx +25 -0
  78. package/dist/templates/expo-base/components/haptic-tab.tsx +18 -0
  79. package/dist/templates/expo-base/components/hello-wave.tsx +19 -0
  80. package/dist/templates/expo-base/components/parallax-scroll-view.tsx +79 -0
  81. package/dist/templates/expo-base/components/themed-text.tsx +60 -0
  82. package/dist/templates/expo-base/components/themed-view.tsx +14 -0
  83. package/dist/templates/expo-base/components/ui/collapsible.tsx +45 -0
  84. package/dist/templates/expo-base/components/ui/icon-symbol.ios.tsx +32 -0
  85. package/dist/templates/expo-base/components/ui/icon-symbol.tsx +41 -0
  86. package/dist/templates/expo-base/constants/theme.ts +53 -0
  87. package/dist/templates/expo-base/eslint.config.js +10 -0
  88. package/dist/templates/expo-base/hooks/use-color-scheme.ts +1 -0
  89. package/dist/templates/expo-base/hooks/use-color-scheme.web.ts +21 -0
  90. package/dist/templates/expo-base/hooks/use-theme-color.ts +21 -0
  91. package/dist/templates/expo-base/package-lock.json +12916 -0
  92. package/dist/templates/expo-base/package.json +47 -0
  93. package/dist/templates/expo-base/scripts/reset-project.js +112 -0
  94. package/dist/templates/expo-base/tsconfig.json +17 -0
  95. package/dist/templates/optional/apiClient/api/client.ts +86 -0
  96. package/dist/templates/optional/apiClient/api/index.ts +1 -0
  97. package/dist/templates/optional/apiClient/config/env.cli.ts +5 -0
  98. package/dist/templates/optional/apiClient/config/env.expo.ts +4 -0
  99. package/dist/templates/optional/apiClient/config/env.ts +1 -0
  100. package/dist/templates/optional/apiClient/env.d.ts +3 -0
  101. package/dist/templates/optional/auth-context/api/authApi.ts +14 -0
  102. package/dist/templates/optional/auth-context/context/AuthContext.tsx +47 -0
  103. package/dist/templates/optional/auth-context/navigation/ProtectedStack.tsx +38 -0
  104. package/dist/templates/optional/auth-context/navigation/cli/BottomTabs.tsx +17 -0
  105. package/dist/templates/optional/auth-context/navigation/expo/BottomTabs.tsx +29 -0
  106. package/dist/templates/optional/auth-context/screens/HomeScreen.tsx +14 -0
  107. package/dist/templates/optional/auth-context/screens/LoginScreen.tsx +28 -0
  108. package/dist/templates/optional/auth-context/screens/ProfileScreen.tsx +10 -0
  109. package/dist/templates/optional/auth-context/screens/RegisterScreen.tsx +28 -0
  110. package/dist/templates/optional/auth-context/screens/SettingsScreen.tsx +10 -0
  111. package/dist/templates/optional/auth-context/utils/storage.ts +13 -0
  112. package/dist/templates/optional/auth-redux/api/authApi.ts +14 -0
  113. package/dist/templates/optional/auth-redux/navigation/ProtectedStack.tsx +30 -0
  114. package/dist/templates/optional/auth-redux/navigation/cli/BottomTabs.tsx +17 -0
  115. package/dist/templates/optional/auth-redux/navigation/expo/BottomTabs.tsx +31 -0
  116. package/dist/templates/optional/auth-redux/screens/HomeScreen.tsx +15 -0
  117. package/dist/templates/optional/auth-redux/screens/LoginScreen.tsx +29 -0
  118. package/dist/templates/optional/auth-redux/screens/ProfileScreen.tsx +14 -0
  119. package/dist/templates/optional/auth-redux/screens/RegisterScreen.tsx +14 -0
  120. package/dist/templates/optional/auth-redux/screens/SettingsScreen.tsx +14 -0
  121. package/dist/templates/optional/auth-redux/store/authSlice.ts +25 -0
  122. package/dist/templates/optional/auth-redux/store/store.ts +11 -0
  123. package/dist/templates/optional/auth-zustand/api/authApi.ts +14 -0
  124. package/dist/templates/optional/auth-zustand/navigation/BottomTabs.tsx +1 -0
  125. package/dist/templates/optional/auth-zustand/navigation/ProtectedStack.tsx +44 -0
  126. package/dist/templates/optional/auth-zustand/navigation/cli/BottomTabs.tsx +17 -0
  127. package/dist/templates/optional/auth-zustand/navigation/expo/BottomTabs.tsx +31 -0
  128. package/dist/templates/optional/auth-zustand/screens/HomeScreen.tsx +14 -0
  129. package/dist/templates/optional/auth-zustand/screens/LoginScreen.tsx +28 -0
  130. package/dist/templates/optional/auth-zustand/screens/ProfileScreen.tsx +10 -0
  131. package/dist/templates/optional/auth-zustand/screens/RegisterScreen.tsx +28 -0
  132. package/dist/templates/optional/auth-zustand/screens/SettingsScreen.tsx +10 -0
  133. package/dist/templates/optional/auth-zustand/store/authStore.ts +30 -0
  134. package/dist/templates/optional/auth-zustand/utils/storage.ts +13 -0
  135. package/package.json +2 -2
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "{{projectName}}",
3
+ "main": "expo-router/entry",
4
+ "version": "1.0.0",
5
+ "scripts": {
6
+ "start": "expo start",
7
+ "reset-project": "node ./scripts/reset-project.js",
8
+ "android": "expo start --android",
9
+ "ios": "expo start --ios",
10
+ "web": "expo start --web",
11
+ "lint": "expo lint"
12
+ },
13
+ "dependencies": {
14
+ "@expo/vector-icons": "^15.0.3",
15
+ "@react-navigation/bottom-tabs": "^7.4.0",
16
+ "@react-navigation/elements": "^2.6.3",
17
+ "@react-navigation/native": "^7.1.8",
18
+ "expo": "~54.0.33",
19
+ "expo-constants": "~18.0.13",
20
+ "expo-font": "~14.0.11",
21
+ "expo-haptics": "~15.0.8",
22
+ "expo-image": "~3.0.11",
23
+ "expo-linking": "~8.0.11",
24
+ "expo-router": "~6.0.23",
25
+ "expo-splash-screen": "~31.0.13",
26
+ "expo-status-bar": "~3.0.9",
27
+ "expo-symbols": "~1.0.8",
28
+ "expo-system-ui": "~6.0.9",
29
+ "expo-web-browser": "~15.0.10",
30
+ "react": "19.1.0",
31
+ "react-dom": "19.1.0",
32
+ "react-native": "0.81.5",
33
+ "react-native-gesture-handler": "~2.28.0",
34
+ "react-native-worklets": "0.5.1",
35
+ "react-native-reanimated": "~4.1.1",
36
+ "react-native-safe-area-context": "~5.6.0",
37
+ "react-native-screens": "~4.16.0",
38
+ "react-native-web": "~0.21.0"
39
+ },
40
+ "devDependencies": {
41
+ "@types/react": "~19.1.0",
42
+ "typescript": "~5.9.2",
43
+ "eslint": "^9.25.0",
44
+ "eslint-config-expo": "~10.0.0"
45
+ },
46
+ "private": true
47
+ }
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * This script is used to reset the project to a blank state.
5
+ * It deletes or moves the /app, /components, /hooks, /scripts, and /constants directories to /app-example based on user input and creates a new /app directory with an index.tsx and _layout.tsx file.
6
+ * You can remove the `reset-project` script from package.json and safely delete this file after running it.
7
+ */
8
+
9
+ const fs = require("fs");
10
+ const path = require("path");
11
+ const readline = require("readline");
12
+
13
+ const root = process.cwd();
14
+ const oldDirs = ["app", "components", "hooks", "constants", "scripts"];
15
+ const exampleDir = "app-example";
16
+ const newAppDir = "app";
17
+ const exampleDirPath = path.join(root, exampleDir);
18
+
19
+ const indexContent = `import { Text, View } from "react-native";
20
+
21
+ export default function Index() {
22
+ return (
23
+ <View
24
+ style={{
25
+ flex: 1,
26
+ justifyContent: "center",
27
+ alignItems: "center",
28
+ }}
29
+ >
30
+ <Text>Edit app/index.tsx to edit this screen.</Text>
31
+ </View>
32
+ );
33
+ }
34
+ `;
35
+
36
+ const layoutContent = `import { Stack } from "expo-router";
37
+
38
+ export default function RootLayout() {
39
+ return <Stack />;
40
+ }
41
+ `;
42
+
43
+ const rl = readline.createInterface({
44
+ input: process.stdin,
45
+ output: process.stdout,
46
+ });
47
+
48
+ const moveDirectories = async (userInput) => {
49
+ try {
50
+ if (userInput === "y") {
51
+ // Create the app-example directory
52
+ await fs.promises.mkdir(exampleDirPath, { recursive: true });
53
+ console.log(`📁 /${exampleDir} directory created.`);
54
+ }
55
+
56
+ // Move old directories to new app-example directory or delete them
57
+ for (const dir of oldDirs) {
58
+ const oldDirPath = path.join(root, dir);
59
+ if (fs.existsSync(oldDirPath)) {
60
+ if (userInput === "y") {
61
+ const newDirPath = path.join(root, exampleDir, dir);
62
+ await fs.promises.rename(oldDirPath, newDirPath);
63
+ console.log(`➡️ /${dir} moved to /${exampleDir}/${dir}.`);
64
+ } else {
65
+ await fs.promises.rm(oldDirPath, { recursive: true, force: true });
66
+ console.log(`❌ /${dir} deleted.`);
67
+ }
68
+ } else {
69
+ console.log(`➡️ /${dir} does not exist, skipping.`);
70
+ }
71
+ }
72
+
73
+ // Create new /app directory
74
+ const newAppDirPath = path.join(root, newAppDir);
75
+ await fs.promises.mkdir(newAppDirPath, { recursive: true });
76
+ console.log("\n📁 New /app directory created.");
77
+
78
+ // Create index.tsx
79
+ const indexPath = path.join(newAppDirPath, "index.tsx");
80
+ await fs.promises.writeFile(indexPath, indexContent);
81
+ console.log("📄 app/index.tsx created.");
82
+
83
+ // Create _layout.tsx
84
+ const layoutPath = path.join(newAppDirPath, "_layout.tsx");
85
+ await fs.promises.writeFile(layoutPath, layoutContent);
86
+ console.log("📄 app/_layout.tsx created.");
87
+
88
+ console.log("\n✅ Project reset complete. Next steps:");
89
+ console.log(
90
+ `1. Run \`npx expo start\` to start a development server.\n2. Edit app/index.tsx to edit the main screen.${
91
+ userInput === "y"
92
+ ? `\n3. Delete the /${exampleDir} directory when you're done referencing it.`
93
+ : ""
94
+ }`
95
+ );
96
+ } catch (error) {
97
+ console.error(`❌ Error during script execution: ${error.message}`);
98
+ }
99
+ };
100
+
101
+ rl.question(
102
+ "Do you want to move existing files to /app-example instead of deleting them? (Y/n): ",
103
+ (answer) => {
104
+ const userInput = answer.trim().toLowerCase() || "y";
105
+ if (userInput === "y" || userInput === "n") {
106
+ moveDirectories(userInput).finally(() => rl.close());
107
+ } else {
108
+ console.log("❌ Invalid input. Please enter 'Y' or 'N'.");
109
+ rl.close();
110
+ }
111
+ }
112
+ );
@@ -0,0 +1,17 @@
1
+ {
2
+ "extends": "expo/tsconfig.base",
3
+ "compilerOptions": {
4
+ "strict": true,
5
+ "paths": {
6
+ "@/*": [
7
+ "./*"
8
+ ]
9
+ }
10
+ },
11
+ "include": [
12
+ "**/*.ts",
13
+ "**/*.tsx",
14
+ ".expo/types/**/*.ts",
15
+ "expo-env.d.ts"
16
+ ]
17
+ }
@@ -0,0 +1,86 @@
1
+ import { API_BASE_URL } from "../config/env";
2
+
3
+ export class ApiError extends Error {
4
+ status: number;
5
+ data: unknown;
6
+
7
+ constructor(status: number, message: string, data: unknown) {
8
+ super(message);
9
+ this.name = "ApiError";
10
+ this.status = status;
11
+ this.data = data;
12
+ }
13
+ }
14
+
15
+ type RequestOptions = {
16
+ headers?: Record<string, string>;
17
+ query?: Record<string, string | number | boolean | undefined>;
18
+ body?: unknown;
19
+ token?: string | null;
20
+ signal?: AbortSignal;
21
+ };
22
+
23
+ function buildUrl(path: string, query?: RequestOptions["query"]) {
24
+ const normalizedPath = path.startsWith("/") ? path : `/${path}`;
25
+ const url = new URL(`${API_BASE_URL}${normalizedPath}`);
26
+
27
+ if (query) {
28
+ Object.entries(query).forEach(([key, value]) => {
29
+ if (value !== undefined) url.searchParams.set(key, String(value));
30
+ });
31
+ }
32
+
33
+ return url.toString();
34
+ }
35
+
36
+ async function parseResponse<T>(response: Response): Promise<T> {
37
+ const contentType = response.headers.get("content-type") || "";
38
+ const data = contentType.includes("application/json")
39
+ ? await response.json()
40
+ : await response.text();
41
+
42
+ if (!response.ok) {
43
+ const message =
44
+ typeof data === "object" && data !== null && "message" in data
45
+ ? String((data as { message: unknown }).message)
46
+ : `Request failed with status ${response.status}`;
47
+
48
+ throw new ApiError(response.status, message, data);
49
+ }
50
+
51
+ return data as T;
52
+ }
53
+
54
+ async function request<T>(
55
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE",
56
+ path: string,
57
+ options: RequestOptions = {},
58
+ ): Promise<T> {
59
+ const { headers = {}, query, body, token, signal } = options;
60
+
61
+ const response = await fetch(buildUrl(path, query), {
62
+ method,
63
+ headers: {
64
+ "Content-Type": "application/json",
65
+ ...(token ? { Authorization: `Bearer ${token}` } : {}),
66
+ ...headers,
67
+ },
68
+ body: body === undefined ? undefined : JSON.stringify(body),
69
+ signal,
70
+ });
71
+
72
+ return parseResponse<T>(response);
73
+ }
74
+
75
+ export const apiClient = {
76
+ get: <T>(path: string, options?: Omit<RequestOptions, "body">) =>
77
+ request<T>("GET", path, options),
78
+ post: <T>(path: string, body?: unknown, options?: RequestOptions) =>
79
+ request<T>("POST", path, { ...options, body }),
80
+ put: <T>(path: string, body?: unknown, options?: RequestOptions) =>
81
+ request<T>("PUT", path, { ...options, body }),
82
+ patch: <T>(path: string, body?: unknown, options?: RequestOptions) =>
83
+ request<T>("PATCH", path, { ...options, body }),
84
+ delete: <T>(path: string, options?: Omit<RequestOptions, "body">) =>
85
+ request<T>("DELETE", path, options),
86
+ };
@@ -0,0 +1 @@
1
+ export * from "./client";
@@ -0,0 +1,5 @@
1
+ import { API_BASE_URL as DOTENV_API_BASE_URL } from "@env";
2
+
3
+ const FALLBACK_API_URL = "https://example.com/api";
4
+
5
+ export const API_BASE_URL = DOTENV_API_BASE_URL || FALLBACK_API_URL;
@@ -0,0 +1,4 @@
1
+ const FALLBACK_API_URL = "https://example.com/api";
2
+
3
+ export const API_BASE_URL =
4
+ process.env.EXPO_PUBLIC_API_URL ?? process.env.API_BASE_URL ?? FALLBACK_API_URL;
@@ -0,0 +1 @@
1
+ export { API_BASE_URL } from "./env.expo";
@@ -0,0 +1,3 @@
1
+ declare module "@env" {
2
+ export const API_BASE_URL: string;
3
+ }
@@ -0,0 +1,14 @@
1
+ function assertCredentials(email: string, password: string) {
2
+ if (!email.trim()) throw new Error("Email is required");
3
+ if (!password.trim()) throw new Error("Password is required");
4
+ }
5
+
6
+ export const loginApi = async (email: string, password: string) => {
7
+ assertCredentials(email, password);
8
+ return `demo-token-${email.trim().toLowerCase()}`;
9
+ };
10
+
11
+ export const registerApi = async (email: string, password: string) => {
12
+ assertCredentials(email, password);
13
+ return `demo-token-${email.trim().toLowerCase()}`;
14
+ };
@@ -0,0 +1,47 @@
1
+ import React, { createContext, ReactNode, useEffect, useState } from "react";
2
+ import { getToken, removeToken, storeToken } from "../utils/storage";
3
+
4
+ interface AuthContextType {
5
+ token: string | null;
6
+ isHydrated: boolean;
7
+ login: (token: string) => Promise<void>;
8
+ logout: () => Promise<void>;
9
+ }
10
+
11
+ export const AuthContext = createContext<AuthContextType>({
12
+ token: null,
13
+ isHydrated: false,
14
+ login: async () => {},
15
+ logout: async () => {},
16
+ });
17
+
18
+ export const AuthProvider = ({ children }: { children: ReactNode }) => {
19
+ const [token, setToken] = useState<string | null>(null);
20
+ const [isHydrated, setIsHydrated] = useState(false);
21
+
22
+ useEffect(() => {
23
+ const hydrate = async () => {
24
+ const savedToken = await getToken();
25
+ setToken(savedToken);
26
+ setIsHydrated(true);
27
+ };
28
+
29
+ void hydrate();
30
+ }, []);
31
+
32
+ const login = async (nextToken: string) => {
33
+ setToken(nextToken);
34
+ await storeToken(nextToken);
35
+ };
36
+
37
+ const logout = async () => {
38
+ setToken(null);
39
+ await removeToken();
40
+ };
41
+
42
+ return (
43
+ <AuthContext.Provider value={{ token, isHydrated, login, logout }}>
44
+ {children}
45
+ </AuthContext.Provider>
46
+ );
47
+ };
@@ -0,0 +1,38 @@
1
+ import React, { useContext } from "react";
2
+ import { ActivityIndicator, View } from "react-native";
3
+ import { createNativeStackNavigator } from "@react-navigation/native-stack";
4
+ import { AuthContext } from "../context/AuthContext";
5
+ import LoginScreen from "../screens/LoginScreen";
6
+ import RegisterScreen from "../screens/RegisterScreen";
7
+ import BottomTabs from "./BottomTabs";
8
+
9
+ const Stack = createNativeStackNavigator();
10
+
11
+ export default function ProtectedStack() {
12
+ const { token, isHydrated } = useContext(AuthContext);
13
+
14
+ if (!isHydrated) {
15
+ return (
16
+ <View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
17
+ <ActivityIndicator />
18
+ </View>
19
+ );
20
+ }
21
+
22
+ return (
23
+ <Stack.Navigator>
24
+ {token ? (
25
+ <Stack.Screen
26
+ name="Main"
27
+ component={BottomTabs}
28
+ options={{ headerShown: false }}
29
+ />
30
+ ) : (
31
+ <>
32
+ <Stack.Screen name="Login" component={LoginScreen} />
33
+ <Stack.Screen name="Register" component={RegisterScreen} />
34
+ </>
35
+ )}
36
+ </Stack.Navigator>
37
+ );
38
+ }
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+ import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
3
+ import HomeScreen from "../../screens/HomeScreen";
4
+ import ProfileScreen from "../../screens/ProfileScreen";
5
+ import SettingsScreen from "../../screens/SettingsScreen";
6
+
7
+ const Tab = createBottomTabNavigator();
8
+
9
+ export default function BottomTabs() {
10
+ return (
11
+ <Tab.Navigator screenOptions={{ headerShown: false }}>
12
+ <Tab.Screen name="Home" component={HomeScreen} />
13
+ <Tab.Screen name="Profile" component={ProfileScreen} />
14
+ <Tab.Screen name="Settings" component={SettingsScreen} />
15
+ </Tab.Navigator>
16
+ );
17
+ }
@@ -0,0 +1,29 @@
1
+ import React from "react";
2
+ import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
3
+ import { Ionicons } from "@expo/vector-icons";
4
+ import HomeScreen from "../../screens/HomeScreen";
5
+ import ProfileScreen from "../../screens/ProfileScreen";
6
+ import SettingsScreen from "../../screens/SettingsScreen";
7
+
8
+ const Tab = createBottomTabNavigator();
9
+
10
+ export default function BottomTabs() {
11
+ return (
12
+ <Tab.Navigator
13
+ screenOptions={({ route }) => ({
14
+ headerShown: false,
15
+ tabBarIcon: ({ color, size }) => {
16
+ let iconName: string = "home";
17
+ if (route.name === "Home") iconName = "home";
18
+ else if (route.name === "Profile") iconName = "person";
19
+ else if (route.name === "Settings") iconName = "settings";
20
+ return <Ionicons name={iconName as any} size={size} color={color} />;
21
+ },
22
+ })}
23
+ >
24
+ <Tab.Screen name="Home" component={HomeScreen} />
25
+ <Tab.Screen name="Profile" component={ProfileScreen} />
26
+ <Tab.Screen name="Settings" component={SettingsScreen} />
27
+ </Tab.Navigator>
28
+ );
29
+ }
@@ -0,0 +1,14 @@
1
+ import React, { useContext } from "react";
2
+ import { View, Text, Button } from "react-native";
3
+ import { AuthContext } from "../context/AuthContext";
4
+
5
+ export default function HomeScreen() {
6
+ const { logout } = useContext(AuthContext);
7
+
8
+ return (
9
+ <View style={{ padding: 20 }}>
10
+ <Text>Welcome Home!</Text>
11
+ <Button title="Logout" onPress={() => void logout()} />
12
+ </View>
13
+ );
14
+ }
@@ -0,0 +1,28 @@
1
+ import React, { useContext, useState } from "react";
2
+ import { View, TextInput, Button } from "react-native";
3
+ import { AuthContext } from "../context/AuthContext";
4
+ import { loginApi } from "../api/authApi";
5
+
6
+ export default function LoginScreen() {
7
+ const { login } = useContext(AuthContext);
8
+ const [email, setEmail] = useState("");
9
+ const [password, setPassword] = useState("");
10
+
11
+ const handleLogin = async () => {
12
+ const token = await loginApi(email, password);
13
+ await login(token);
14
+ };
15
+
16
+ return (
17
+ <View style={{ padding: 20 }}>
18
+ <TextInput placeholder="Email" value={email} onChangeText={setEmail} />
19
+ <TextInput
20
+ placeholder="Password"
21
+ value={password}
22
+ onChangeText={setPassword}
23
+ secureTextEntry
24
+ />
25
+ <Button title="Login" onPress={() => void handleLogin()} />
26
+ </View>
27
+ );
28
+ }
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+ import { View, Text } from "react-native";
3
+
4
+ export default function ProfileScreen() {
5
+ return (
6
+ <View style={{ padding: 20 }}>
7
+ <Text>This is the Profile Screen</Text>
8
+ </View>
9
+ );
10
+ }
@@ -0,0 +1,28 @@
1
+ import React, { useContext, useState } from "react";
2
+ import { View, TextInput, Button } from "react-native";
3
+ import { AuthContext } from "../context/AuthContext";
4
+ import { registerApi } from "../api/authApi";
5
+
6
+ export default function RegisterScreen() {
7
+ const { login } = useContext(AuthContext);
8
+ const [email, setEmail] = useState("");
9
+ const [password, setPassword] = useState("");
10
+
11
+ const handleRegister = async () => {
12
+ const token = await registerApi(email, password);
13
+ await login(token);
14
+ };
15
+
16
+ return (
17
+ <View style={{ padding: 20 }}>
18
+ <TextInput placeholder="Email" value={email} onChangeText={setEmail} />
19
+ <TextInput
20
+ placeholder="Password"
21
+ value={password}
22
+ onChangeText={setPassword}
23
+ secureTextEntry
24
+ />
25
+ <Button title="Register" onPress={() => void handleRegister()} />
26
+ </View>
27
+ );
28
+ }
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+ import { View, Text } from "react-native";
3
+
4
+ export default function SettingsScreen() {
5
+ return (
6
+ <View style={{ padding: 20 }}>
7
+ <Text>This is the Settings Screen</Text>
8
+ </View>
9
+ );
10
+ }
@@ -0,0 +1,13 @@
1
+ import AsyncStorage from "@react-native-async-storage/async-storage";
2
+
3
+ export const storeToken = async (token: string) => {
4
+ await AsyncStorage.setItem("@token", token);
5
+ };
6
+
7
+ export const getToken = async () => {
8
+ return await AsyncStorage.getItem("@token");
9
+ };
10
+
11
+ export const removeToken = async () => {
12
+ await AsyncStorage.removeItem("@token");
13
+ };
@@ -0,0 +1,14 @@
1
+ function assertCredentials(email: string, password: string) {
2
+ if (!email.trim()) throw new Error("Email is required");
3
+ if (!password.trim()) throw new Error("Password is required");
4
+ }
5
+
6
+ export const loginApi = async (email: string, password: string) => {
7
+ assertCredentials(email, password);
8
+ return `demo-token-${email.trim().toLowerCase()}`;
9
+ };
10
+
11
+ export const registerApi = async (email: string, password: string) => {
12
+ assertCredentials(email, password);
13
+ return `demo-token-${email.trim().toLowerCase()}`;
14
+ };
@@ -0,0 +1,30 @@
1
+ import React from "react";
2
+ import { createNativeStackNavigator } from "@react-navigation/native-stack";
3
+ import { useSelector } from "react-redux";
4
+ import type { RootState } from "../store/store";
5
+ import LoginScreen from "../screens/LoginScreen";
6
+ import RegisterScreen from "../screens/RegisterScreen";
7
+ import BottomTabs from "./BottomTabs";
8
+
9
+ const Stack = createNativeStackNavigator();
10
+
11
+ export default function ProtectedStack() {
12
+ const token = useSelector((state: RootState) => state.auth.token);
13
+
14
+ return (
15
+ <Stack.Navigator>
16
+ {token ? (
17
+ <Stack.Screen
18
+ name="Main"
19
+ component={BottomTabs}
20
+ options={{ headerShown: false }}
21
+ />
22
+ ) : (
23
+ <>
24
+ <Stack.Screen name="Login" component={LoginScreen} />
25
+ <Stack.Screen name="Register" component={RegisterScreen} />
26
+ </>
27
+ )}
28
+ </Stack.Navigator>
29
+ );
30
+ }
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+ import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
3
+ import HomeScreen from "../../screens/HomeScreen";
4
+ import ProfileScreen from "../../screens/ProfileScreen";
5
+ import SettingsScreen from "../../screens/SettingsScreen";
6
+
7
+ const Tab = createBottomTabNavigator();
8
+
9
+ export default function BottomTabs() {
10
+ return (
11
+ <Tab.Navigator screenOptions={{ headerShown: false }}>
12
+ <Tab.Screen name="Home" component={HomeScreen} />
13
+ <Tab.Screen name="Profile" component={ProfileScreen} />
14
+ <Tab.Screen name="Settings" component={SettingsScreen} />
15
+ </Tab.Navigator>
16
+ );
17
+ }
@@ -0,0 +1,31 @@
1
+ import React from "react";
2
+ import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
3
+ import { Ionicons } from "@expo/vector-icons";
4
+ import HomeScreen from "../../screens/HomeScreen";
5
+ import ProfileScreen from "../../screens/ProfileScreen";
6
+ import SettingsScreen from "../../screens/SettingsScreen";
7
+
8
+ const Tab = createBottomTabNavigator();
9
+
10
+ export default function BottomTabs() {
11
+ return (
12
+ <Tab.Navigator
13
+ screenOptions={({ route }) => ({
14
+ headerShown: false,
15
+ tabBarIcon: ({ color, size }) => {
16
+ let iconName: string = "home";
17
+
18
+ if (route.name === "Home") iconName = "home";
19
+ else if (route.name === "Profile") iconName = "person";
20
+ else if (route.name === "Settings") iconName = "settings";
21
+
22
+ return <Ionicons name={iconName as any} size={size} color={color} />;
23
+ },
24
+ })}
25
+ >
26
+ <Tab.Screen name="Home" component={HomeScreen} />
27
+ <Tab.Screen name="Profile" component={ProfileScreen} />
28
+ <Tab.Screen name="Settings" component={SettingsScreen} />
29
+ </Tab.Navigator>
30
+ );
31
+ }
@@ -0,0 +1,15 @@
1
+ import React from "react";
2
+ import { View, Text, Button } from "react-native";
3
+ import { useDispatch } from "react-redux";
4
+ import { logout } from "../store/authSlice";
5
+
6
+ export default function HomeScreen() {
7
+ const dispatch = useDispatch();
8
+
9
+ return (
10
+ <View style={{ padding: 20 }}>
11
+ <Text>Welcome Home!</Text>
12
+ <Button title="Logout" onPress={() => dispatch(logout())} />
13
+ </View>
14
+ );
15
+ }