Bläddra i källkod

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

master
Saúl Ibarra Corretgé 7 år sedan
förälder
incheckning
2128c84212
1 ändrade filer med 32 tillägg och 6 borttagningar
  1. 32
    6
      react/features/base/styles/functions.js

+ 32
- 6
react/features/base/styles/functions.js Visa fil

5
 import { ColorPalette } from './components';
5
 import { ColorPalette } from './components';
6
 
6
 
7
 declare type StyleSheet = Object;
7
 declare type StyleSheet = Object;
8
+export type StyleType = StyleSheet | Array<StyleSheet>;
8
 
9
 
9
 /**
10
 /**
10
  * The list of the well-known style properties which may not be numbers on Web
11
  * The list of the well-known style properties which may not be numbers on Web
14
  */
15
  */
15
 const _WELL_KNOWN_NUMBER_PROPERTIES = [ 'height', 'width' ];
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
  * Create a style sheet using the provided style definitions.
49
  * Create a style sheet using the provided style definitions.
25
  * (often platform-independent) styles.
54
  * (often platform-independent) styles.
26
  * @returns {StyleSheet}
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
     const combinedStyles = {};
59
     const combinedStyles = {};
34
 
60
 
35
     for (const k of Object.keys(styles)) {
61
     for (const k of Object.keys(styles)) {

Laddar…
Avbryt
Spara