-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android] Fix non selectable Text in FlatList #28952
[Android] Fix non selectable Text in FlatList #28952
Conversation
Base commit: 8a8a532 |
Base commit: 8a8a532 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code analysis results:
google-java-format
found some issues. See https://github.com/google/google-java-format
ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java
Outdated
Show resolved
Hide resolved
ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java
Outdated
Show resolved
Hide resolved
@lunaleaps has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Hey, just noticed this PR in the internal review queue :) Not sure doing this in each onDraw here is a correct solution (for performance and otherwise).
|
Code Review from ShikaSD facebook#28952 (comment) A similar solution was merged to master for a similar problem with TextInput inside FlatList facebook#28852
Thanks a lot ShikaSD for the code review. after some investigation I notice that The change was already applied with commit 89340f1 and then reverted later with commit 862136a The title of the revert |
The fix was reverted due to a regression with commit facebook@862136a. I will investigate this change and verify that no regression are introduced
@lunaleaps has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
@lunaleaps merged this pull request in c360b1d. |
calling setError does not display an error if the TextInput is a controlled component. https://reactnative.dev/docs/textinput#value >The value to show for the text input. TextInput is a controlled component, which means the native value will be forced to match this value prop if provided. For most uses, this works great, but in some cases this may cause flickering - one common cause is preventing edits by keeping value the same. In addition to setting the same value, either set editable={false}, or set/update maxLength to prevent unwanted edits without flicker. ```javascript function ErrorExample(): React.Node { const [text, setText] = React.useState(''); const [error, setError] = React.useState(null); return ( <TextInput errorMessage={error} onChangeText={newText => { setText(newText); setError(newText === 'error' ? 'this input is invalid' : null); }} value={text} /> ); } ``` The solution from pr facebook#28952 fixes this issue and forces the update by invalidating the TextInput instance which triggers onAttachedToWindow() To be noticed that there is logic to trigger this updates in the ReactTextInputManager https://github.com/fabriziobertoglio1987/react-native/blob/60b6c9be8e811241039a6db5dc906a0e88e6ba82/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java#L1291-L1292 The PR was previously accepted and could be an acceptable solution for this issue
@fabriziobertoglio1987 I'm on version 0.64.3, and Text still isn't selectable in a FlatList. Any ideas? Setting This is my code: const MyClass = ({data}) => {
const renderItem = useCallback(
(item: key) => {
return (
<View>
<Text selectable> {key} </Text>
<Text selectable> {data[key]} </Text>
</View>
)
}
, [data])
return <FlatList data={Object.keys(data)} renderItem={renderItem}
} |
@Zmwang622 I think it is part of 0.67 https://github.com/facebook/react-native/blob/main/CHANGELOG.md#v0670 |
@fabriziobertoglio1987 Ah okay got it, thanks for the quick response! |
I'm using react-native 0.72.4 and still need |
Please, this issue isn't fixed yet. |
Reopened the issue here: #46999 |
Summary
This issue fixes #26264 fixes #27107
Text is not selectable inside a FlatList on Android. The solution is to invalidate the ReactTextView after a change of the selectable prop. If the view is visible, onDraw(android.graphics.Canvas) will be called at some point in the future and make the Text selectable.
Changelog
[Android] [Fixed] - Fix non selectable Text in FlatList
Test Plan
CLICK TO OPEN TESTS RESULTS
The issue was demonstrated in the following snack (more info in issue #26264).
The solution is:
invalidate()
from setSelectableText after changing theselectable
prop andmSelectableText
value.invalidate()
triggers theonDraw
callback.setTextIsSelectable(mSelectableText);
from theonDraw
callbackThe example below is availabe in RNTester FlatList example. Two options (
onPressDisabled
andtextSelectable
) have been added to test the functionality inside a FlatList.