Dár*_*rio 14 javascript navigation reactjs react-native tailwind-css
NativeWind 不起作用。当文件 tailwind.config.js 的内容为“./App,{js,jsx,ts,tsx}”时它可以工作,但自从我实现了 React Navigation 后就不再工作了。
tailwind.config.js:
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./App.{js,jsx,ts,tsx}", "./screens/**/*.{js,jsx,ts,tsx}"],
theme: {
extend: {},
},
plugins: [],
}
Run Code Online (Sandbox Code Playgroud)
包.json:
{
"name": "inovarlagos",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web"
},
"dependencies": {
"@react-navigation/native": "^6.0.12",
"@react-navigation/native-stack": "^6.8.0",
"expo": "~46.0.9",
"expo-status-bar": "~1.4.0",
"nativewind": "^2.0.7",
"react": "18.0.0",
"react-native": "0.69.5",
"react-native-safe-area-context": "4.3.1",
"react-native-screens": "~3.15.0"
},
"devDependencies": {
"@babel/core": "^7.12.9",
"tailwindcss": "^3.1.8"
},
"private": true
}
Run Code Online (Sandbox Code Playgroud)
应用程序.js:
import * as React from 'react';
import { View, Text } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import HomeScreen from './screens/HomeScreen';
const Stack = createNativeStackNavigator();
function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
export default App;
Run Code Online (Sandbox Code Playgroud)
./screens/HomeScreen.js:
import { View, Text } from 'react-native';
import React from 'react';
const HomeScreen = () => {
return (
<View className="flex-1 items-center justify-center bg-black">
<Text className="text-red-200">Futuristik Lagos- Home</Text>
</View>
);
};
export default HomeScreen;
Run Code Online (Sandbox Code Playgroud)
项目结构:
结果(TailWind 不起作用):
小智 32
我假设您正在使用 NativeWind,因为 React Native 最近终止了对 TailwindCSS 的支持。
首先停止expo服务器。然后,不要使用 启动它expo start
,而是运行expo start -c
以擦除 NativeWind 添加的缓存并重新启动服务器。
来源: https: //www.nativewind.dev/guides/troubleshooting
如果您使用的是 Expo,只需将以下代码放入您的 app.js 中
import { NativeWindStyleSheet } from "nativewind";
NativeWindStyleSheet.setOutput({
default: "native",
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
14779 次 |
最近记录: |