Skip to content

Commit

Permalink
feat(client): add nativewind to the project
Browse files Browse the repository at this point in the history
  • Loading branch information
brunocroh committed Feb 2, 2025
1 parent 9b87baa commit fcea864
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 54 deletions.
71 changes: 45 additions & 26 deletions apps/client/app/(tabs)/explore.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
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 { IconSymbol } from '@/components/ui/IconSymbol';
import { Image, Platform, StyleSheet, Text } 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 { IconSymbol } from '@/components/ui/IconSymbol'

export default function TabTwoScreen() {
return (
Expand All @@ -18,19 +17,24 @@ export default function TabTwoScreen() {
name="chevron.left.forwardslash.chevron.right"
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>
<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)/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>{' '}
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">
Expand All @@ -39,24 +43,30 @@ export default function TabTwoScreen() {
</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.
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
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' }} />
<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{' '}
Open <ThemedText type="defaultSemiBold">app/_layout.tsx</ThemedText>{' '}
to see how to load{' '}
<ThemedText style={{ fontFamily: 'SpaceMono' }}>
custom fonts such as this one.
</ThemedText>
Expand All @@ -68,8 +78,9 @@ export default function TabTwoScreen() {
<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 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>
Expand All @@ -78,21 +89,29 @@ export default function TabTwoScreen() {
<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>{' '}
<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>{' '}
The{' '}
<ThemedText type="defaultSemiBold">
components/ParallaxScrollView.tsx
</ThemedText>{' '}
component provides a parallax effect for the header image.
</ThemedText>
),
})}
</Collapsible>
</ParallaxScrollView>
);
)
}

const styles = StyleSheet.create({
Expand All @@ -106,4 +125,4 @@ const styles = StyleSheet.create({
flexDirection: 'row',
gap: 8,
},
});
})
36 changes: 20 additions & 16 deletions apps/client/app/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native';
import { useFonts } from 'expo-font';
import { Stack } from 'expo-router';
import * as SplashScreen from 'expo-splash-screen';
import { StatusBar } from 'expo-status-bar';
import { useEffect } from 'react';
import 'react-native-reanimated';

import { useColorScheme } from '@/hooks/useColorScheme';
import { useEffect } from 'react'
import 'react-native-reanimated'
import { useFonts } from 'expo-font'
import { Stack } from 'expo-router'
import * as SplashScreen from 'expo-splash-screen'
import { StatusBar } from 'expo-status-bar'
import { useColorScheme } from '@/hooks/useColorScheme'
import {
DarkTheme,
DefaultTheme,
ThemeProvider,
} from '@react-navigation/native'
import '../global.css'

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

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

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

if (!loaded) {
return null;
return null
}

return (
Expand All @@ -35,5 +39,5 @@ export default function RootLayout() {
</Stack>
<StatusBar style="auto" />
</ThemeProvider>
);
)
}
9 changes: 9 additions & 0 deletions apps/client/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = function (api) {
api.cache(true)
return {
presets: [
['babel-preset-expo', { jsxImportSource: 'nativewind' }],
'nativewind/babel',
],
}
}
3 changes: 3 additions & 0 deletions apps/client/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
4 changes: 3 additions & 1 deletion apps/client/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Learn more https://docs.expo.dev/guides/monorepos
const { getDefaultConfig } = require('expo/metro-config')
const { FileStore } = require('metro-cache')
const { withNativeWind } = require('nativewind/metro')

const path = require('path')

// Create the default Expo config for Metro
Expand All @@ -26,4 +28,4 @@ config.cacheStores = [
}),
]

module.exports = config
module.exports = withNativeWind(config, { input: './global.css' })
3 changes: 3 additions & 0 deletions apps/client/nativewind-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// <reference types="nativewind/types" />

// NOTE: This file should not be edited and should be committed with your source code. It is generated by NativeWind.
6 changes: 4 additions & 2 deletions apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@
"expo-symbols": "~0.2.1",
"expo-system-ui": "~4.0.7",
"expo-web-browser": "~14.0.2",
"nativewind": "^4.1.23",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-native": "0.76.6",
"react-native-gesture-handler": "~2.20.2",
"react-native-reanimated": "~3.16.1",
"react-native-reanimated": "~3.16.7",
"react-native-safe-area-context": "4.12.0",
"react-native-screens": "~4.4.0",
"react-native-web": "~0.19.13",
"react-native-webview": "13.12.5"
"react-native-webview": "13.12.5",
"tailwindcss": "^3.4.3"
},
"devDependencies": {
"@babel/core": "^7.25.2",
Expand Down
10 changes: 10 additions & 0 deletions apps/client/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
// NOTE: Update this to include the paths to all of your component files.
content: ["./app/**/*.{js,jsx,ts,tsx}"],
presets: [require("nativewind/preset")],
theme: {
extend: {},
},
plugins: [],
}
5 changes: 3 additions & 2 deletions apps/client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"**/*.ts",
"**/*.tsx",
".expo/types/**/*.ts",
"expo-env.d.ts"
"expo-env.d.ts",
"nativewind-env.d.ts"
]
}
}
Loading

0 comments on commit fcea864

Please sign in to comment.