Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions apps/templates/expo-router-with-nativewind/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
# Welcome to your Expo app 👋

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

## Get started

1. Install dependencies
1. Start the app

```bash
npm install
```

2. Start the app

```bash
npx expo start
npm run start
```

In the output, you'll find options to open the app in a
Expand All @@ -25,26 +19,18 @@ In the output, you'll find options to open the app in a

You can start developing by editing the files inside the **app** directory. This project uses [file-based routing](https://docs.expo.dev/router/introduction).

## Get a fresh project

When you're ready, run:

```bash
npm run reset-project
```

This command will move the starter code to the **app-example** directory and create a blank **app** directory where you can start developing.

## Learn more

To learn more about developing your project with Expo, look at the following resources:

- [Expo documentation](https://docs.expo.dev/): Learn fundamentals, or go into advanced topics with our [guides](https://docs.expo.dev/guides).
- [Learn Expo tutorial](https://docs.expo.dev/tutorial/introduction/): Follow a step-by-step tutorial where you'll create a project that runs on Android, iOS, and the web.
- [Nativewind](https://www.nativewind.dev/): Nativewind is a utility-first library for building native apps with Tailwind CSS.
- [Gluestack](https://gluestack.io/): Gluestack is a component library for building native apps with Tailwind CSS.

## Join the community

Join our community of developers creating universal apps.

- [Expo on GitHub](https://github.com/expo/expo): View our open source platform and contribute.
- [Discord community](https://chat.expo.dev): Chat with Expo users and ask questions.
- [gluestack-ui on GitHub](https://github.com/gluestack/gluestack-ui): View our open source ui library and contribute.
- [gluestack community](https://discord.com/channels/1050761204852858900/1336392784168484914): Chat with gluestack users and ask questions.
Original file line number Diff line number Diff line change
@@ -1,40 +1,30 @@
import React from 'react';
import React, { useEffect } from 'react';
import { config } from './config';
import { ColorSchemeName, useColorScheme, View, ViewProps } from 'react-native';
import { View, ViewProps } from 'react-native';
import { OverlayProvider } from '@gluestack-ui/overlay';
import { ToastProvider } from '@gluestack-ui/toast';
import { colorScheme as colorSchemeNW } from 'nativewind';

type ModeType = 'light' | 'dark' | 'system';

const getColorSchemeName = (
colorScheme: ColorSchemeName,
mode: ModeType
): 'light' | 'dark' => {
if (mode === 'system') {
return colorScheme ?? 'light';
}
return mode;
};
import { useColorScheme } from 'nativewind';
import { ModeType } from './types';

export function GluestackUIProvider({
mode = 'light',
...props
}: {
mode?: 'light' | 'dark' | 'system';
mode?: ModeType;
children?: React.ReactNode;
style?: ViewProps['style'];
}) {
const colorScheme = useColorScheme();

const colorSchemeName = getColorSchemeName(colorScheme, mode);
const { colorScheme, setColorScheme } = useColorScheme();

colorSchemeNW.set(mode);
useEffect(() => {
setColorScheme(mode);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [mode]);

return (
<View
style={[
config[colorSchemeName],
config[colorScheme!],
// eslint-disable-next-line react-native/no-inline-styles
{ flex: 1, height: '100%', width: '100%' },
props.style,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { OverlayProvider } from '@gluestack-ui/overlay';
import { ToastProvider } from '@gluestack-ui/toast';
import { setFlushStyles } from '@gluestack-ui/nativewind-utils/flush';
import { script } from './script';
import { ModeType } from './types';

const variableStyleTagId = 'nativewind-style';
const createStyle = (styleTagId: string) => {
Expand All @@ -21,7 +22,7 @@ export function GluestackUIProvider({
mode = 'light',
...props
}: {
mode?: 'light' | 'dark' | 'system';
mode?: ModeType;
children?: React.ReactNode;
}) {
let cssVariablesWithMode = ``;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type ModeType = 'light' | 'dark' | 'system';
1 change: 0 additions & 1 deletion apps/templates/expo-router-with-nativewind/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"version": "1.0.0",
"scripts": {
"start": "expo start",
"reset-project": "node ./scripts/reset-project.js",
"android": "DARK_MODE=media expo start --android",
"ios": "DARK_MODE=media expo start --ios",
"web": "DARK_MODE=media expo start --web",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import gluestackPlugin from "@gluestack-ui/nativewind-utils/tailwind-plugin";

/** @type {import('tailwindcss').Config} */
module.exports = {
darkMode: "media",
darkMode: "class",
content: ["app/**/*.{tsx,jsx,ts,js}", "components/**/*.{tsx,jsx,ts,js}"],
presets: [require("nativewind/preset")],
safelist: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,30 @@
import React from 'react';
import React, { useEffect } from 'react';
import { config } from './config';
import { ColorSchemeName, useColorScheme, View, ViewProps } from 'react-native';
import { View, ViewProps } from 'react-native';
import { OverlayProvider } from '@gluestack-ui/overlay';
import { ToastProvider } from '@gluestack-ui/toast';
import { colorScheme as colorSchemeNW } from 'nativewind';

type ModeType = 'light' | 'dark' | 'system';

const getColorSchemeName = (
colorScheme: ColorSchemeName,
mode: ModeType
): 'light' | 'dark' => {
if (mode === 'system') {
return colorScheme ?? 'light';
}
return mode;
};
import { useColorScheme } from 'nativewind';
import { ModeType } from './types';

export function GluestackUIProvider({
mode = 'light',
...props
}: {
mode?: 'light' | 'dark' | 'system';
mode?: ModeType;
children?: React.ReactNode;
style?: ViewProps['style'];
}) {
const colorScheme = useColorScheme();

const colorSchemeName = getColorSchemeName(colorScheme, mode);
const { colorScheme, setColorScheme } = useColorScheme();

colorSchemeNW.set(mode);
useEffect(() => {
setColorScheme(mode);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [mode]);

return (
<View
style={[
config[colorSchemeName],
config[colorScheme!],
// eslint-disable-next-line react-native/no-inline-styles
{ flex: 1, height: '100%', width: '100%' },
props.style,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { OverlayProvider } from '@gluestack-ui/overlay';
import { ToastProvider } from '@gluestack-ui/toast';
import { setFlushStyles } from '@gluestack-ui/nativewind-utils/flush';
import { script } from './script';
import { ModeType } from './types';

const variableStyleTagId = 'nativewind-style';
const createStyle = (styleTagId: string) => {
Expand All @@ -21,7 +22,7 @@ export function GluestackUIProvider({
mode = 'light',
...props
}: {
mode?: 'light' | 'dark' | 'system';
mode?: ModeType;
children?: React.ReactNode;
}) {
let cssVariablesWithMode = ``;
Expand Down Expand Up @@ -80,6 +81,12 @@ export function GluestackUIProvider({

return (
<>
<script
suppressHydrationWarning
dangerouslySetInnerHTML={{
__html: `(${script.toString()})('${mode}')`,
}}
/>
<OverlayProvider>
<ToastProvider>{props.children}</ToastProvider>
</OverlayProvider>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type ModeType = 'light' | 'dark' | 'system';
Loading