首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Emotion.js如何在react-native中进行合成/条件样式设计?

Emotion.js如何在react-native中进行合成/条件样式设计?
EN

Stack Overflow用户
提问于 2019-10-10 16:24:03
回答 1查看 2.1K关注 0票数 1

https://github.com/emotion-js/emotion/tree/master/packages/native

举个例子

代码语言:javascript
复制
    style={css`
      border-radius: 10px;
    `}

但是,我不知道如何才能像在https://emotion.sh/docs/composition中使用react-native那样执行composition

代码语言:javascript
复制
    <div css={[danger, base]}>

我也不能像在https://emotion.sh/docs/styled中那样做条件样式

代码语言:javascript
复制
const Button = styled.button`
  color: ${props =>
    props.primary ? 'hotpink' : 'turquoise'};
`

即使我可以这样做,他们也会使用两种不同的方法,一种是使用css,另一种是使用styled。如何使用react-native同时获得这两个?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-10 22:44:11

问题1:如何在React Native的emotion/native中执行composition

它非常简单,你只需要像这样使用style属性:

代码语言:javascript
复制
const style1 = css`
  font-size: 40px;
`

const color = css`
  color: red;
`

// And then in your component you can pass the all your style objects 
// in an array to style property
<Text style={[fontSize, color]}>Hello world</Text>

问题2: React Native中emotion/native中的条件样式?

代码语言:javascript
复制
const Description = styled.Text`
    font-size: ${props =>  props.fontSize !== undefined ? props.fontSize : "40px"};
  color: hotpink;
`

<Description fontSize={"60px"}>
Change code in the editor and watch it change on your phone! Save to get a shareable url.
</Description>

这是一个作为snack的工作示例

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58318472

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档