question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Theming in react-native

See original GitHub issue

The problem In web, I can do following with css props:

import React from "react";
import { css } from "@emotion/core";

const myStyle = theme => css`
  background-color: ${theme.backgroundColor};
`;

const MyComponent = () => <div css={myStyle}>Foo</div>;

export default MyComponent;

The theme object is abstracted from the component.

However, on react-native I need to explicitly provide the theme object using useTheme:

import React from "react";
import { View, Text } from "react-native";
import { css } from "@emotion/native";
import { useTheme } from "emotion-theming";

const myStyle = (theme) => css`
  background-color: ${theme.backgroundColor};
`;

const MyComponent = () => {
  const theme = useTheme();
  return <View style={myStyle(theme)}><Text>Foo</Text></View>;
};

export default MyComponent;

I think it is more consistent if we also abstract the theme object on react-native.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Andaristcommented, Aug 8, 2020

Did I miss anything? Btw I am using emotion@10.0.27

Your code looks fine so not sure what’s happening. I will try to look into this, but cant promise when - this shouldn’t be hard to debug so if you could check this out I would highly appreciate it.

Add css prop in react-native so that we can use something like <Text css={myStyleFunction} /> (i.e. without the styled API usage), or

Probably this.

0reactions
elramuscommented, Feb 10, 2021

Hi, just checking that I understand where things stand with this currently. In React Native, the only way to incorporate your theme (outside of the component, anyway) is with the styled syntax? Getting ahold of theme using the css syntax is not supported?

Thanks for the awesome library 🙌

Read more comments on GitHub >

github_iconTop Results From Across the Web

Theming · React Native Paper
The dark theme adds a white overlay with opacity depending on elevation of surfaces. It uses it for the better accentuation of surface...
Read more >
Themes - React Navigation
Themes allow you to change the colors of various components provided by React Navigation. ... A theme is a JS object containing a...
Read more >
Reactive styles in React Native - Medium
First and foremost we define the theme with the help of interfaces. Our components will be styled based on the Theme interface, and...
Read more >
Theme Variables | React Made Native Easy
Integrating theme variables into our NoteTaker demo ; import {StyleSheet} from 'react-native' ; import theme from '../../styles/theme.style' ; export default ...
Read more >
react-native-theming - npm
A theming library for React Native applications. Latest version: 1.0.21, last published: 3 years ago. Start using react-native-theming in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found