Giter Club home page Giter Club logo

react-native-css's People

Contributors

agereaude avatar alexmick avatar alfonsodev avatar caiosba avatar davidgruebl avatar drmabuse23 avatar explodingcabbage avatar irfaan avatar jxpearce-godaddy avatar martnu avatar originalgremlin avatar siemiatj avatar thabti avatar tylermcginnis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-css's Issues

npm WARN requires

I get this message at the end of the npm install:

npm WARN [email protected] requires a peer of react-native@>=0.5 but none was installed.

should I ignore it?

Interest in Integrating?

So a while back I wrote this...
https://github.com/jspears/postcss-react-native
Its very similar, however it has a few things that react-native-css does not.

  • Transitions
  • Animations
  • Full shorthand support.
  • psuedo classes.
  • Multi file watching.
  • Postcss plugin
  • Orientation Change
  • Relative units.

--Work Started On --

  • Background images.
  • Gradients.

If there's interest I'd attempt to do a big old PR, but it would be pretty major. Otherwise maybe there is some useful code for people out there.

Syntax improvements

description {
  margin-Bottom: 20;
  fontSize: 18;
  textAlign: center;
  color: #656656;
}

Why margin-Bottom but textAlign? Could we not have marginBottom?

Little hack for code complete to who use VSCode! [suggestion]

Hi,

Who uses the VSCode, version >= 1.20.0, if you put the css word in a .js or .jsx file, you will can use css-code complete.

Take a look:

captura de tela de 2018-02-18 11-59-03

captura de tela de 2018-02-18 12-00-58

And it works normally! Even with interpolation ;)

[EDIT]
Remember that is not a JSON type, so you could not use comma after each item:

captura de tela de 2018-02-18 12-29-36

value auto is set like null

Hi,

When I use the property with 'auto', it set like null ¿it is normal?

for example:

img {
  width: 100%;
  height: auto;
}

Generate

"img":{"width":100,"height":null}

Thank you!!

Update purpose and scope

I recently stumbled upon this project as a result of the pain of using styles in react-native and found it to be extremely useful as is (with a couple fixes). However it is only part of the solution as I ideally want to leverage a bulk of styling assets as well as making it easy to change entire themes gracefully. I was able to throw a quick solution together that is able to somewhat replicate how CSS works in the browser and allow implicit styling of components and pushed it into the 'inheritance' branch. For a quick guide of what it does and how it works, look at https://github.com/sabeurthabti/react-native-css/tree/inheritance/examples.

The question is whether or not to actually include this functionality in this project or to push it entirely into a different project. I'm strongly in favor of keeping it in this project for 2 main reasons: 1) It requires the current code to function, 2) it follows strongly with the name of the project.

Key Updates

  1. I've added a flag to the client called 'inherit'. This changes the functionality of the normal transform by doing the following:
  • It keeps classes intact.
  • Text is treated as a special rule and any text properties in parent containers are 'inhertied' into the text property using a special [selector]&inherited key. While this can be referenced directly in the current scheme, it is especially handy when combined with the next change.
  1. I've added a component wrapper that looks up matching CSS selectors and automatically injects the corresponding styles into the target component.
    • Component paths are generated via getChildContext implementation.
    • The wrapped component accepts an optional className property, however still responds to just selecting by component name, e.g. 'view > text'.
    • I've created a very lean and simple parser and matcher. Since there is just a small subset of CSS that maps to react-native, I didn't want to bloat runtime code with excess libraries. It works, however I assume several improvements can be made overtime. Styles are highly cached to reduce any performance impact one way or the other.

Suggested purpose

One of the best and worst things about React is that it is a very un-opinionated framework. In fact their goal is to create a framework that uses pure JavaScript conventions without any special designs. The downside is that they don't offer a good direction for styling projects. The current method is cumbersome for large projects. It is especially bad when you want to leverage choosable themes or you have to create white-labeled versions (not an uncommon practice for me).

I believe that SASS is a far superior way of styling compared to the standard react-native way. Speed, flexibility and features like import and extend make it significantly easier to use and maintain compared to the JS styles. Additionally the ability to share partials with traditional web projects is a huge plus. Fundamentally I see these as a more than fair tradeoff compared to the small performance hit of implementing the styling.

Along these lines I propose expanding the scope of the project to incorporate this new line. Additionally this architecture can allow for adding things like media query support or even special properties that can map to non-style properties, ios#shadow would be a good example of this.

@sabeurthabti Let me know if you're open to this change or would prefer I move it to a separate project and just use this as a dependency. My only qualm with that is the name here is so good.

No Longer under active development.

I am keen to get someone involved to carry this project on and push it further. I don't work with React-native actively and I have not contributed to the core of this project.

If you're interest in this project please email me: [email protected]

Shorthands aren't properly expanding

Two value shorthands, e.g. padding:10px 20px, are expanding only into Top and Bottom using the Left, Right values, e.g. {paddingTop:20, paddingBottom:20}.

Additionally, border-width and border-radius are also shorthands however aren't treated as such, e.g. border-width: 1px 0 is converted to {borderWidth: 10}.

TypeError: Object input.css has no method 'includes'

Not sure why this is failing. Apparently input is not defined as a file.

tbuck:Desktop $ react-native-css input.css output.js
React-native-css - v1.2.2

/usr/local/lib/node_modules/react-native-css/build/index.js:28
        if (input.includes('scss')) {
                  ^
TypeError: Object /Users/tbuckley/Desktop/input.css has no method 'includes'
    at Object.parse (/usr/local/lib/node_modules/react-native-css/build/index.js:28:13)
    at Object.<anonymous> (/usr/local/lib/node_modules/react-native-css/bin/react-native-css:20:6)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

nesting styles

Hi guys,
I love your module.

One thing about nesting. I see that this sass:

mainContainer {
  flex: 1;
  padding: 30px;
  backgroundColor: #FF9900;
  flexDirection: column;

  headerText {
    color: white;
  }
}

Is converted into:

"mainContainer headerText":{"color":"white"}

Which means I need to select it in react like this:

<Text style={styles['mainContainer headerText']}>Header</Text>

Was this how you intended it to work? Or you have a better suggestion about how to use it?

undefined is not a function (Symbol.iterator)

[email protected]
[email protected]
Android 7.1.1
Only happens when remote debugging is turned off.
Crapping out on line 95 of build/index

 for (var _iterator = stylesheet.rules[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {

This line was transpiled from src/index at line 65:

 65 for (const rule of stylesheet.rules) {

Looks like the guys at styled components faced the same issue and removed dependency on (for of) styled-components/css-to-react-native#31

screenshot_20170905-210413

Convert px to numbers fails when overriding previous property

This css

.row {
  padding: 10px;
  padding-left: 5px;
  flex-direction: row;
  margin-bottom: 2px;
}

will compile to

row: {
  paddingTop: 10,
  paddingBottom: 10,
  paddingRight: 10,
  paddingLeft: "5px",
  flexDirection: row,
  marginBottom: "2px",
}

which is not valid for a React Native Stylesheet.

I believe this is because the padding-left overrides the padding just above and that isn't properly managed.

I've forked the repo, written a regression test and will try to submit a PR with a fix.

TypeError: cb is not a function

when I want to use react-native-css like this

react-native-css ./styles/css/new.css ./styles/js/style.js

then

/Users/lxxyx/.nvm/versions/node/v5.8.0/lib/node_modules/.react-native-css_npminstall/react-native-css/1.2.29/react-native-css/build/index.js:58
          cb(styleSheet);
          ^

TypeError: cb is not a function
    at /Users/lxxyx/.nvm/versions/node/v5.8.0/lib/node_modules/.react-native-css_npminstall/react-native-css/1.2.29/react-native-css/build/index.js:58:11
    at tryToString (fs.js:414:3)
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:401:12)

I had try sass scss and css
but i got same question.

My OS is mac osx 10.10 and node.js 5.7/5.8(5.7,5.8,4.4LTS got same question)

Thank you

Repo description is misleading

To someone new to React Native and unfamiliar with styling in it, the description of this repo makes it sound like it will allow you to write components with id and class attributes and style them with CSS like you would style HTML elements in a browser. I had hoped to use this to reuse our CSS when converting an existing React application to React Native.

The reality is that it just creates a React Native Stylesheet object mapping CSS selectors to rules; it's still necessary to explicitly look up rule sets by selector to use them, rendering this tool useless for my use case, and only helpful for a very niche set of scenarios. This could be clearer in the repo description.

Perhaps remove the sentences "Style React-Native components with css and built in support for SASS" and "Write your React-Native component styles in CSS/SCSS" from the description and instead put something like "Generate a React Native Stylesheet from your CSS with the selectors as keys." That would be equally clear to people who understand React Native without confusing newbies.

Media queries support?

I assume it should work since the module simply creates a json structure. Just asking to be sure that it works.

Convert properties that don't match their CSS equivalent

For instance:

  • text-decoration should be converted to textDecorationLine
  • flex-grow to flex
  • vertical-align to textAlignVertical
  • textAlignVertical: "middle" to textAlignVertical: "center"
  • transforms to an array, eg: translate(100) scaleY(100) to [{ translate: 100, scaleY: 100 }]
  • position: fixed to position: "absolute"
  • border-(top|right|bottom|left): 0|none to border(Top|Right|Bottom|Left)Width: 0

This would help to re-use existing CSS.

Using dash in naming

React-native StyleSheet apparently doesn't accept dash "-" in the names unlike css. React interprets dash as an indicator for multiple classes.
So react-native-css shouldn't just create names with dashes in the output file.
I would say it should output an error when generating js file.

Add validation

We should add validation for CSS properties that would generate invalid RN values and display a warning in the console for these values and preferably show the file and line number. This is useful for catching values that would behave unexpectedly in RN, especially when porting web assets.

  • Any size values that aren't ended with px (or if the unit is omitted). %, em, pt, etc.
  • Values that use 'auto' or calc(...)
  • Non-single value flex properties
  • line-height must end in px.
  • Unsupported properties, e.g. float, background, etc. This probably should be an optional flag to show individual properties on this. Ignore these properties with one warning per file if flag is not set.
  • Mixing properties that would not be supported on the same component.

This would be especially useful since the authors of many CSS assets probably won't know the supported styles of RN or intend their styling to be used in RN.

scss - font-weight value needs double quotes

Hi, I got an issue:
My SCSS:
txt {
color: #00f;
font-weight: 400;
}
is translated to JS:
module.exports = require('react-native').StyleSheet.create({
"txt": {
"color": "#00f",
"fontWeight": 400
}
});
but React Native throws an error that 400 has to be within double quotes like "400"

bash: react-native-css: command not found

I have a problem.
I install react-native-css through npm successfully,
2015-12-27 10 48 00

but when I run "react-native-css" in terminal, it console a mistake as this.

bash: react-native-css: command not found

I can't figure it out.

shadowOpacity

How can I properly use the shadowOpacity: {height, width}?

watching multiple files?

Trying to use your awesome module as an npm script in my project, but when I do something like:

node_modules/react-native-css/bin/react-native-css -i src/styles/_scss/*.scss -o src/styles/*.styles.js -w

It looks like your script is taking the * literally… How can I watch multiple files?

Thanks a bunch. This is really cool!

Doesn't work with Windows OS

If I use Linux, this package work correctly but in windows... --pretty params doesn't work and only the first class is interpreted...

Version 2

Just to announce we are releasing version two:

- Remove sass/scss support, this is a huge overhead for little benefit. 
- No CLI, we believe that this is an unnecessary context switch
- NO I/O, no longer writing files, we do everything at runtime.  

Old code is still available on the v1 branch and we can continue pushing that development.

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.