Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RN Expo boilerplate - Sign in & Sign up #19

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
11 changes: 11 additions & 0 deletions examples/common_expo/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// https://docs.expo.dev/guides/using-eslint/
module.exports = {
extends: ['expo', 'prettier'],
plugins: ['prettier', 'jest'],
rules: {
'prettier/prettier': 'error',
},
env: {
'jest/globals': true,
},
};
38 changes: 38 additions & 0 deletions examples/common_expo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files

# dependencies
node_modules/

# Expo
.expo/
dist/
web-build/

# Native
*.orig.*
*.jks
*.p8
*.p12
*.key
*.mobileprovision

# Metro
.metro-health-check*

# debug
npm-debug.*
yarn-debug.*
yarn-error.*

# macOS
.DS_Store
*.pem

# local env files
.env*.local

# typescript
*.tsbuildinfo

# expo-cli
expo-env.d.ts
1 change: 1 addition & 0 deletions examples/common_expo/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node-linker=hoisted
4 changes: 4 additions & 0 deletions examples/common_expo/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
15 changes: 15 additions & 0 deletions examples/common_expo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Common Expo

## Setup Mobile App

1. **Install the project dependencies:**

To install the necessary dependencies for your project, run the following command:

`pnpm install`

2. **Start the development server:**

Once the dependencies are installed, you can start project using the command:

`pnpm start`
40 changes: 40 additions & 0 deletions examples/common_expo/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"expo": {
"name": "common_expo",
"slug": "common_expo",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/images/icon.png",
"scheme": "myapp",
"userInterfaceStyle": "automatic",
"splash": {
"image": "./assets/images/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"ios": {
"supportsTablet": true,
"config": {
"usesNonExemptEncryption": false
}
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/images/adaptive-icon.png",
"backgroundColor": "#ffffff"
}
},
"web": {
"bundler": "metro",
"output": "static",
"favicon": "./assets/images/favicon.png"
},
"plugins": [
"expo-router",
"expo-secure-store"
],
"experiments": {
"typedRoutes": true
}
}
}
46 changes: 46 additions & 0 deletions examples/common_expo/app/(app)/(tabs)/_layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { ComponentProps } from 'react';
import FontAwesome from '@expo/vector-icons/FontAwesome';
import { Tabs } from 'expo-router';

import Colors from '@/constants/theme/Colors';
import { useColorScheme } from '@/hooks/useColorScheme';

type TabLayoutProps = {
name: ComponentProps<typeof FontAwesome>['name'];
color: string;
};

// You can explore the built-in icon families and icons on the web at https://icons.expo.fyi/
function TabBarIcon(props: TabLayoutProps) {
return <FontAwesome size={28} style={{ marginBottom: -3 }} {...props} />;
}

export default function TabLayout() {
const colorScheme = useColorScheme();

return (
<Tabs
screenOptions={{
tabBarActiveTintColor: Colors[colorScheme ?? 'light'].tint,
// Disable the static render of the header on web
// to prevent a hydration error in React Navigation v6.
headerShown: false,
}}
>
<Tabs.Screen
name="index"
options={{
title: 'Home',
tabBarIcon: ({ color }) => <TabBarIcon name="home" color={color} />,
}}
/>
<Tabs.Screen
name="profile"
options={{
title: 'Profile',
tabBarIcon: ({ color }) => <TabBarIcon name="user" color={color} />,
}}
/>
</Tabs>
);
}
10 changes: 10 additions & 0 deletions examples/common_expo/app/(app)/(tabs)/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { CenterView } from '@/components/CenterView';
import { Typography } from '@/components/Typography';

export default function HomeScreen() {
return (
<CenterView>
<Typography.Header>Home screen</Typography.Header>
</CenterView>
);
}
10 changes: 10 additions & 0 deletions examples/common_expo/app/(app)/(tabs)/profile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { CenterView } from '@/components/CenterView';
import { Typography } from '@/components/Typography';

export default function Profile() {
return (
<CenterView>
<Typography.Header>Profile screen</Typography.Header>
</CenterView>
);
}
33 changes: 33 additions & 0 deletions examples/common_expo/app/(app)/_layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ActivityIndicator, TouchableOpacity } from 'react-native';
import { Redirect, Stack } from 'expo-router';
import { useAuth } from '@/providers/AuthProvider';
import { Typography } from '@/components/Typography';
import { CenterView } from '@/components/CenterView';

export default function AppLayout() {
const { session, isLoading, signOut } = useAuth();

if (isLoading) {
return (
<CenterView>
<ActivityIndicator size="large" />
</CenterView>
);
}

if (!session) {
return <Redirect href="/sign-in" />;
}

return (
<Stack
screenOptions={{
headerRight: () => (
<TouchableOpacity onPress={signOut}>
<Typography.Text>Logout</Typography.Text>
</TouchableOpacity>
),
}}
/>
);
}
42 changes: 42 additions & 0 deletions examples/common_expo/app/+html.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { ScrollViewStyleReset } from 'expo-router/html';
import { PropsWithChildren } from 'react';

// This file is web-only and used to configure the root HTML for every
// web page during static rendering.
// The contents of this function only run in Node.js environments and
// do not have access to the DOM or browser APIs.
export default function Root({ children }: PropsWithChildren) {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>

{/*
Disable body scrolling on web. This makes ScrollView components work closer to how they do on native.
However, body scrolling is often nice to have for mobile web. If you want to enable it, remove this line.
*/}
<ScrollViewStyleReset />

{/* Using raw CSS styles as an escape-hatch to ensure the background color never flickers in dark-mode. */}
<style dangerouslySetInnerHTML={{ __html: responsiveBackground }} />
{/* Add any additional <head> elements that you want globally available on web... */}
</head>
<body>{children}</body>
</html>
);
}

const responsiveBackground = `
body {
background-color: #fff;
}
@media (prefers-color-scheme: dark) {
body {
background-color: #000;
}
}`;
40 changes: 40 additions & 0 deletions examples/common_expo/app/+not-found.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Link, Stack } from 'expo-router';
import { StyleSheet } from 'react-native';

import { Text, View } from '@/components/Themed';

export default function NotFoundScreen() {
return (
<>
<Stack.Screen options={{ title: 'Oops!' }} />
<View style={styles.container}>
<Text style={styles.title}>This screen doesn't exist.</Text>

<Link href="/" style={styles.link}>
<Text style={styles.linkText}>Go to home screen!</Text>
</Link>
</View>
</>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
padding: 20,
},
title: {
fontSize: 20,
fontWeight: 'bold',
},
link: {
marginTop: 15,
paddingVertical: 15,
},
linkText: {
fontSize: 14,
color: '#2e78b7',
},
});
63 changes: 63 additions & 0 deletions examples/common_expo/app/_layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import FontAwesome from '@expo/vector-icons/FontAwesome';
import {
DarkTheme,
DefaultTheme,
ThemeProvider,
} from '@react-navigation/native';
import { useFonts } from 'expo-font';
import { Slot } from 'expo-router';
import * as SplashScreen from 'expo-splash-screen';
import { useEffect } from 'react';
import 'react-native-reanimated';

import { useColorScheme } from '@/hooks/useColorScheme';
import { AuthProvider } from '@/providers/AuthProvider';

export {
// Catch any errors thrown by the Layout component.
ErrorBoundary,
} from 'expo-router';

export const unstable_settings = {
// Ensure that reloading on `/modal` keeps a back button present.
initialRouteName: '(tabs)',
};

// Prevent the splash screen from auto-hiding before asset loading is complete.
SplashScreen.preventAutoHideAsync();

export default function RootLayout() {
const [loaded, error] = useFonts({
SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),
...FontAwesome.font,
});

// Expo Router uses Error Boundaries to catch errors in the navigation tree.
useEffect(() => {
if (error) throw error;
}, [error]);

useEffect(() => {
if (loaded) {
SplashScreen.hideAsync();
}
}, [loaded]);

if (!loaded) {
return null;
}

return <RootLayoutNav />;
}

function RootLayoutNav() {
const colorScheme = useColorScheme();

return (
<ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
<AuthProvider>
<Slot />
</AuthProvider>
</ThemeProvider>
);
}
Loading