Skip to content

Commit

Permalink
Merge pull request #2 from shoutem/feature/forward_native_props
Browse files Browse the repository at this point in the history
* Forward setNativeProps to the child component

- forward the nativeProps to the wrapped component to prevent from
  breaking the wrapped components' functionality if they are native
- https://facebook.github.io/react-native/docs/direct-manipulation.html
  • Loading branch information
Vunovati authored Sep 29, 2016
2 parents 1a4fdcd + 2691b57 commit 720de22
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions connectAnimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export function connectAnimation(WrappedComponent, animations = {}) {
super(props, context);
this.onLayout = this.onLayout.bind(this);
this.resolveStyle = this.resolveStyle.bind(this);
this.setWrappedInstance = this.setWrappedInstance.bind(this);
this.state = {
layout: {
height: 0,
Expand Down Expand Up @@ -174,6 +175,16 @@ export function connectAnimation(WrappedComponent, animations = {}) {
});
}

setNativeProps(nativeProps) {
if (this.wrappedInstance.setNativeProps) {
this.wrappedInstance.setNativeProps(nativeProps);
}
}

setWrappedInstance(component) {
this.wrappedInstance = component;
}

render() {
const { resolvedStyle } = this.state;
const ConnectedComponent = isComponentAnimated(this.props) ?
Expand All @@ -185,6 +196,7 @@ export function connectAnimation(WrappedComponent, animations = {}) {
onLayout={this.onLayout}
{...this.props}
style={resolvedStyle}
ref={this.setWrappedInstance}
/>
);
}
Expand Down

0 comments on commit 720de22

Please # to comment.