Skip to content

Commit

Permalink
chore: upgrade example app to add more screens
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkpatchaa committed Aug 16, 2024
1 parent 6ae9fb5 commit f1ab54c
Show file tree
Hide file tree
Showing 26 changed files with 1,144 additions and 50 deletions.
6 changes: 6 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ yarn-error.*

# typescript
*.tsbuildinfo

# @generated expo-cli sync-2b81b286409207a5da26e14c78851eb30d8ccbdb
# The following patterns were generated by expo-cli

expo-env.d.ts
# @end expo-cli
20 changes: 13 additions & 7 deletions example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,33 @@
"slug": "phosphor-react-native-example",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"icon": "./assets/images/icon.png",
"scheme": "phosphor-react-native-example",
"userInterfaceStyle": "light",
"splash": {
"image": "./assets/splash.png",
"image": "./assets/images/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"foregroundImage": "./assets/images/adaptive-icon.png",
"backgroundColor": "#ffffff"
}
},
"web": {
"favicon": "./assets/favicon.png"
"bundler": "metro",
"output": "static",
"favicon": "./assets/images/favicon.png"
},
"plugins": [
"expo-router"
],
"experiments": {
"typedRoutes": true
}
}
}
42 changes: 42 additions & 0 deletions example/app/(tabs)/_layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Tabs } from 'expo-router';
import React from 'react';

import { TabBarIcon } from '@/components/navigation/TabBarIcon';
import List from 'phosphor-react-native/src/icons/List';
import { Colors } from '@/constants/Colors';
import { useColorScheme } from '@/hooks/useColorScheme';

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

return (
<Tabs
screenOptions={{
tabBarActiveTintColor: Colors[colorScheme ?? 'light'].tint,
headerShown: false,
}}
>
<Tabs.Screen
name="index"
options={{
title: 'All icons',
tabBarIcon: ({ color, focused }) => (
<List weight={focused ? 'fill' : 'light'} color={color} />
),
}}
/>
<Tabs.Screen
name="duotone"
options={{
title: 'Duotone',
tabBarIcon: ({ color, focused }) => (
<TabBarIcon
name={focused ? 'code-slash' : 'code-slash-outline'}
color={color}
/>
),
}}
/>
</Tabs>
);
}
10 changes: 10 additions & 0 deletions example/app/(tabs)/duotone.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable react-native/no-inline-styles */
import { Text, View } from 'react-native';

export default function DuotoneScreen() {
return (
<View>
<Text>Explore</Text>
</View>
);
}
165 changes: 165 additions & 0 deletions example/app/(tabs)/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/* eslint-disable react-native/no-inline-styles */
/* eslint-disable @typescript-eslint/no-explicit-any */

import * as React from 'react';

import {
StyleSheet,
View,
Text,
SafeAreaView,
FlatList,
StatusBar,
Image,
TouchableOpacity,
} from 'react-native';
import * as IconPack from 'phosphor-react-native';
import PhosphorLogo from '@/assets/images/phosphor-mark-tight-yellow.png';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { IconContext, ...Icons } = IconPack;

const weights = ['thin', 'light', 'regular', 'bold', 'fill', 'duotone'];

export default function App() {
const [weightIdx, setWeightIdx] = React.useState(2);
const [iconColor, setIconColor] = React.useState(undefined);
const [mirrorActive, setMirrorActive] = React.useState(false);

const weight: IconPack.IconWeight = React.useMemo(
() => weights[weightIdx] as any,
[weightIdx]
);

const handleChangeWeight = React.useCallback(() => {
setWeightIdx((weightIdx + 1) % weights.length);
}, [weightIdx]);

const handleChangeIconColor = React.useCallback(() => {
setIconColor(`#${Math.floor(Math.random() * 16777215).toString(16)}`);
}, []);

const handleToggleMirror = React.useCallback(() => {
setMirrorActive(!mirrorActive);
}, [mirrorActive]);

return (
<View style={styles.rootView}>
<StatusBar barStyle="light-content" />

<SafeAreaView style={styles.headerContainer}>
<View style={styles.header}>
<Image source={PhosphorLogo} style={styles.logoImage} />
<View
style={{
flex: 1,
alignItems: 'flex-start',
justifyContent: 'center',
paddingStart: 10,
}}
>
<Text style={styles.headerText}>Phosphor React Native</Text>
<Text
style={{
color: '#fff',
opacity: 0.8,
textTransform: 'capitalize',
}}
>
{weight}
</Text>
</View>
<TouchableOpacity
style={styles.weightSelect}
onPress={handleChangeIconColor}
>
<IconPack.Palette color="#FFF" weight={weight} />
</TouchableOpacity>
<TouchableOpacity
style={styles.weightSelect}
onPress={handleChangeWeight}
>
<IconPack.PencilLine color="#FFF" weight={weight} />
</TouchableOpacity>
<TouchableOpacity
style={styles.weightSelect}
onPress={handleToggleMirror}
>
<IconPack.Swap color="#FFF" weight={weight} />
</TouchableOpacity>
</View>
</SafeAreaView>
<FlatList
style={styles.scrollView}
contentContainerStyle={styles.main}
data={Object.entries(Icons).filter(([, Icon]) => !!Icon) as any[]}
keyExtractor={(item) => item[0]}
numColumns={3}
renderItem={({ item: [name, Icon] }) => (
<View style={styles.iconItem}>
<Icon
size={48}
weight={weight}
mirrored={mirrorActive}
color={iconColor}
/>
<Text style={styles.iconName}>{name}</Text>
</View>
)}
/>
</View>
);
}

const styles = StyleSheet.create({
rootView: {
flex: 1,
backgroundColor: '#FFF',
},
headerContainer: {
backgroundColor: '#e76f51',
},
header: {
backgroundColor: '#e76f51',
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'row',
paddingBottom: 16,
paddingHorizontal: 16,
},
logoImage: {
width: 40,
height: 40,
borderRadius: 20,
},
headerText: {
color: '#FFF',
fontSize: 18,
fontWeight: 'bold',
flex: 1,
textAlign: 'center',
},
weightSelect: {
width: 35,
},
scrollView: {
flex: 1,
},
main: {
backgroundColor: 'white',
paddingHorizontal: 8,
paddingBottom: 16,
},
iconItem: {
width: '33%',
height: 100,
alignItems: 'center',
justifyContent: 'center',
padding: 8,
},
iconName: {
textAlign: 'center',
opacity: 0.8,
marginTop: 4,
},
});
42 changes: 42 additions & 0 deletions example/app/+html.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { ScrollViewStyleReset } from 'expo-router/html';
import { type 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;
}
}`;
32 changes: 32 additions & 0 deletions example/app/+not-found.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Link, Stack } from 'expo-router';
import { StyleSheet } from 'react-native';

import { ThemedText } from '@/components/ThemedText';
import { ThemedView } from '@/components/ThemedView';

export default function NotFoundScreen() {
return (
<>
<Stack.Screen options={{ title: 'Oops!' }} />
<ThemedView style={styles.container}>
<ThemedText type="title">This screen doesn't exist.</ThemedText>
<Link href="/" style={styles.link}>
<ThemedText type="link">Go to home screen!</ThemedText>
</Link>
</ThemedView>
</>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
padding: 20,
},
link: {
marginTop: 15,
paddingVertical: 15,
},
});
31 changes: 31 additions & 0 deletions example/app/_layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
DarkTheme,
DefaultTheme,
ThemeProvider,
} from '@react-navigation/native';
import { Stack } from 'expo-router';
import * as SplashScreen from 'expo-splash-screen';
import { useEffect } from 'react';
import 'react-native-reanimated';

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

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

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

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

return (
<ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
<Stack>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen name="+not-found" />
</Stack>
</ThemeProvider>
);
}
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Loading

0 comments on commit f1ab54c

Please sign in to comment.