|
4 | 4 | */ |
5 | 5 |
|
6 | 6 | import React, {useMemo} from 'react'; |
7 | | -import {Text} from 'react-native'; |
| 7 | +import {Text, StyleSheet} from 'react-native'; |
8 | 8 | import PropTypes from 'prop-types'; |
9 | 9 | import parser from './lib/parser'; |
10 | 10 | import getUniqueID from './lib/util/getUniqueID'; |
@@ -36,6 +36,39 @@ export { |
36 | 36 | removeTextStyleProps, |
37 | 37 | }; |
38 | 38 |
|
| 39 | +// we use StyleSheet.flatten here to make sure we have an object, in case someone |
| 40 | +// passes in a StyleSheet.create result to the style prop |
| 41 | +const getStyle = (mergeStyle, styles, style) => { |
| 42 | + let useStyles = {}; |
| 43 | + |
| 44 | + if (mergeStyle === true && style) { |
| 45 | + Object.keys(styles).forEach(value => { |
| 46 | + useStyles[value] = { |
| 47 | + ...styles[value], |
| 48 | + ...(style !== null ? StyleSheet.flatten(style[value]) : {}), |
| 49 | + }; |
| 50 | + }); |
| 51 | + } else { |
| 52 | + useStyles = { |
| 53 | + ...styles, |
| 54 | + }; |
| 55 | + |
| 56 | + if (style !== null) { |
| 57 | + Object.keys(style).forEach(value => { |
| 58 | + useStyles[value] = { |
| 59 | + ...StyleSheet.flatten(style[value]), |
| 60 | + }; |
| 61 | + }); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + Object.keys(useStyles).forEach(value => { |
| 66 | + useStyles['_VIEW_SAFE_' + value] = removeTextStyleProps(useStyles[value]); |
| 67 | + }); |
| 68 | + |
| 69 | + return StyleSheet.create(useStyles); |
| 70 | +}; |
| 71 | + |
39 | 72 | const getRenderer = ( |
40 | 73 | renderer, |
41 | 74 | rules, |
@@ -69,21 +102,7 @@ const getRenderer = ( |
69 | 102 | ); |
70 | 103 | } |
71 | 104 | } else { |
72 | | - let useStyles = {}; |
73 | | - |
74 | | - if (mergeStyle === true) { |
75 | | - Object.keys(styles).forEach(value => { |
76 | | - useStyles[value] = { |
77 | | - ...styles[value], |
78 | | - ...style[value], |
79 | | - }; |
80 | | - }); |
81 | | - } else { |
82 | | - useStyles = { |
83 | | - ...styles, |
84 | | - ...style, |
85 | | - }; |
86 | | - } |
| 105 | + let useStyles = getStyle(mergeStyle, styles, style); |
87 | 106 |
|
88 | 107 | return new AstRenderer( |
89 | 108 | { |
|
0 commit comments