Commit 30f8898
Fix crash when link endOffset > line offset
Summary:
I got notified that a recent change I made was causing a crash. This would happen when the endOffset of the link is larger than the end offset of the line. This can be repro'd with
```
/**
* (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
*
* flow strict-local
* format
*/
import {useState} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
export default function Playground() {
const [state, setState] = useState(false);
function toggle() {
setState(old => !old);
}
return (
<View style={styles.container}>
<Text
style={[styles.paragraph, state && {backgroundColor: 'red'}]}
numberOfLines={3}>
<Text>Bacon Ipsum{'\n'}</Text>
<Text>Dolor sit amet{'\n'}</Text>
<Text>{'\n'}</Text>
<Text accessibilityRole="link" onPress={toggle}>
http://www.google.com
</Text>
</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: 24,
backgroundColor: '#ecf0f1',
padding: 8,
},
paragraph: {
margin: 24,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
},
});
```
This was encountered already by NickGerleman in D46206673 (facebook#37050) and the fix is fairly straightforward. I modified that fix to check for the endOffset as well.
Changelog: [Internal]
Differential Revision: D748234581 parent 2fa2c20 commit 30f8898
1 file changed
Lines changed: 4 additions & 3 deletions
File tree
- packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text
Lines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
227 | | - | |
228 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
229 | 231 | | |
230 | 232 | | |
231 | 233 | | |
232 | 234 | | |
233 | 235 | | |
234 | 236 | | |
235 | 237 | | |
236 | | - | |
237 | 238 | | |
238 | 239 | | |
239 | 240 | | |
| |||
0 commit comments