mirror of
https://github.com/status-im/react-native.git
synced 2025-02-26 08:05:34 +00:00
Define Flow types for style and stylesheet objects, more checking
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 https://github.com/facebook/react-native/pull/8882 Differential Revision: D3587964 Pulled By: gabelevi fbshipit-source-id: 629e0176484436848be69b1417638e1200a3669a
This commit is contained in:
parent
5ee70415bc
commit
8eed600d5b
@ -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();
|
||||
@ -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]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user