avi*_*rty 2 reactjs react-native tailwind-css
如果样式是在 App.Js 中完成的,则使用Nativewind 的React-native 样式效果很好。像这儿:
<NavigationContainer>
<View>
<Text className = "text-red-500">Hello</Text>
</View>
</NavigationContainer>
Run Code Online (Sandbox Code Playgroud)
但如果样式是在组件级别完成的,那么它就不再起作用了。
return (
<NavigationContainer>
<HomeScreen/>
</NavigationContainer>
);
Run Code Online (Sandbox Code Playgroud)
主屏幕组件:
import { View, Text } from 'react-native'
import React from 'react'
const HomeScreen = () => {
return (
<View>
<Text className = "text-red-500">Hello</Text>
</View>
)
}
export default HomeScreen
Run Code Online (Sandbox Code Playgroud)
您需要通过将其添加到 tailwind.config.ts 来告诉 Nativewind 您的组件所在的位置
content: ["./App.{js,jsx,ts,tsx}", "./<custom directory such as src>/**/*.{js,jsx,ts,tsx}"],
Run Code Online (Sandbox Code Playgroud)
参考: https: //www.nativewind.dev/quick-starts/react-native-cli