Skip to content

Commit 0b8518e

Browse files
committed
chore: Merge plugins for nativewind & portability patterns
2 parents c299b6a + 9efca2f commit 0b8518e

24 files changed

+2241
-1177
lines changed

apps/expo/app/ExpoRootLayout.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@ import { Image as ExpoContextImage } from '@app/core/components/Image.expo'
55
import { Link as ExpoContextLink } from '@app/core/navigation/Link.expo'
66
import { useRouter as useExpoContextRouter } from '@app/core/navigation/useRouter.expo'
77
import { useRouteParams as useExpoRouteParams } from '@app/core/navigation/useRouteParams.expo'
8+
import { NativeWindStyleSheet } from 'nativewind'
89

910
// -i- Expo Router's layout setup is much simpler than Next.js's layout setup
1011
// -i- Since Expo doesn't require a custom document setup or server component root layout
1112
// -i- Use this file to apply your Expo specific layout setup:
1213
// -i- like rendering our Universal Layout and App Providers
1314

14-
/* --- <ExpoRootLayout/> ----------------------------------------------------------------------- */
15+
/* --- Settings -------------------------------------------------------------------------------- */
16+
17+
NativeWindStyleSheet.setOutput({
18+
default: 'native',
19+
})
20+
21+
/* --- <ExpoRootLayout> ------------------------------------------------------------------------ */
1522

1623
export default function ExpoRootLayout() {
1724
// Navigation

apps/expo/babel.config.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// babel.config.js
22
module.exports = function (api) {
3-
api.cache(true);
3+
api.cache(true)
44
return {
5-
presets: ["babel-preset-expo"],
6-
};
7-
};
5+
presets: ['babel-preset-expo'],
6+
plugins: ['nativewind/babel'],
7+
}
8+
}

apps/expo/tailwind.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const { universalTheme } = require('@app/core/tailwind.theme')
2+
3+
/** @type {import('tailwindcss').Config} */
4+
module.exports = {
5+
content: [
6+
'../../apps/**/*.tsx',
7+
'../../features/**/*.tsx',
8+
'../../packages/**/*.tsx',
9+
],
10+
plugins: [],
11+
theme: {
12+
...universalTheme,
13+
},
14+
}

apps/next/babel.config.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// babel.config.js
22
module.exports = function (api) {
3-
api.cache(true);
3+
api.cache(true)
44
return {
5-
presets: ["babel-preset-expo"],
6-
};
7-
};
5+
presets: ['babel-preset-expo'],
6+
plugins: ['nativewind/babel', { mode: 'transformOnly' }],
7+
}
8+
}

apps/next/global.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2+
@tailwind base;
3+
@tailwind components;
4+
@tailwind utilities;
5+
16
/* -i- Upgrade from the CSS reset that came with Expo's default Next.js setup */
27
/* Follows the setup for react-native-web: */
38
/* https://necolas.github.io/react-native-web/docs/setup/#root-element */

apps/next/next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const nextConfig = withExpo({
88
"react-native",
99
"react-native-web",
1010
"expo",
11+
"nativewind",
1112
// Add more React Native / Expo packages here...
1213
],
1314
experimental: {

apps/next/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
"dependencies": {
66
"next": "~14.0.4"
77
},
8-
"devDependencies": {},
8+
"devDependencies": {
9+
"autoprefixer": "^10.4.19",
10+
"postcss": "8.4.23"
11+
},
912
"scripts": {
1013
"dev": "next dev",
1114
"build": "next build",

apps/next/postcss.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
plugins: {
3+
tailwindcss: {},
4+
autoprefixer: {},
5+
},
6+
}

apps/next/tailwind.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { universalTheme } = require('@app/core/tailwind.theme')
2+
3+
/** @type {import('tailwindcss').Config} */
4+
module.exports = {
5+
content: [
6+
'../../apps/**/*.tsx',
7+
'../../features/**/*.tsx',
8+
'../../packages/**/*.tsx',
9+
],
10+
plugins: [require('nativewind/tailwind/css')],
11+
important: 'html',
12+
theme: {
13+
...universalTheme,
14+
},
15+
}

features/app-core/components/Image.expo.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Image as ExpoImage } from 'expo-image'
2-
import { UniversalImageProps, UniversalImageMethods } from './Image.types'
32
import { Platform } from 'react-native'
3+
import { parseNativeWindStyles } from '../utils/parseNativeWindStyles'
4+
import type { UniversalImageProps, UniversalImageMethods } from './Image.types'
45

56
/* --- <Image/> -------------------------------------------------------------------------------- */
67

@@ -39,10 +40,13 @@ const Image = (props: UniversalImageProps): JSX.Element => {
3940
responsivePolicy,
4041
} = props
4142

43+
// -- Nativewind --
44+
45+
const { nativeWindStyles, restStyle } = parseNativeWindStyles(style)
46+
const finalStyle = { width, height, ...nativeWindStyles, ...restStyle }
47+
4248
// -- Overrides --
4349

44-
// @ts-ignore
45-
const finalStyle = { width, height, ...style }
4650
if (fill) finalStyle.height = '100%'
4751
if (fill) finalStyle.width = '100%'
4852

0 commit comments

Comments
 (0)