Skip to content

Commit

Permalink
Define Flow types for style and stylesheet objects, more checking
Browse files Browse the repository at this point in the history
Summary:
- Define a Styles type for the object that gets passed into StyleSheet.create
- Define a StyleSheet type that is returned from StyleSheet.create
- Clean up the type declarations in StyleSheet.create
Closes #8882

Differential Revision: D3587964

Pulled By: gabelevi

fbshipit-source-id: 629e0176484436848be69b1417638e1200a3669a
  • Loading branch information
ide authored and Facebook Github Bot 2 committed Aug 15, 2016
1 parent 5ee7041 commit 8eed600
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Libraries/StyleSheet/StyleSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ var StyleSheetValidation = require('StyleSheetValidation');

var flatten = require('flattenStyle');

export type Styles = {[key: string]: Object};
export type StyleSheet<S: Styles> = {[key: $Keys<S>]: number};

var hairlineWidth = PixelRatio.roundToNearestPixel(0.4);
if (hairlineWidth === 0) {
hairlineWidth = 1 / PixelRatio.get();
Expand Down Expand Up @@ -160,8 +163,8 @@ module.exports = {
/**
* Creates a StyleSheet style reference from the given object.
*/
create<T: Object, U>(obj: T): {[key:$Keys<T>]: number} {
var result: T = (({}: any): T);
create<S: Styles>(obj: S): StyleSheet<S> {
const result: StyleSheet<S> = {};
for (var key in obj) {
StyleSheetValidation.validateStyle(key, obj);
result[key] = ReactNativePropRegistry.register(obj[key]);
Expand Down

0 comments on commit 8eed600

Please sign in to comment.