Skip to content

Commit

Permalink
feat(mobile): setup nativewind and nativecn (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkdev98 authored Jun 9, 2024
1 parent 7b2033d commit 63560e8
Show file tree
Hide file tree
Showing 38 changed files with 1,831 additions and 358 deletions.
2 changes: 1 addition & 1 deletion apps/mobile/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Welcome to your Expo app 👋
# @6pm/mobile

This is an [Expo](https://expo.dev) project created with [`create-expo-app`](https://www.npmjs.com/package/create-expo-app).

Expand Down
117 changes: 20 additions & 97 deletions apps/mobile/app/(tabs)/explore.tsx
Original file line number Diff line number Diff line change
@@ -1,102 +1,25 @@
import Ionicons from '@expo/vector-icons/Ionicons';
import { StyleSheet, Image, Platform } from 'react-native';

import { Collapsible } from '@/components/Collapsible';
import { ExternalLink } from '@/components/ExternalLink';
import ParallaxScrollView from '@/components/ParallaxScrollView';
import { ThemedText } from '@/components/ThemedText';
import { ThemedView } from '@/components/ThemedView';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/Avatar';
import { View } from 'react-native';

export default function TabTwoScreen() {
return (
<ParallaxScrollView
headerBackgroundColor={{ light: '#D0D0D0', dark: '#353636' }}
headerImage={<Ionicons size={310} name="code-slash" style={styles.headerImage} />}>
<ThemedView style={styles.titleContainer}>
<ThemedText type="title">Explore</ThemedText>
</ThemedView>
<ThemedText>This app includes example code to help you get started.</ThemedText>
<Collapsible title="File-based routing">
<ThemedText>
This app has two screens:{' '}
<ThemedText type="defaultSemiBold">app/(tabs)/index.tsx</ThemedText> and{' '}
<ThemedText type="defaultSemiBold">app/(tabs)/explore.tsx</ThemedText>
</ThemedText>
<ThemedText>
The layout file in <ThemedText type="defaultSemiBold">app/(tabs)/_layout.tsx</ThemedText>{' '}
sets up the tab navigator.
</ThemedText>
<ExternalLink href="https://docs.expo.dev/router/introduction">
<ThemedText type="link">Learn more</ThemedText>
</ExternalLink>
</Collapsible>
<Collapsible title="Android, iOS, and web support">
<ThemedText>
You can open this project on Android, iOS, and the web. To open the web version, press{' '}
<ThemedText type="defaultSemiBold">w</ThemedText> in the terminal running this project.
</ThemedText>
</Collapsible>
<Collapsible title="Images">
<ThemedText>
For static images, you can use the <ThemedText type="defaultSemiBold">@2x</ThemedText> and{' '}
<ThemedText type="defaultSemiBold">@3x</ThemedText> suffixes to provide files for
different screen densities
</ThemedText>
<Image source={require('@/assets/images/react-logo.png')} style={{ alignSelf: 'center' }} />
<ExternalLink href="https://reactnative.dev/docs/images">
<ThemedText type="link">Learn more</ThemedText>
</ExternalLink>
</Collapsible>
<Collapsible title="Custom fonts">
<ThemedText>
Open <ThemedText type="defaultSemiBold">app/_layout.tsx</ThemedText> to see how to load{' '}
<ThemedText style={{ fontFamily: 'SpaceMono' }}>
custom fonts such as this one.
</ThemedText>
</ThemedText>
<ExternalLink href="https://docs.expo.dev/versions/latest/sdk/font">
<ThemedText type="link">Learn more</ThemedText>
</ExternalLink>
</Collapsible>
<Collapsible title="Light and dark mode components">
<ThemedText>
This template has light and dark mode support. The{' '}
<ThemedText type="defaultSemiBold">useColorScheme()</ThemedText> hook lets you inspect
what the user's current color scheme is, and so you can adjust UI colors accordingly.
</ThemedText>
<ExternalLink href="https://docs.expo.dev/develop/user-interface/color-themes/">
<ThemedText type="link">Learn more</ThemedText>
</ExternalLink>
</Collapsible>
<Collapsible title="Animations">
<ThemedText>
This template includes an example of an animated component. The{' '}
<ThemedText type="defaultSemiBold">components/HelloWave.tsx</ThemedText> component uses
the powerful <ThemedText type="defaultSemiBold">react-native-reanimated</ThemedText> library
to create a waving hand animation.
</ThemedText>
{Platform.select({
ios: (
<ThemedText>
The <ThemedText type="defaultSemiBold">components/ParallaxScrollView.tsx</ThemedText>{' '}
component provides a parallax effect for the header image.
</ThemedText>
),
})}
</Collapsible>
</ParallaxScrollView>
<View className="flex justify-center flex-1 items-center flex-row gap-4">
<Avatar className="h-14 w-14">
<AvatarImage
source={{
uri: 'https://avatars.githubusercontent.com/u/16166195?s=96&v=4',
}}
/>
<AvatarFallback>CG</AvatarFallback>
</Avatar>
<Avatar className="h-14 w-14">
<AvatarImage
source={{
uri: 'https://avatars.githubusercontent.com/u/9253690?s=96&v=4',
}}
/>
<AvatarFallback>SS</AvatarFallback>
</Avatar>
</View>
);
}

const styles = StyleSheet.create({
headerImage: {
color: '#808080',
bottom: -90,
left: -35,
position: 'absolute',
},
titleContainer: {
flexDirection: 'row',
gap: 8,
},
});
67 changes: 2 additions & 65 deletions apps/mobile/app/(tabs)/index.tsx
Original file line number Diff line number Diff line change
@@ -1,70 +1,7 @@
import { Image, StyleSheet, Platform } from 'react-native';

import { HelloWave } from '@/components/HelloWave';
import ParallaxScrollView from '@/components/ParallaxScrollView';
import { ThemedText } from '@/components/ThemedText';
import { ThemedView } from '@/components/ThemedView';
import { Button } from '@/components/Button';

export default function HomeScreen() {
return (
<ParallaxScrollView
headerBackgroundColor={{ light: '#A1CEDC', dark: '#1D3D47' }}
headerImage={
<Image
source={require('@/assets/images/partial-react-logo.png')}
style={styles.reactLogo}
/>
}>
<ThemedView style={styles.titleContainer}>
<ThemedText type="title">Welcome!</ThemedText>
<HelloWave />
</ThemedView>
<ThemedView style={styles.stepContainer}>
<ThemedText type="subtitle">Step 1: Try it</ThemedText>
<ThemedText>
Edit <ThemedText type="defaultSemiBold">app/(tabs)/index.tsx</ThemedText> to see changes.
Press{' '}
<ThemedText type="defaultSemiBold">
{Platform.select({ ios: 'cmd + d', android: 'cmd + m' })}
</ThemedText>{' '}
to open developer tools.
</ThemedText>
</ThemedView>
<ThemedView style={styles.stepContainer}>
<ThemedText type="subtitle">Step 2: Explore</ThemedText>
<ThemedText>
Tap the Explore tab to learn more about what's included in this starter app.
</ThemedText>
</ThemedView>
<ThemedView style={styles.stepContainer}>
<ThemedText type="subtitle">Step 3: Get a fresh start</ThemedText>
<ThemedText>
When you're ready, run{' '}
<ThemedText type="defaultSemiBold">npm run reset-project</ThemedText> to get a fresh{' '}
<ThemedText type="defaultSemiBold">app</ThemedText> directory. This will move the current{' '}
<ThemedText type="defaultSemiBold">app</ThemedText> to{' '}
<ThemedText type="defaultSemiBold">app-example</ThemedText>.
</ThemedText>
</ThemedView>
</ParallaxScrollView>
<Button label="6pm" className='my-20 mx-4' />
);
}

const styles = StyleSheet.create({
titleContainer: {
flexDirection: 'row',
alignItems: 'center',
gap: 8,
},
stepContainer: {
gap: 8,
marginBottom: 8,
},
reactLogo: {
height: 178,
width: 290,
bottom: 0,
left: 0,
position: 'absolute',
},
});
15 changes: 7 additions & 8 deletions apps/mobile/app/+not-found.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { Link, Stack } from 'expo-router';
import { StyleSheet } from 'react-native';
import { StyleSheet, Text, View } from 'react-native';

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

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>
<View className="flex-1 items-center justify-center p-4">
<Text>This screen doesn't exist.</Text>
<Link href="/" style={styles.link} asChild>
<Button label="Go to home screen!" />
</Link>
</ThemedView>
</View>
</>
);
}
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'react-native-reanimated';

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

import "../global.css"

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

Expand Down
Binary file modified apps/mobile/assets/images/adaptive-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/mobile/assets/images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/mobile/assets/images/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions apps/mobile/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module.exports = function (api) {
module.exports = function(api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
presets: [
['babel-preset-expo', { jsxImportSource: 'nativewind' }],
'nativewind/babel'
],
plugins: [],
};
};
60 changes: 60 additions & 0 deletions apps/mobile/components/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { forwardRef, useState } from 'react';
import { Image, Text, View } from 'react-native';

import { cn } from '../lib/utils';

const Avatar = forwardRef<
React.ElementRef<typeof View>,
React.ComponentPropsWithoutRef<typeof View>
>(({ className, ...props }, ref) => (
<View
ref={ref}
className={cn(
'relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full',
className
)}
{...props}
/>
));
Avatar.displayName = 'Avatar';

const AvatarImage = forwardRef<
React.ElementRef<typeof Image>,
React.ComponentPropsWithoutRef<typeof Image>
>(({ className, ...props }, ref) => {
const [hasError, setHasError] = useState(false);

if (hasError) {
return null;
}
return (
<Image
ref={ref}
onError={() => setHasError(true)}
className={cn('aspect-square h-full w-full', className)}
{...props}
/>
);
});
AvatarImage.displayName = 'AvatarImage';

const AvatarFallback = forwardRef<
React.ElementRef<typeof View>,
React.ComponentPropsWithoutRef<typeof View> & { textClassname?: string }
>(({ children, className, textClassname, ...props }, ref) => (
<View
ref={ref}
className={cn(
'flex h-full w-full items-center justify-center rounded-full bg-muted',
className
)}
{...props}
>
<Text className={cn('text-lg text-primary', textClassname)}>
{children}
</Text>
</View>
));
AvatarFallback.displayName = 'AvatarFallback';

export { Avatar, AvatarImage, AvatarFallback };
59 changes: 59 additions & 0 deletions apps/mobile/components/Badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { type VariantProps, cva } from 'class-variance-authority';
import { Text, View } from 'react-native';

import { cn } from '../lib/utils';

const badgeVariants = cva(
'flex flex-row items-center rounded-full px-2 py-1 text-xs font-semibold',
{
variants: {
variant: {
default: 'bg-primary',
secondary: 'bg-secondary',
destructive: 'bg-destructive',
success: 'bg-green-500 dark:bg-green-700',
},
},
defaultVariants: {
variant: 'default',
},
}
);

const badgeTextVariants = cva('font-medium text-center text-xs', {
variants: {
variant: {
default: 'text-primary-foreground',
secondary: 'text-secondary-foreground',
destructive: 'text-destructive-foreground',
success: 'text-green-100',
},
},
defaultVariants: {
variant: 'default',
},
});

export interface BadgeProps
extends React.ComponentPropsWithoutRef<typeof View>,
VariantProps<typeof badgeVariants> {
label: string;
labelClasses?: string;
}
function Badge({
label,
labelClasses,
className,
variant,
...props
}: BadgeProps) {
return (
<View className={cn(badgeVariants({ variant }), className)} {...props}>
<Text className={cn(badgeTextVariants({ variant }), labelClasses)}>
{label}
</Text>
</View>
);
}

export { Badge, badgeVariants };
Loading

0 comments on commit 63560e8

Please sign in to comment.