react-native-platform-touchable icon indicating copy to clipboard operation
react-native-platform-touchable copied to clipboard

Question regarding children constraint

Open sospedra opened this issue 6 years ago • 2 comments

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 :)

sospedra avatar Sep 07 '17 18:09 sospedra

from docs:

// Good
<Touchable>
  <Child>
    <GrandChild />
    <GrandChild />
  </Child>
</Touchable>

// Bad
<Touchable>
  <Child />
  <Child />
</Touchable>

in the good example: <View> -> <Child>...</Child> {children} -> <GrandChild /><GrandChild />

b-asaf avatar Nov 22 '17 14:11 b-asaf

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.

Cnordbo avatar Dec 10 '18 09:12 Cnordbo