Skip to content

Commit

Permalink
Merge pull request styled-components#764 from MatthieuLemoine/v2
Browse files Browse the repository at this point in the history
[v2] Restore setNativeProps
  • Loading branch information
kitten authored May 22, 2017
2 parents e0d3fa5 + 280e2d7 commit 88d7f6d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ All notable changes to this project will be documented in this file. If a contri
- Switch to babel-preset-env. (see [#717](https://github.com/styled-components/styled-components/pull/717))
- Update StyledNativeComponent to match StyledComponent implementation.
- Fix Theme context for StyledComponent for IE <10. (see [#807](https://github.com/styled-components/styled-components/pull/807))
- Restore `setNativeProps` in StyledNativeComponent, thanks to [@MatthieuLemoine](https://github.com/MatthieuLemoine). (see [#764](https://github.com/styled-components/styled-components/pull/764))

## [v1.4.6] - 2017-05-02

Expand Down
20 changes: 18 additions & 2 deletions src/models/StyledNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default (constructWithOptions: Function) => {
static styledComponentId: string
static attrs: Object
static inlineStyle: Object
root: Object

attrs = {}
state = {
Expand Down Expand Up @@ -95,8 +96,21 @@ export default (constructWithOptions: Function) => {
}
}

setNativeProps(nativeProps: Object) {
this.root.setNativeProps(nativeProps)
}

onRef = (node: any) => {
const { innerRef } = this.props
this.root = node

if (typeof innerRef === 'function') {
innerRef(node)
}
}

render() {
const { children, style, innerRef } = this.props
const { children, style } = this.props
const { generatedStyles } = this.state
const { target } = this.constructor

Expand All @@ -107,8 +121,10 @@ export default (constructWithOptions: Function) => {
}

if (!isStyledComponent(target)) {
propsForElement.ref = innerRef
propsForElement.ref = this.onRef
delete propsForElement.innerRef
} else {
propsForElement.innerRef = this.onRef
}

return createElement(target, propsForElement, children)
Expand Down
1 change: 0 additions & 1 deletion src/native/test/native.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ describe('native', () => {

// $FlowFixMe
expect(ref).toHaveBeenCalledWith(view.node)
expect(innerComponent.prop('innerRef')).toBe(ref)
})
})
})

0 comments on commit 88d7f6d

Please sign in to comment.