react-native: TextInput inside View doesn't work
<View>
<TextInput placeholder="This works" />
<View>
<TextInput placeholder="This doesn't work" />
</View>
</View>
The sample project with this bug is here - https://github.com/boopathi/textinputbug
Am I doing something wrong here ?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 2
- Comments: 18 (9 by maintainers)
Commits related to this issue
- Adds pointerEvents=box-none as suggested by https://github.com/facebook/react-native/issues/99#issuecomment-87716083 and it works! — committed to boopathi/textinputbug by boopathi 9 years ago
- Fix hitTest for auto Summary: - Returns matching subview hitTest or super hitTest if no match found. Should fix #99 . Closes https://github.com/facebook/react-native/pull/501 Github Author: Boopathi... — committed to vjeux/react-native by boopathi 9 years ago
- Fix hitTest for auto Summary: - Returns matching subview hitTest or super hitTest if no match found. Should fix #99 . Closes https://github.com/facebook/react-native/pull/501 Github Author: Boopathi... — committed to vjeux/react-native by boopathi 9 years ago
- Fix hitTest for auto Summary: - Returns matching subview hitTest or super hitTest if no match found. Should fix #99 . Closes https://github.com/facebook/react-native/pull/501 Github Author: Boopathi... — committed to vjeux/react-native by boopathi 9 years ago
For people looking here for a solution, without understanding/going through someone’s code:
Example:
So interestingly the work’s already been done to support this.
RCTView
will hit test its subviews regardless of whether they’re in its bounds iffpointerEvents
isbox-none
: https://github.com/facebook/react-native/blob/f3cd27cf483671b8821e4f50bfa7bb370893e59a/React/Views/RCTView.m#L126-136And indeed, if we use the original example in https://github.com/boopathi/textinputbug/blob/326362e5d39588682048bccda281d6bb2701d04a/index.ios.js with
pointerEvents='box-none'
on the problem parent views, it works as expected 💥So making this “just work” seems to only be a matter of changing the default
pointerEvents
, or changing the behavior ofRCTPointerEventsUnspecified
to fallback to searching its subviews.