This is an Expo project created with create-expo-app
, showing how TailwindCSS styles can be used in React Native apps.
This app can be built for web, mobile devices (iOS, iPadOS, and Android), and TV devices (Apple TV, Android TV).
You can see the web version at
https://nativewindmultiplatform.expo.app/
Some of the packages used:
- The React Native TV fork, which supports both phone (Android and iOS) and TV (Android TV and Apple TV) targets
- The React Native TV config plugin, to allow Expo prebuild to modify the project's native files for TV builds
- The NativeWind package which lets you use Tailwind CSS in react-native.
- The react-native-bottom-tabs package that provides a fully native tab bar (top bar for Apple TV, bottom bar for Android TV).
-
cd
into the project -
Build for mobile devices (including iPad tablet support)
yarn
yarn prebuild # Executes a clean Expo prebuild to generate iOS and Android native files
yarn ios # Build and run for iOS
yarn android # Build and run for Android
- Build for TV devices
yarn
yarn prebuild:tv # Executes a clean Expo prebuild to generate tvOS and Android TV native files
yarn ios # Build and run for Apple TV
yarn android # Build and run for Android TV
- Web (local development)
yarn
yarn web # Runs the web app as a local development server on port 8081
- Web (deploy to EAS hosting)
yarn
eas init
yarn build:web # Build the web deployment bundle
yarn deploy:web # Deploy to the EAS hosting dev environment
NOTE: Setting the environment variable
EXPO_TV=1
enables the@react-native-tvos/config-tv
plugin to modify the project for TV. This can also be done by setting the parameterisTV
to true in theapp.json
.
The UI is derived from the NativeWind example app plus this Tailwind CSS example. It includes custom CSS transforms.
Theme.ts
contains dark and light versions of the custom colors used in the app, as well as custom scale factors for scaling buttons when they are focused, hovered, or active. The colors are the same as those used in the default template used when creating new Expo Router apps. useTheme.ts
exports a hook that returns the current theme.
The root layout sets the theme as the style in the root view.
The themed components demonstrate how to use NativeWind class names and the custom colors to provide consistent text, button, and link appearance. These are used both in the home screen and the tab layout for web.
The app provides a native tab layout using react-native-bottom-tabs
.
For web and Android TV, the web tab layout uses the custom tab layout feature of Expo Router.
These are shown in the focus/hover/active demo screen.
- The buttons are styled with
focus:bg-blue-300
andactive:bg-green-600
. On TV, thefocus
prefix causes the style to be applied to controls whenonFocus()
is invoked, and the style is removed whenonBlur()
is invoked. On both TV and mobile, theactive
prefix applies the style whenonPressIn()
is invoked, and removes it whenonPressOut()
is invoked. - The buttons are also styled with
hover:bg-blue-300
, to apply that style when the mouse hovers over the button in the web version of the app. - Finally,
transition duration-500
is applied so that the focus, blur, and hover transitions happen smoothly with an animation.
The home screen shows how to wrap the <Image />
component provided by expo-image
for use with NativeWind, using the cssInterop()
API.
The video demo shows the same technique applied to the <VideoView />
component from expo-video
.
To learn more about developing your project with Expo, look at the following resources:
- Expo documentation: Learn fundamentals, or go into advanced topics with our guides.
- Learn Expo tutorial: Follow a step-by-step tutorial where you'll create a project that runs on Android, iOS, and the web.
- Building Expo apps for TV
Join our community of developers creating universal apps.
- Expo on GitHub: View our open source platform and contribute.
- Discord community: Chat with Expo users and ask questions.