React Native外部样式表 [英] React Native External Stylesheet

查看:347
本文介绍了React Native外部样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在React Native中是否有一种方法可以将我的所有样式放在一个文件中,以便可以轻松维护(从我的角度来看),就像在HTML中我们有一个 .css 档案。

Is there a way in React Native that I can put all of my styles in a single file so it can easily be maintained (from my perspective) like in HTML we have a .css file.

我还有一个模块,根据当前用户有不同的样式。

And also I have a module where there are different styles based on a current user.

推荐答案

您可以使用所有样式创建一个样式组件,如此...

You could simply create a Styles component like so with all your styles...

import { StyleSheet } from "react-native"

export default StyleSheet.create({
   ...
})

然后在任何需要样式的视图上,只需要它......

Then on any view needing styles, simply require it...

import styles from "./Styles"

这篇关于React Native外部样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆