浏览代码

Improve consistency

j8
Lyubomir Marinov 8 年前
父节点
当前提交
d1520773cf

+ 0
- 24
react/features/base/styles/createStyleSheet.js 查看文件

@@ -1,24 +0,0 @@
1
-import { shimStyles } from './shimStyles';
2
-
3
-/**
4
- * Create a style sheet using the provided style definitions.
5
- *
6
- * @param {Object} styles - A dictionary of named style definitions.
7
- * @param {Object} [overrides={}] - Optional set of additional (often
8
- * platform-dependent/specific) style definitions that will override the base
9
- * (often platform-independent) styles.
10
- * @returns {Object}
11
- */
12
-export function createStyleSheet(styles, overrides = {}) {
13
-    const combinedStyles = {};
14
-
15
-    for (const k of Object.keys(styles)) {
16
-        combinedStyles[k]
17
-            = shimStyles({
18
-                ...styles[k],
19
-                ...overrides[k]
20
-            });
21
-    }
22
-
23
-    return combinedStyles;
24
-}

+ 73
- 0
react/features/base/styles/functions.js 查看文件

@@ -0,0 +1,73 @@
1
+/* @flow */
2
+
3
+declare type StyleSheet = Object;
4
+
5
+/**
6
+ * The list of the well-known style properties which may not be numbers on Web
7
+ * but must be numbers on React Native.
8
+ *
9
+ * @private
10
+ */
11
+const _WELL_KNOWN_NUMBER_PROPERTIES = [ 'height', 'width' ];
12
+
13
+/* eslint-disable flowtype/space-before-type-colon */
14
+
15
+/**
16
+ * Create a style sheet using the provided style definitions.
17
+ *
18
+ * @param {StyleSheet} styles - A dictionary of named style definitions.
19
+ * @param {StyleSheet} [overrides={}] - Optional set of additional (often
20
+ * platform-dependent/specific) style definitions that will override the base
21
+ * (often platform-independent) styles.
22
+ * @returns {StyleSheet}
23
+ */
24
+export function createStyleSheet(styles: StyleSheet, overrides: StyleSheet = {})
25
+        : StyleSheet {
26
+
27
+/* eslint-enable flowtype/space-before-type-colon */
28
+
29
+    const combinedStyles = {};
30
+
31
+    for (const k of Object.keys(styles)) {
32
+        combinedStyles[k]
33
+            = _shimStyles({
34
+                ...styles[k],
35
+                ...overrides[k]
36
+            });
37
+    }
38
+
39
+    return combinedStyles;
40
+}
41
+
42
+/**
43
+ * Shims style properties to work correctly on native. Allows us to minimize the
44
+ * number of style declarations that need to be set or overridden for specific
45
+ * platforms.
46
+ *
47
+ * @param {StyleSheet} styles - An object which represents a stylesheet.
48
+ * @private
49
+ * @returns {StyleSheet}
50
+ */
51
+function _shimStyles<T: StyleSheet>(styles: T): T {
52
+    // Certain style properties may not be numbers on Web but must be numbers on
53
+    // React Native. For example, height and width may be expressed in percent
54
+    // on Web but React Native will not understand them and we will get errors
55
+    // (at least during development). Convert such well-known properties to
56
+    // numbers if possible; otherwise, remove them to avoid runtime errors.
57
+    for (const k of _WELL_KNOWN_NUMBER_PROPERTIES) {
58
+        const v = styles[k];
59
+        const typeofV = typeof v;
60
+
61
+        if (typeofV !== 'undefined' && typeofV !== 'number') {
62
+            const numberV = Number(v);
63
+
64
+            if (Number.isNaN(numberV)) {
65
+                delete styles[k];
66
+            } else {
67
+                styles[k] = numberV;
68
+            }
69
+        }
70
+    }
71
+
72
+    return styles;
73
+}

+ 1
- 1
react/features/base/styles/index.js 查看文件

@@ -1,2 +1,2 @@
1 1
 export * from './components';
2
-export * from './createStyleSheet';
2
+export * from './functions';

+ 0
- 38
react/features/base/styles/shimStyles.native.js 查看文件

@@ -1,38 +0,0 @@
1
-/**
2
- * The list of the well-known style properties which may not be numbers on Web
3
- * but must be numbers on React Native.
4
- */
5
-const WELL_KNOWN_NUMBER_PROPERTIES = [ 'height', 'width' ];
6
-
7
-/**
8
- * Shim style properties to work correctly on native.
9
- *
10
- * Using this shimStyles method allows us to minimize the number of style
11
- * declarations that need to be set or overridden for specific platforms.
12
- *
13
- * @param {Object} styles - A dictionary of named style definitions.
14
- * @returns {Object}
15
- */
16
-export function shimStyles(styles) {
17
-    // Certain style properties may not be numbers on Web but must be numbers on
18
-    // React Native. For example, height and width may be expressed in percent
19
-    // on Web but React Native will not understand them and we will get errors
20
-    // (at least during development). Convert such well-known properties to
21
-    // numbers if possible; otherwise, remove them to avoid runtime errors.
22
-    for (const k of WELL_KNOWN_NUMBER_PROPERTIES) {
23
-        const v = styles[k];
24
-        const typeofV = typeof v;
25
-
26
-        if (typeofV !== 'undefined' && typeofV !== 'number') {
27
-            const numberV = Number(v);
28
-
29
-            if (Number.isNaN(numberV)) {
30
-                delete styles[k];
31
-            } else {
32
-                styles[k] = numberV;
33
-            }
34
-        }
35
-    }
36
-
37
-    return styles;
38
-}

正在加载...
取消
保存