Giter Site home page Giter Site logo

Comments (7)

Romick2005 avatar Romick2005 commented on June 15, 2024

I guess you have bad styles architecture.

What is the purpose of creating two different styles?

const variants = {
  white: StyleSheet.create({
    container: {
      backgroundColor: 'white',
    },
  }),
  primary: StyleSheet.create({
    container: {
      backgroundColor: colors.primary,
    },
  }),
};

It would be better when it would be inside main styles declaration.
Or if you really want dynamic creation it can be like this:

  const viewStyle = [
    styles.container,
    {
      backgroundColor: variant === 'white' ? 'white' : colors.primary
    },
    ...logonScreen ? [styles.center] : [],
  ];

from eslint-plugin-react-native.

AdamGerthel avatar AdamGerthel commented on June 15, 2024

I'm having the same issue. Variant styles are accessed using bracket notation, but the linter doesn't understand it.

I guess you have bad styles architecture.

That's not a very helpful comment. What's bad about it?

from eslint-plugin-react-native.

Romick2005 avatar Romick2005 commented on June 15, 2024

I'm having the same issue. Variant styles are accessed using bracket notation, but the linter doesn't understand it.

I guess you have bad styles architecture.

That's not a very helpful comment. What's bad about it?

But I described in my comment that having multiple Styles.createStylesheet is not very convenient.

What is the point having multiple styles objects not within main style object?

from eslint-plugin-react-native.

AdamGerthel avatar AdamGerthel commented on June 15, 2024

I'm having the same issue. Variant styles are accessed using bracket notation, but the linter doesn't understand it.

I guess you have bad styles architecture.

That's not a very helpful comment. What's bad about it?

But I described in my comment that having multiple Styles.createStylesheet is not very convenient.

Not really. You said:

It would be better when it would be inside main styles declaration.

But what's "better" about it? Having an object with multiple properties, where each key is the name and each value is a style makes sense IMO when you have a lot of style changes from variant to variant. It makes it very easy to see the differences between each variant.

Let's say we have 5 variants and each variant has 3 style properties (i.e. backgroundColor, borderWidth etc). Using your suggestion that would quickly become unmanageable. Ternary operators will be super messy, and it would require at least 5 lines in the array of styles rather than just 1 line when using bracket notation.

from eslint-plugin-react-native.

Romick2005 avatar Romick2005 commented on June 15, 2024

Yeah that is your option. Could you please provide short example and I will edit it how I see it. Just to see smth

from eslint-plugin-react-native.

AdamGerthel avatar AdamGerthel commented on June 15, 2024

Yeah that is your option. Could you please provide short example and I will edit it how I see it. Just to see smth

Here you go: https://snack.expo.dev/jjL9yJ3ze

from eslint-plugin-react-native.

Romick2005 avatar Romick2005 commented on June 15, 2024

Yeah that is your option. Could you please provide short example and I will edit it how I see it. Just to see smth

Here you go: https://snack.expo.dev/jjL9yJ3ze

I would go with theme for your case, but it could also be done like this: https://snack.expo.dev/@romick/variants

Pros: render code is cleaner, no array merge styles logic, all possible styles are cached and is not recreated on every render. Easy to change any style without no changes to break other variant style. All styles within createStylesheet is processed by the linter.
Cons: duplicated styles in some style object that can cause difficulties in adding some style for each variant style.

from eslint-plugin-react-native.

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.