Theming in react-native
See original GitHub issueThe 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:
- Created 3 years ago
- Comments:11 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
Probably this.
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 oftheme
using thecss
syntax is not supported?Thanks for the awesome library 🙌