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.

Components breaks when using custom styles created by StyleSheet.create

See original GitHub issue

NativeBase components, like Footer and Content breaks when you use the style prop passing an object created by ReactNative StyleSheet.create class.

I’m using the following code to reproduce the problem:

import React, { Component } from "react";
import {Container, Header, Content, Footer, Title, Button} from "native-base";

import { get as getDimension } from "Dimensions";

import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  ScrollView,
} from "react-native";

class AwesomeNativeBase extends Component {

  render() {
    return(
        <Container>
          <Content>
            <Text> Hello nativebase </Text>
          </Content>
          <Footer style={styles.footer}>
            <Text> This is an awesome footer </Text>
          </Footer>
        </Container>
    );
  }
}

const styles = StyleSheet.create({
  footer: {
    backgroundColor: "transparent"
  }
});

AppRegistry.registerComponent("AwesomeNativeBase", () => AwesomeNativeBase);

The error that I get is the following: nativebaseerror

If I change the the Footer as show below the component works fine.

          <Footer style={{ backgroundColor: "transparent" }}>
            <Text> This is an awesome footer </Text>
          </Footer>

I tried to look into nativebase base but I couldn’t find exactly why this hapen but I guess this is related to this nativebase file and this React Native breaking change: StyleSheetRegistry has been renamed to ReactNativePropRegistry. This module is private so it shouldn't affect everyone using React Native's public API, though: 433fb33, this breaking change can be found on this React Native release note.

Thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:21 (4 by maintainers)

github_iconTop GitHub Comments

26reactions
hoduchacommented, May 21, 2016

+1 for this. You can solve this issue by flatten the style object like this:

<Footer style={StyleSheet.flatten(styles.footer)}>
    <Text> This is an awesome footer </Text>
</Footer>
8reactions
jjantcommented, Apr 28, 2017

@sanketsahusoft Please do so, it’s very annoying to have to see which library we’re importing components from to decide how we’re going to create style objects.

Read more comments on GitHub >

github_iconTop Results From Across the Web

StyleSheet.create() inside React Native component
So that way you keep your styles object outside of the component, and they are not newly-created on each re-render. Share.
Read more >
StyleSheet - React Native
A StyleSheet is an abstraction similar to CSS StyleSheets. ... Naming the styles is a good way to add meaning to the low...
Read more >
Solving the React Error: Not Picking Up CSS Style | Pluralsight
In this guide, you will learn about the errors that can occur while importing a CSS file into your React file.
Read more >
How To Style React Components | DigitalOcean
In this tutorial, you'll learn three different ways to style React components: plain Cascading Style Sheets (CSS), inline styles with JavaScript ...
Read more >
Styling // React Native for Web - GitHub Pages
Style performance is improved when styles are defined outside of components using the StyleSheet API. This creates opaque references to the ...
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