11.11.0 • Published 12 months ago

@emotion/native v11.11.0

Weekly downloads
86,037
License
MIT
Repository
github
Last release
12 months ago

@emotion/native

Style and render React Native components using emotion

Install

npm install @emotion/react @emotion/native

or if you use yarn

yarn add @emotion/react @emotion/native

This package also depends on react, react-native and prop-types so make sure you've them installed.

Example

import React from 'react'
import { AppRegistry } from 'react-native'
import styled, { css } from '@emotion/native'

const Container = styled.View`
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 50px;
`

const Description = styled.Text({
  color: 'hotpink'
})

const Image = styled.Image`
  padding: 40px;
`

const emotionLogo = 'https://cdn.rawgit.com/emotion-js/emotion/main/emotion.png'

class App extends React.Component {
  render() {
    return (
      <Container
        style={css`
          border-radius: 10px;
        `}
      >
        <Description style={{ fontSize: 45, fontWeight: 'bold' }}>
          Emotion Primitives
        </Description>
        <Image
          source={{
            uri: emotionLogo,
            height: 150,
            width: 150
          }}
        />
      </Container>
    )
  }
}

AppRegistry.registerComponent('ExampleApp', () => App)

Theming

Use @emotion/react for theming support.

import React from 'react'
import styled, { css } from '@emotion/native'
import { ThemeProvider } from '@emotion/react'

const theme = {
  color: 'hotpink',
  backgroundColor: 'purple'
}

const Container = styled.View`
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 50px;
  border: 5px solid red;
  background-color: ${props => props.theme.backgroundColor};
`

const Description = styled.Text({
  color: 'hotpink'
})

const Image = styled.Image`
  padding: 40px;
`

const emotionLogo = 'https://cdn.rawgit.com/emotion-js/emotion/main/emotion.png'

class App extends React.Component {
  render() {
    return (
      <ThemeProvider theme={theme}>
        <Container
          style={css`
            border-radius: 10px;
          `}
        >
          <Description style={{ fontSize: 45, fontWeight: 'bold' }}>
            Emotion Primitives
          </Description>
          <Image
            source={{
              uri: emotionLogo,
              height: 150,
              width: 150
            }}
          />
        </Container>
      </ThemeProvider>
    )
  }
}

Gotchas

  • Note that the flex property works like CSS shorthand, and not the legacy flex property in React Native. Setting flex: 1 sets flexShrink to 1 in addition to setting flexGrow to 1 and flexBasis to 0.
11.10.6

1 year ago

11.11.0

12 months ago

11.10.0

2 years ago

11.9.3

2 years ago

11.0.0

3 years ago

11.0.0-rc.0

4 years ago

11.0.0-next.19

4 years ago

11.0.0-next.18

4 years ago

11.0.0-next.17

4 years ago

11.0.0-next.16

4 years ago

11.0.0-next.15

4 years ago

11.0.0-next.14

4 years ago

11.0.0-next.13

4 years ago

11.0.0-next.12

4 years ago

11.0.0-next.11

4 years ago

11.0.0-next.10

4 years ago

10.0.27

4 years ago

11.0.0-next.9

4 years ago

11.0.0-next.8

4 years ago

11.0.0-next.7

4 years ago

11.0.0-next.6

4 years ago

11.0.0-next.5

4 years ago

11.0.0-next.4

4 years ago

11.0.0-next.3

4 years ago

11.0.0-next.2

4 years ago

11.0.0-next.1

4 years ago

11.0.0-next.0

4 years ago

10.0.22

5 years ago

10.0.14

5 years ago

10.0.11

5 years ago

10.0.10

5 years ago

10.0.9

5 years ago

10.0.8

5 years ago

10.0.7

5 years ago

10.0.6

5 years ago

10.0.5

5 years ago

10.0.4

5 years ago

10.0.3

5 years ago

10.0.2

5 years ago

10.0.1

5 years ago

10.0.0

5 years ago

10.0.0-beta.13

5 years ago

10.0.0-beta.12

5 years ago

10.0.0-beta.11

5 years ago

10.0.0-beta.10

5 years ago

10.0.0-beta.8

5 years ago

10.0.0-beta.7

5 years ago

10.0.0-beta.6

6 years ago

10.0.0-beta.5

6 years ago

10.0.0-beta.4

6 years ago

10.0.0-beta.3

6 years ago

10.0.0-beta.2

6 years ago

10.0.0-beta.1

6 years ago

10.0.0-beta.0

6 years ago

9.2.9

6 years ago

9.2.7

6 years ago