Skip to content

Stylesheet.create incompatible return type #2068

Description

@badsyntax

The problem

The return type of RNW StyleSheet.create is incompatible with RN StyleSheet.create. This causes problems in css libraries where RN is aliased to RNW via https://www.npmjs.com/package/babel-plugin-react-native-web.

RNW implementation:

create(styles: Object): {| [key: string]: number |} {
const result = {};
Object.keys(styles).forEach((key) => {
if (process.env.NODE_ENV !== 'production') {
validate(key, styles);
}
const id = styles[key] && ReactNativePropRegistry.register(styles[key]);
result[key] = id;
});
return result;
},

RN implementation:

https://github.com/facebook/react-native/blob/36318b6776507ba31070f6c8a3493609238a1a98/Libraries/StyleSheet/StyleSheet.js#L359-L371

How to reproduce

// RNW
StyleSheet.create({
  foo: {
    color: 'blue'
  }
})
// results in: { foo: 89 }


// RN
StyleSheet.create({
  foo: {
    color: 'blue'
  }
})
// results in: { foo: { color: 'blue' } }

Simplified test case: Not sure if this is useful: https://codesandbox.io/s/async-bush-kfpgo?file=/src/App.js

Expected behavior

I expect the return type to match RN.

Environment (include versions). Did this work in previous versions?

  • React Native for Web (version): 0.17.0
  • React (version): 16.14.0
  • Browser: n/a

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions