react-native-platform-touchable
react-native-platform-touchable copied to clipboard
Question regarding children constraint
We all know that TouchableNativeFeedback
only support one single child. But, why don't handle it and wrap the children into a View
?
render () {
// changing some pieces of your render
// notice the `toArray`
children = React.Children.toArray(children);
// notice the View wrapping the children
return <TouchableComponent>
<View>{children}</View>
</TouchableComponent>
}
Just wondering why don't do this approach :)
from docs:
// Good
<Touchable>
<Child>
<GrandChild />
<GrandChild />
</Child>
</Touchable>
// Bad
<Touchable>
<Child />
<Child />
</Touchable>
in the good example:
<View>
-> <Child>...</Child>
{children}
-> <GrandChild /><GrandChild />
Because you should be in control yourself :)
Adding a wrapper to your element could have a major impact on your layout, which would introduce you to a lot of "why doesnt this work" bugs, without seeing the error in your own code.