Skip to content

Commit e23d1bc

Browse files
committed
commit
1 parent c5dcd97 commit e23d1bc

File tree

5 files changed

+190
-180
lines changed

5 files changed

+190
-180
lines changed

src/index.js

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import React, {useMemo} from 'react';
7-
import {Text} from 'react-native';
7+
import {Text, StyleSheet} from 'react-native';
88
import PropTypes from 'prop-types';
99
import parser from './lib/parser';
1010
import getUniqueID from './lib/util/getUniqueID';
@@ -36,6 +36,39 @@ export {
3636
removeTextStyleProps,
3737
};
3838

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+
3972
const getRenderer = (
4073
renderer,
4174
rules,
@@ -69,21 +102,7 @@ const getRenderer = (
69102
);
70103
}
71104
} 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);
87106

88107
return new AstRenderer(
89108
{

src/lib/AstRenderer.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {StyleSheet} from 'react-native';
2+
13
import getUniqueID from './util/getUniqueID';
24
import convertAdditionalStyles from './util/convertAdditionalStyles';
35

@@ -57,7 +59,6 @@ export default class AstRenderer {
5759
parents.unshift(node);
5860

5961
// calculate the children first
60-
6162
let children = node.children.map(value => {
6263
return this.renderNode(value, parents);
6364
});
@@ -90,7 +91,10 @@ export default class AstRenderer {
9091

9192
// combine in specific styles for the object
9293
if (this._style[parentNodes[a].type]) {
93-
refStyle = {...refStyle, ...this._style[parentNodes[a].type]};
94+
refStyle = {
95+
...refStyle,
96+
...StyleSheet.flatten(this._style[parentNodes[a].type]),
97+
};
9498
}
9599

96100
// then work out if any of them are text styles that should be used in the end.

0 commit comments

Comments
 (0)