-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mobile): setup nativewind and nativecn
- Loading branch information
Quốc Khánh
authored and
Quốc Khánh
committed
Jun 8, 2024
1 parent
0506cfd
commit 9fe8538
Showing
38 changed files
with
1,819 additions
and
359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [], | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
Oops, something went wrong.