Fix(iOS): onPress fails for Text with nested View#49393
Closed
coado wants to merge 1 commit into
Closed
Conversation
Contributor
|
@coado has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Summary: On the new architecture the `RCTParagraphTextView` is used to draw text on iOS but React doesn't know about it. The hit test stops propagation on the first encountered UIView of this type. The suggested solution is to add a dummy hit test for `RCTParagraphTextView` that returns always `null`, allowing further search of the touch target. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [IOS][FIXED] - Fixed onPress for Text with nested View. Test Plan: | Before | After | |--------------|--------------| |<video src="https://github.com/user-attachments/assets/745f555a-d4b6-4285-91a7-0e9ea9f43d84"> | <video src="https://github.com/user-attachments/assets/9896848f-13ca-4b57-bcc9-bead478ab078"> | <details> <summary>code</summary> ```ts import {SafeAreaView, StyleSheet, Text, View, findNodeHandle} from 'react-native'; function App() { return ( <SafeAreaView style={styles.container}> <Text ref={e => console.log(`Outer Text: ${findNodeHandle(e)}`)} > With Nested View <View ref={e => console.log(`View: ${findNodeHandle(e)}`)}> <Text ref={e => console.log(`Inner Text: ${findNodeHandle(e)}`)} onPress={() => { console.log('1. text pressed'); }} style={styles.pressableText} > Pressable Text </Text> </View> </Text> <Text> Without Nested View <Text onPress={() => { console.log('2. text pressed'); }} style={styles.pressableText} > Pressable Text </Text> </Text> </SafeAreaView> ); } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', gap: 10, }, pressableText: { fontSize: 18, color: 'blue', backgroundColor: 'transparent', }, nestedView: { backgroundColor: 'red', height: 100, }, pressable: { backgroundColor: 'blue', height: 100, width: 100, }, }); export default App; ``` </details> Differential Revision: D69591520 Pulled By: coado
149e7d5 to
06e034c
Compare
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D69591520 |
Contributor
Collaborator
|
This pull request was successfully merged by @coado in 6b2c40c When will my fix make it into a release? | How to file a pick request? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
On the new architecture the
RCTParagraphTextViewis used to draw text on iOS but React doesn't know about it. The hit test stops propagation on the first encountered UIView of this type. The suggested solution is to add a dummy hit test forRCTParagraphTextViewthat returns alwaysnull, allowing further search of the touch target.Changelog:
[IOS][FIXED] - Fixed onPress for Text with nested View.
Test Plan:
before.mov
after.mov
code