Procházet zdrojové kódy

[RN] Add utility function to combine 2 sets of styles

master
Saúl Ibarra Corretgé před 7 roky
rodič
revize
2128c84212
1 změnil soubory, kde provedl 32 přidání a 6 odebrání
  1. 32
    6
      react/features/base/styles/functions.js

+ 32
- 6
react/features/base/styles/functions.js Zobrazit soubor

@@ -5,6 +5,7 @@ import { Platform } from '../react';
5 5
 import { ColorPalette } from './components';
6 6
 
7 7
 declare type StyleSheet = Object;
8
+export type StyleType = StyleSheet | Array<StyleSheet>;
8 9
 
9 10
 /**
10 11
  * The list of the well-known style properties which may not be numbers on Web
@@ -14,7 +15,35 @@ declare type StyleSheet = Object;
14 15
  */
15 16
 const _WELL_KNOWN_NUMBER_PROPERTIES = [ 'height', 'width' ];
16 17
 
17
-/* eslint-disable flowtype/space-before-type-colon */
18
+/**
19
+ * Combines the given 2 styles into a single one.
20
+ *
21
+ * @param {StyleType} a - An object or array of styles.
22
+ * @param {StyleType} b - An object or array of styles.
23
+ * @private
24
+ * @returns {StyleType} - The merged styles.
25
+ */
26
+export function combineStyles(a: StyleType, b: StyleType): StyleType {
27
+    const result = [];
28
+
29
+    if (a) {
30
+        if (Array.isArray(a)) {
31
+            result.push(...a);
32
+        } else {
33
+            result.push(a);
34
+        }
35
+    }
36
+
37
+    if (b) {
38
+        if (Array.isArray(b)) {
39
+            result.push(...b);
40
+        } else {
41
+            result.push(b);
42
+        }
43
+    }
44
+
45
+    return result;
46
+}
18 47
 
19 48
 /**
20 49
  * Create a style sheet using the provided style definitions.
@@ -25,11 +54,8 @@ const _WELL_KNOWN_NUMBER_PROPERTIES = [ 'height', 'width' ];
25 54
  * (often platform-independent) styles.
26 55
  * @returns {StyleSheet}
27 56
  */
28
-export function createStyleSheet(styles: StyleSheet, overrides: StyleSheet = {})
29
-        : StyleSheet {
30
-
31
-/* eslint-enable flowtype/space-before-type-colon */
32
-
57
+export function createStyleSheet(
58
+        styles: StyleSheet, overrides: StyleSheet = {}): StyleSheet {
33 59
     const combinedStyles = {};
34 60
 
35 61
     for (const k of Object.keys(styles)) {

Načítá se…
Zrušit
Uložit