Skip to content

Commit e524d78

Browse files
authored
Merge pull request #109 from gluestack/fix/provider-native
fix: provider update
2 parents ae29afb + b42aaf0 commit e524d78

File tree

10 files changed

+42
-151
lines changed

10 files changed

+42
-151
lines changed
Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
# Welcome to your Expo app 👋
22

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

55
## Get started
66

7-
1. Install dependencies
7+
1. Start the app
88

99
```bash
10-
npm install
11-
```
12-
13-
2. Start the app
14-
15-
```bash
16-
npx expo start
10+
npm run start
1711
```
1812

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

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

28-
## Get a fresh project
29-
30-
When you're ready, run:
31-
32-
```bash
33-
npm run reset-project
34-
```
35-
36-
This command will move the starter code to the **app-example** directory and create a blank **app** directory where you can start developing.
37-
3822
## Learn more
3923

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

4226
- [Expo documentation](https://docs.expo.dev/): Learn fundamentals, or go into advanced topics with our [guides](https://docs.expo.dev/guides).
4327
- [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.
28+
- [Nativewind](https://www.nativewind.dev/): Nativewind is a utility-first library for building native apps with Tailwind CSS.
29+
- [Gluestack](https://gluestack.io/): Gluestack is a component library for building native apps with Tailwind CSS.
4430

4531
## Join the community
4632

4733
Join our community of developers creating universal apps.
4834

49-
- [Expo on GitHub](https://github.com/expo/expo): View our open source platform and contribute.
50-
- [Discord community](https://chat.expo.dev): Chat with Expo users and ask questions.
35+
- [gluestack-ui on GitHub](https://github.com/gluestack/gluestack-ui): View our open source ui library and contribute.
36+
- [gluestack community](https://discord.com/channels/1050761204852858900/1336392784168484914): Chat with gluestack users and ask questions.

apps/templates/expo-router-with-nativewind/components/ui/gluestack-ui-provider/index.tsx

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,30 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import { config } from './config';
3-
import { ColorSchemeName, useColorScheme, View, ViewProps } from 'react-native';
3+
import { View, ViewProps } from 'react-native';
44
import { OverlayProvider } from '@gluestack-ui/overlay';
55
import { ToastProvider } from '@gluestack-ui/toast';
6-
import { colorScheme as colorSchemeNW } from 'nativewind';
7-
8-
type ModeType = 'light' | 'dark' | 'system';
9-
10-
const getColorSchemeName = (
11-
colorScheme: ColorSchemeName,
12-
mode: ModeType
13-
): 'light' | 'dark' => {
14-
if (mode === 'system') {
15-
return colorScheme ?? 'light';
16-
}
17-
return mode;
18-
};
6+
import { useColorScheme } from 'nativewind';
7+
import { ModeType } from './types';
198

209
export function GluestackUIProvider({
2110
mode = 'light',
2211
...props
2312
}: {
24-
mode?: 'light' | 'dark' | 'system';
13+
mode?: ModeType;
2514
children?: React.ReactNode;
2615
style?: ViewProps['style'];
2716
}) {
28-
const colorScheme = useColorScheme();
29-
30-
const colorSchemeName = getColorSchemeName(colorScheme, mode);
17+
const { colorScheme, setColorScheme } = useColorScheme();
3118

32-
colorSchemeNW.set(mode);
19+
useEffect(() => {
20+
setColorScheme(mode);
21+
// eslint-disable-next-line react-hooks/exhaustive-deps
22+
}, [mode]);
3323

3424
return (
3525
<View
3626
style={[
37-
config[colorSchemeName],
27+
config[colorScheme!],
3828
// eslint-disable-next-line react-native/no-inline-styles
3929
{ flex: 1, height: '100%', width: '100%' },
4030
props.style,

apps/templates/expo-router-with-nativewind/components/ui/gluestack-ui-provider/index.web.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { OverlayProvider } from '@gluestack-ui/overlay';
55
import { ToastProvider } from '@gluestack-ui/toast';
66
import { setFlushStyles } from '@gluestack-ui/nativewind-utils/flush';
77
import { script } from './script';
8+
import { ModeType } from './types';
89

910
const variableStyleTagId = 'nativewind-style';
1011
const createStyle = (styleTagId: string) => {
@@ -21,7 +22,7 @@ export function GluestackUIProvider({
2122
mode = 'light',
2223
...props
2324
}: {
24-
mode?: 'light' | 'dark' | 'system';
25+
mode?: ModeType;
2526
children?: React.ReactNode;
2627
}) {
2728
let cssVariablesWithMode = ``;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type ModeType = 'light' | 'dark' | 'system';

apps/templates/expo-router-with-nativewind/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"version": "1.0.0",
55
"scripts": {
66
"start": "expo start",
7-
"reset-project": "node ./scripts/reset-project.js",
87
"android": "DARK_MODE=media expo start --android",
98
"ios": "DARK_MODE=media expo start --ios",
109
"web": "DARK_MODE=media expo start --web",

apps/templates/expo-router-with-nativewind/scripts/reset-project.js

Lines changed: 0 additions & 84 deletions
This file was deleted.

apps/templates/expo-router-with-nativewind/tailwind.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import gluestackPlugin from "@gluestack-ui/nativewind-utils/tailwind-plugin";
22

33
/** @type {import('tailwindcss').Config} */
44
module.exports = {
5-
darkMode: "media",
5+
darkMode: "class",
66
content: ["app/**/*.{tsx,jsx,ts,js}", "components/**/*.{tsx,jsx,ts,js}"],
77
presets: [require("nativewind/preset")],
88
safelist: [

apps/templates/next-app-router-with-nativewind/components/ui/gluestack-ui-provider/index.tsx

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,30 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import { config } from './config';
3-
import { ColorSchemeName, useColorScheme, View, ViewProps } from 'react-native';
3+
import { View, ViewProps } from 'react-native';
44
import { OverlayProvider } from '@gluestack-ui/overlay';
55
import { ToastProvider } from '@gluestack-ui/toast';
6-
import { colorScheme as colorSchemeNW } from 'nativewind';
7-
8-
type ModeType = 'light' | 'dark' | 'system';
9-
10-
const getColorSchemeName = (
11-
colorScheme: ColorSchemeName,
12-
mode: ModeType
13-
): 'light' | 'dark' => {
14-
if (mode === 'system') {
15-
return colorScheme ?? 'light';
16-
}
17-
return mode;
18-
};
6+
import { useColorScheme } from 'nativewind';
7+
import { ModeType } from './types';
198

209
export function GluestackUIProvider({
2110
mode = 'light',
2211
...props
2312
}: {
24-
mode?: 'light' | 'dark' | 'system';
13+
mode?: ModeType;
2514
children?: React.ReactNode;
2615
style?: ViewProps['style'];
2716
}) {
28-
const colorScheme = useColorScheme();
29-
30-
const colorSchemeName = getColorSchemeName(colorScheme, mode);
17+
const { colorScheme, setColorScheme } = useColorScheme();
3118

32-
colorSchemeNW.set(mode);
19+
useEffect(() => {
20+
setColorScheme(mode);
21+
// eslint-disable-next-line react-hooks/exhaustive-deps
22+
}, [mode]);
3323

3424
return (
3525
<View
3626
style={[
37-
config[colorSchemeName],
27+
config[colorScheme!],
3828
// eslint-disable-next-line react-native/no-inline-styles
3929
{ flex: 1, height: '100%', width: '100%' },
4030
props.style,

apps/templates/next-app-router-with-nativewind/components/ui/gluestack-ui-provider/index.web.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { OverlayProvider } from '@gluestack-ui/overlay';
55
import { ToastProvider } from '@gluestack-ui/toast';
66
import { setFlushStyles } from '@gluestack-ui/nativewind-utils/flush';
77
import { script } from './script';
8+
import { ModeType } from './types';
89

910
const variableStyleTagId = 'nativewind-style';
1011
const createStyle = (styleTagId: string) => {
@@ -21,7 +22,7 @@ export function GluestackUIProvider({
2122
mode = 'light',
2223
...props
2324
}: {
24-
mode?: 'light' | 'dark' | 'system';
25+
mode?: ModeType;
2526
children?: React.ReactNode;
2627
}) {
2728
let cssVariablesWithMode = ``;
@@ -80,6 +81,12 @@ export function GluestackUIProvider({
8081

8182
return (
8283
<>
84+
<script
85+
suppressHydrationWarning
86+
dangerouslySetInnerHTML={{
87+
__html: `(${script.toString()})('${mode}')`,
88+
}}
89+
/>
8390
<OverlayProvider>
8491
<ToastProvider>{props.children}</ToastProvider>
8592
</OverlayProvider>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type ModeType = 'light' | 'dark' | 'system';

0 commit comments

Comments
 (0)