Skip to content

Commit

Permalink
Correctly handle RN styles
Browse files Browse the repository at this point in the history
  • Loading branch information
vovkasm committed Dec 16, 2016
1 parent e55c023 commit abc2721
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/stylesheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,27 @@ class Stylesheet {
const ctx = parseContext(context)
const rules = []
this.collectRules(rules, ctx)
const style = {}
let isStyle = false
for (let i in rules) {
const rule = rules[i]
if (rule.props !== undefined) {
mergeTo(props, rule.props)
}
if (rule.style !== undefined) {
if (props.style === undefined) props.style = {}
mergeTo(props.style, rule.style)
mergeTo(style, rule.style)
isStyle = true
}
}
if (isStyle) {
if (props.style === undefined) {
props.style = style
} else if (Array.isArray(props.style)) {
const newStyle = props.style.slice()
newStyle.unshift(style)
props.style = newStyle
} else {
props.style = [style, props.style]
}
}
return props
Expand Down
6 changes: 4 additions & 2 deletions test/stylesheets.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ describe('Stylesheet', function () {
})
it('get correct style with ownStyle', function () {
expect(s.getProps('App Other Text', {style: {color: 'green'}})).to.be.deep.equal({
style: {
style: [{
fontSize: 10,
color: 'black'
}, {
color: 'green'
}
}]
})
})
})
Expand Down

0 comments on commit abc2721

Please sign in to comment.