Invariant Violation: Touchable child must either be native or forward setNativeProps to a native component
See original GitHub issueHi,
when I’m trying to wrap my custom component by TouchableOpacity
<TouchableOpacity onPress={this._goToThreadDetail}>
<CommonThreadRow {...item} />
</TouchableOpacity>
so application falls with error: Invariant Violation: Touchable child must either be native or forward setNativeProps to a native component
How to solve this? Thank you.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:3
- Comments:10 (2 by maintainers)
Top Results From Across the Web
Invariant Violation: Touchable child must either be native or ...
I was able to fix a similar error in my app by following the instructions in the docs about Composite components and setNativeProps...
Read more >iOS : Error: Invariant Violation: Touchable child must either be ...
iOS : Error: Invariant Violation : Touchable child must either be native or forward setNativeProps to a native component stack [ Beautify ...
Read more >Invariant Violation: Touchable child must either be native or ...
Coding example for the question Error: Invariant Violation: Touchable child must either be native or forward setNativeProps to a native component stack.
Read more >Direct Manipulation - React Native
If you run this you will immediately see this error: Touchable child must either be native or forward setNativeProps to a native component...
Read more >invariant violation nothing was returned from render react-native
Invariant Violation: Touchable child must either be native or forward setNativeProps to a native component #1040. Invariant Violation: Touchable child must ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The problem with those two components, is that they reach in the internals of the child via setNativeProps and POPAnimationMixin.startAnimation. In the meantime, you can wrap your children into a
<View>
and it should work fine.I’m working on a larger proposal that would address those two problems.
The React way is to pass down updated values on every frame as prop and let the child component update on every frame. The issue is that if you don’t implement shouldComponentUpdate in your child component (which is highly likely) then you’re going to re-render large parts of your app and the animation or update will be really slow.
So, in order to “fix” this, what we do is to take the underlying node and set the values directly. This works when you are passing native components such as View or Image, but if you are passing composite components it falls apart. This is a really unfortunate situation as the biggest strength of React is that you can build your app with those composite components.
My idea is to pass down the current opacity as the style prop as usual, and let it any composite component in between manipulate it and thread it through an eventual native component. Then, the trick is to record on what native element and what style attribute it was eventually applied to.
If you can store this information as metadata of the style value, then anytime you want to update it, you can just list all the affected elements and set their value directly.
In order to make this work, you need the value to be opaque, meaning that all the composite components (which are implemented using arbitrary js) can only move it around but not be able to inspect the value. Thankfully for style, this isn’t an issue in practice as all the objects returned from StyleSheet.create are already opaque.
You’ll likely hear more from this crazy idea in the next few weeks 😃
@vjeux So, umm, where is this crazy idea…? I’m still getting this same error after 2 years…