Uh oh!
There was an error while loading. Please reload this page.
[Android] Fix non selectable Text in FlatList - #28952
Conversation
Base commit: 8a8a532 |
Base commit: 8a8a532 |
analysis-bot
left a comment
There was a problem hiding this comment.
Code analysis results:
google-java-formatfound some issues. See https://github.com/google/google-java-format
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
facebook-github-bot
commented
Jul 29, 2021
@lunaleaps has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
ShikaSD
commented
Aug 2, 2021
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 react#28952 (comment) A similar solution was merged to master for a similar problem with TextInput inside FlatList react#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 react@862136a. I will investigate this change and verify that no regression are introduced
facebook-github-bot
commented
Aug 17, 2021
@lunaleaps has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
facebook-github-bot
commented
Sep 1, 2021
@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 react#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: constMyClass=({data})=>{constrenderItem=useCallback((item: key)=>{return(<View><Textselectable>{key}</Text><Textselectable>{data[key]}</Text></View>)},[data])return<FlatListdata={Object.keys(data)}renderItem={renderItem}} |
fabOnReact
commented
Aug 28, 2022
@Zmwang622 I think it is part of 0.67 https://github.com/facebook/react-native/blob/main/CHANGELOG.md#v0670 |
Zmwang622
commented
Aug 29, 2022
@fabriziobertoglio1987 Ah okay got it, thanks for the quick response! |
markedwards
commented
Sep 11, 2023
I'm using react-native 0.72.4 and still need |
Code-Victor
commented
Sep 19, 2024
Please, this issue isn't fixed yet. |
LA-Johan
commented
Oct 12, 2024
Reopened the issue here: #46999 |
Summary
This issue fixes#26264fixes#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 theselectableprop andmSelectableTextvalue.invalidate()triggers theonDrawcallback.setTextIsSelectable(mSelectableText);from theonDrawcallbackThe example below is availabe in RNTester FlatList example. Two options (
onPressDisabledandtextSelectable) have been added to test the functionality inside a FlatList.