Giter Site home page Giter Site logo

Comments (21)

hoducha avatar hoducha commented on May 4, 2024 26

+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>

from nativebase.

jjant avatar jjant commented on May 4, 2024 8

@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.

from nativebase.

sanketsahu avatar sanketsahu commented on May 4, 2024 4

@bishbashbosh123 We can add the compatibility of Stylesheet.create() but that wouldn't add anything to the performance here because StyleSheet.create passes the object to the native layer only once and if we fetch the object in the JS layer and pass the object again to the native layer. It doesn't make sense.

But we are going to add the support of Stylesheet.create() in the next version.

from nativebase.

jeroenpeeters avatar jeroenpeeters commented on May 4, 2024 2

@sanketsahusoft, why can't you support it? Wouldn't it be as simple as checking the type of the style argument? when it's an object let NativeBase call Stylesheet.create(). When it's an number, don't do anything.

from nativebase.

fab1an avatar fab1an commented on May 4, 2024 1

This apparently breaks usage of my styling-library.

from nativebase.

poupryc avatar poupryc commented on May 4, 2024 1

This is not working in the latest verison

from nativebase.

sankhadeeproy007 avatar sankhadeeproy007 commented on May 4, 2024

Yes, that is something we too came across while testing. As of now NativeBase only supports inline styles and not style objects. We'll fix this with our next release.

from nativebase.

erickzanardo avatar erickzanardo commented on May 4, 2024

@sankhadeeproy007 Awesome, thanks for the response, I will wait for the next release.

from nativebase.

sankhadeeproy007 avatar sankhadeeproy007 commented on May 4, 2024

Hey @hoducha, thanks for helping out. @erickzanardo We got a bit busy with other stuff, expect an update early next week.

from nativebase.

erickzanardo avatar erickzanardo commented on May 4, 2024

@hoducha thanks for the help

@sankhadeeproy007 no problem, take your time :D

Thanks all

from nativebase.

sankhadeeproy007 avatar sankhadeeproy007 commented on May 4, 2024

It has been fixed and is available in development branch. Not publishing now as we're planning on adding a few more features for the next release. Pull from the development branch if you need it urgently.

from nativebase.

hoducha avatar hoducha commented on May 4, 2024

Great. Thanks all.

from nativebase.

dvluong avatar dvluong commented on May 4, 2024

Issue still exists in version 2.0.5. Only works if you use version 0.5.11 of nativebase.

from nativebase.

shivrajkumar avatar shivrajkumar commented on May 4, 2024

@dvluong version 2.0.5 doesn't support Stylesheet.create yet
http://nativebase.io/docs/v2.0.0/migration

from nativebase.

dvluong avatar dvluong commented on May 4, 2024

@shivrajkumar Ahh ok, did not realize it was still in the works, thanks!

from nativebase.

sanketsahu avatar sanketsahu commented on May 4, 2024

@dvluong Actually, it doesn't look like we will ever support Stylesheet.create() because internally it is called by NativeBase engine. You can just pass the CSS object in style props instead.

from nativebase.

sanketsahu avatar sanketsahu commented on May 4, 2024

@jeroenpeeters

It's not that straightforward because

  • If the style attribute gets a number we need to fetch the reverse mapped JS object to get the styles and merge it to the style present in the context because NativeBase has contextual styling which is affected by some base style of the component and the context where the component is being used.
  • Also, React Native doesn't provide a way to translate the number of Stylesheet with the corresponding JS object. We manually required some files of React Native with 0.x and we didn't want to add that hack again

from nativebase.

designorant avatar designorant commented on May 4, 2024

Just pointing #510, #525, #527 here for more context on the issue and to point everyone to @hoducha's workaround above in case they prefer to keep all stylesheets in one place.

from nativebase.

jamesjessian avatar jamesjessian commented on May 4, 2024

I've just switched from storing my styles as flat objects to objects generated from StyleSheet.create and got this problem. I can't find any clear reason why anyone should use StyleSheet.create rather than flat objects anyway. Does anyone know? I don't quite understand the performance reasons in the React Native docs:

Making a stylesheet from a style object makes it possible to refer to it by ID instead of creating a new style object every time.

My style objects aren't created in the render method, if that's what this is referring to; I import them so I think they're only created once.

It also allows to send the style only once through the bridge. All subsequent uses are going to refer an id (not implemented yet).

The latter I can understand, but it's apparently not implemented anyway.

But on this note, @sanketsahusoft :

React Native doesn't provide a way to translate the number of Stylesheet with the corresponding JS object.

...isn't that what StyleSheet.flatten does?

from nativebase.

manujvashist avatar manujvashist commented on May 4, 2024

@hoducha this is not working for

from nativebase.

jaimevelasquezjr avatar jaimevelasquezjr commented on May 4, 2024

base in your code, I think you miss this code to add
import { StyleSheet } from 'react-native';

from nativebase.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.