create-rn-folder-structure 1.0.4 → 1.0.7
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.
- package/README.md +3 -1
- package/generators/features.js +107 -1
- package/generators/navigation.js +18 -15
- package/package.json +2 -2
package/README.md
CHANGED
package/generators/features.js
CHANGED
|
@@ -14,6 +14,112 @@ module.exports = function generateFeatures(projectRoot) {
|
|
|
14
14
|
const features = ["auth", "profile", "dashboard", "settings"];
|
|
15
15
|
|
|
16
16
|
features.forEach((feature) => {
|
|
17
|
+
|
|
18
|
+
// --- Handle AUTH feature differently ---
|
|
19
|
+
if (feature === "auth") {
|
|
20
|
+
write(
|
|
21
|
+
projectRoot,
|
|
22
|
+
`src/features/${feature}/screens/${capitalize(feature)}Screen.tsx`,
|
|
23
|
+
`
|
|
24
|
+
import { useNavigation } from '@react-navigation/native';
|
|
25
|
+
import React, { useContext, useState } from 'react';
|
|
26
|
+
import { View, Text, TextInput, TouchableOpacity, StyleSheet } from 'react-native';
|
|
27
|
+
import { AuthContext } from '../../../app/navigation/RootNavigator';
|
|
28
|
+
import { saveToken } from '../../../services/storage/token';
|
|
29
|
+
|
|
30
|
+
export default function AuthScreen() {
|
|
31
|
+
const [email, setEmail] = useState('');
|
|
32
|
+
const [password, setPassword] = useState('');
|
|
33
|
+
const navigation = useNavigation()
|
|
34
|
+
const { login } = useContext(AuthContext);
|
|
35
|
+
|
|
36
|
+
const handleLogin = async () => {
|
|
37
|
+
// your login API logic here
|
|
38
|
+
const token = "abc123"; // from backend
|
|
39
|
+
await saveToken(token);
|
|
40
|
+
|
|
41
|
+
login(); // 🔥 triggers navigation switch
|
|
42
|
+
};
|
|
43
|
+
return (
|
|
44
|
+
<View style={styles.container}>
|
|
45
|
+
<Text style={styles.title}>Login</Text>
|
|
46
|
+
|
|
47
|
+
<TextInput
|
|
48
|
+
style={styles.input}
|
|
49
|
+
placeholder="Email"
|
|
50
|
+
value={email}
|
|
51
|
+
onChangeText={setEmail}
|
|
52
|
+
/>
|
|
53
|
+
|
|
54
|
+
<TextInput
|
|
55
|
+
style={styles.input}
|
|
56
|
+
placeholder="Password"
|
|
57
|
+
secureTextEntry
|
|
58
|
+
value={password}
|
|
59
|
+
onChangeText={setPassword}
|
|
60
|
+
/>
|
|
61
|
+
|
|
62
|
+
<TouchableOpacity style={styles.button} onPress={handleLogin}>
|
|
63
|
+
<Text style={styles.buttonText}>Login</Text>
|
|
64
|
+
</TouchableOpacity>
|
|
65
|
+
</View>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const styles = StyleSheet.create({
|
|
70
|
+
container: {
|
|
71
|
+
flex: 1,
|
|
72
|
+
justifyContent: 'center',
|
|
73
|
+
paddingHorizontal: 20,
|
|
74
|
+
backgroundColor: '#f5f5f5',
|
|
75
|
+
},
|
|
76
|
+
title: {
|
|
77
|
+
fontSize: 28,
|
|
78
|
+
fontWeight: 'bold',
|
|
79
|
+
textAlign: 'center',
|
|
80
|
+
marginBottom: 30,
|
|
81
|
+
},
|
|
82
|
+
input: {
|
|
83
|
+
height: 50,
|
|
84
|
+
borderWidth: 1,
|
|
85
|
+
borderColor: '#ccc',
|
|
86
|
+
borderRadius: 8,
|
|
87
|
+
paddingHorizontal: 15,
|
|
88
|
+
marginBottom: 15,
|
|
89
|
+
backgroundColor: '#fff',
|
|
90
|
+
},
|
|
91
|
+
button: {
|
|
92
|
+
backgroundColor: '#007bff',
|
|
93
|
+
paddingVertical: 15,
|
|
94
|
+
borderRadius: 8,
|
|
95
|
+
alignItems: 'center',
|
|
96
|
+
},
|
|
97
|
+
buttonText: {
|
|
98
|
+
color: '#fff',
|
|
99
|
+
fontSize: 16,
|
|
100
|
+
fontWeight: '600',
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
`,
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
write(
|
|
107
|
+
projectRoot,
|
|
108
|
+
`src/features/${feature}/store/index.ts`,
|
|
109
|
+
`export default {};`,
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
write(
|
|
113
|
+
projectRoot,
|
|
114
|
+
`src/features/${feature}/api/index.ts`,
|
|
115
|
+
`// API calls for ${feature}`,
|
|
116
|
+
);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// --- Default feature generation ---
|
|
121
|
+
|
|
122
|
+
|
|
17
123
|
write(
|
|
18
124
|
projectRoot,
|
|
19
125
|
`src/features/${feature}/screens/${capitalize(feature)}Screen.tsx`,
|
|
@@ -22,7 +128,7 @@ import { View, Text } from "react-native";
|
|
|
22
128
|
|
|
23
129
|
export default function ${capitalize(feature)}Screen() {
|
|
24
130
|
return (
|
|
25
|
-
<View>
|
|
131
|
+
<View style={{flex:1, alignItems:'center', justifyContent:'center'}}>
|
|
26
132
|
<Text>${capitalize(feature)} Screen</Text>
|
|
27
133
|
</View>
|
|
28
134
|
);
|
package/generators/navigation.js
CHANGED
|
@@ -19,12 +19,14 @@ module.exports = function generateNavigation(projectRoot) {
|
|
|
19
19
|
projectRoot,
|
|
20
20
|
`${navBase}/RootNavigator.tsx`,
|
|
21
21
|
`
|
|
22
|
-
import React, { useEffect, useState } from "react";
|
|
22
|
+
import React, { useEffect, useState, createContext } from "react";
|
|
23
23
|
import { NavigationContainer } from "@react-navigation/native";
|
|
24
24
|
import AuthStack from "./stacks/AuthStack";
|
|
25
25
|
import AppStack from "./stacks/AppStack";
|
|
26
26
|
import { getToken } from "../../services/storage/token";
|
|
27
27
|
|
|
28
|
+
export const AuthContext = createContext();
|
|
29
|
+
|
|
28
30
|
export default function RootNavigator() {
|
|
29
31
|
const [loading, setLoading] = useState(true);
|
|
30
32
|
const [isLoggedIn, setLoggedIn] = useState(false);
|
|
@@ -38,12 +40,22 @@ export default function RootNavigator() {
|
|
|
38
40
|
init();
|
|
39
41
|
}, []);
|
|
40
42
|
|
|
43
|
+
const login = () => {
|
|
44
|
+
setLoggedIn(true);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const logout = () => {
|
|
48
|
+
setLoggedIn(false);
|
|
49
|
+
};
|
|
50
|
+
|
|
41
51
|
if (loading) return null;
|
|
42
52
|
|
|
43
53
|
return (
|
|
44
|
-
<
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
<AuthContext.Provider value={{ login, logout }}>
|
|
55
|
+
<NavigationContainer>
|
|
56
|
+
{isLoggedIn ? <AppStack /> : <AuthStack />}
|
|
57
|
+
</NavigationContainer>
|
|
58
|
+
</AuthContext.Provider>
|
|
47
59
|
);
|
|
48
60
|
}
|
|
49
61
|
`
|
|
@@ -58,19 +70,14 @@ export default function RootNavigator() {
|
|
|
58
70
|
`
|
|
59
71
|
import React from "react";
|
|
60
72
|
import { createNativeStackNavigator } from "@react-navigation/native-stack";
|
|
61
|
-
|
|
62
|
-
import LoginScreen from "../../features/auth/screens/LoginScreen";
|
|
63
|
-
import RegisterScreen from "../../features/auth/screens/RegisterScreen";
|
|
64
|
-
import ForgotPasswordScreen from "../../features/auth/screens/ForgotPasswordScreen";
|
|
73
|
+
import AuthScreen from "../../../features/auth/screens/AuthScreen";
|
|
65
74
|
|
|
66
75
|
const Stack = createNativeStackNavigator();
|
|
67
76
|
|
|
68
77
|
export default function AuthStack() {
|
|
69
78
|
return (
|
|
70
79
|
<Stack.Navigator screenOptions={{ headerShown: false }}>
|
|
71
|
-
<Stack.Screen name="Login" component={
|
|
72
|
-
<Stack.Screen name="Register" component={RegisterScreen} />
|
|
73
|
-
<Stack.Screen name="ForgotPassword" component={ForgotPasswordScreen} />
|
|
80
|
+
<Stack.Screen name="Login" component={AuthScreen} />
|
|
74
81
|
</Stack.Navigator>
|
|
75
82
|
);
|
|
76
83
|
}
|
|
@@ -88,10 +95,8 @@ import React from "react";
|
|
|
88
95
|
import { createNativeStackNavigator } from "@react-navigation/native-stack";
|
|
89
96
|
|
|
90
97
|
import DashboardScreen from "../../features/dashboard/screens/DashboardScreen";
|
|
91
|
-
import HomeScreen from "../../features/home/screens/HomeScreen";
|
|
92
98
|
import ProfileScreen from "../../features/profile/screens/ProfileScreen";
|
|
93
99
|
import SettingsScreen from "../../features/settings/screens/SettingsScreen";
|
|
94
|
-
import NotificationsScreen from "../../features/notifications/screens/NotificationsScreen";
|
|
95
100
|
|
|
96
101
|
const Stack = createNativeStackNavigator();
|
|
97
102
|
|
|
@@ -99,10 +104,8 @@ export default function AppStack() {
|
|
|
99
104
|
return (
|
|
100
105
|
<Stack.Navigator screenOptions={{ headerShown: false }}>
|
|
101
106
|
<Stack.Screen name="Dashboard" component={DashboardScreen} />
|
|
102
|
-
<Stack.Screen name="Home" component={HomeScreen} />
|
|
103
107
|
<Stack.Screen name="Profile" component={ProfileScreen} />
|
|
104
108
|
<Stack.Screen name="Settings" component={SettingsScreen} />
|
|
105
|
-
<Stack.Screen name="Notifications" component={NotificationsScreen} />
|
|
106
109
|
</Stack.Navigator>
|
|
107
110
|
);
|
|
108
111
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-rn-folder-structure",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "CLI tool to generate React Native folder structure with predefined templates",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"axios": "^1.13.4",
|
|
45
45
|
"create-rn-folder-structure": "^1.0.2",
|
|
46
46
|
"react-native-safe-area-context": "^5.6.2",
|
|
47
|
-
"react-native-screens": "^4.
|
|
47
|
+
"react-native-screens": "^4.23.0",
|
|
48
48
|
"react-redux": "^9.2.0"
|
|
49
49
|
}
|
|
50
50
|
}
|