|
|
1
Victor Rutskin
5 月前
-
确保您安装了所需的依赖项:
npm install nativewind react-native-reanimated
如果您正在使用expo:
npm install --save-dev babel-plugin-tailwindcss-react-native
-
配置你的babel.config.js,你的babel-config.js应该看起来像这样:
module.exports = function (api) {
api.cache(true);
return {
presets: [
["babel-preset-expo", { jsxImportSource: "nativewind" }],
"nativewind/babel",
],
plugins: ["react-native-reanimated/plugin",'babel-plugin-dotenv'],
};
};
-
现在,您还需要为项目配置tailwind.config.js,
如果你没有,那么:
npx tailwindcss init
然后将内容更改为:
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./app/**/*.{js,jsx,ts,tsx}",
"./components/**/*.{js,jsx,ts,tsx}",
],
...
}
-
将其导入到root_layout中:
import 'react-native-reanimated';
-
现在,在确保您已正确配置所有内容后,这是一个如何在tailwind.config.js中定义自己的动画的示例:
module.exports = {
theme: {
extend: {
animation: {
'fade-in': 'fadeIn 1s ease-in-out',
},
keyframes: {
fadeIn: {
'0%': { opacity: 0 },
'100%': { opacity: 1 },
},
},
},
},
};
然后像这样使用它:
<View className="animate-fade-in">
<Text>Hello, world!</Text>
</View>
|