fabOnReact / react-native-notes

MIT License
0 stars 0 forks source link

Text is not rendered fully in the available space. #16

Open fabOnReact opened 1 year ago

fabOnReact commented 1 year ago

https://gist.github.com/fabriziobertoglio1987/7173e32796635cac5390d4d3fb4ed9b9 https://github.com/facebook/react-native/issues/39722 https://github.com/Expensify/App/issues/21219 PR https://github.com/facebook/react-native/pull/41770

fabOnReact commented 1 year ago
Testing getWidth support of padding and margin

| getLineWidth | getWidth | | ----------- | ----------- | | | |

fabOnReact commented 1 year ago

Use boring layout instead of getWidth

CLICK TO OPEN EXAMPLE

```javascript import * as React from 'react'; import { Button, Text, SafeAreaView, StyleSheet, Pressable, View, } from 'react-native'; const RNTesterApp = () => { const [text, setText] = React.useState('From vincenzoddragon+five@gmail.com'); var things = ['short', 'verylong', 'superlongword']; var thing = things[Math.floor(Math.random() * things.length)]; const addText = () => { setText(prevText => prevText + ' ' + thing); }; const email = 'From vincenzoddragon+five@gmail.com From vincenzoddragon+five@gmail.com \n'; return ( <> {text}

CLICK TO OPEN VIDEOS

| Original Issue commit 85308 | After PR | | ----------- | ----------- | | | |

fabOnReact commented 1 year ago
BoringLayout support for margin and padding with single line text

```javascript const RNTesterApp = () => { const email = 'From vincenzoddragon+five@gmail.com From vincenzoddragon+five@gmail.com'; return ( <> {email} ); }; const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', padding: 8, backgroundColor: 'yellow', }, flexBrokenStyle: { flexDirection: 'row', backgroundColor: 'red', }, input: { backgroundColor: 'pink', marginLeft: 50, paddingLeft: 50, marginRight: 50, paddingRight: 50, }, }); ``` | Before | After | | ----------- | ----------- | | | | https://github.com/facebook/react-native/commit/008b6ea20eacf6a8beb9c1beff7e3ee1c21705ef The previous implementation does not support margin and padding: Screenshot 2023-12-02 at 1 27 19 PM Screenshot 2023-12-02 at 1 27 35 PM Screenshot 2023-12-02 at 1 27 48 PM The new implementation correctly adds margin and padding: Screenshot 2023-12-02 at 1 23 16 PM Screenshot 2023-12-02 at 1 23 23 PM Screenshot 2023-12-02 at 1 30 23 PM

fabOnReact commented 1 year ago
Text width is larger of parent

Text width is higher of parent ([YogaMeasureMode.EXACTLY](https://github.com/fabriziobertoglio1987/react-native/blob/008b6ea20eacf6a8beb9c1beff7e3ee1c21705ef/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java#L132))

CLICK TO OPEN TESTS RESULTS

```javascript const RNTesterApp = () => { const email = 'From vincenzoddragon+five@gmail.com From vincenzoddragon+five@gmail.com'; return ( <> {email} ); }; const styles = StyleSheet.create({ container: { justifyContent: 'center', padding: 8, backgroundColor: 'yellow', }, flexBrokenStyle: { paddingTop: 50, paddingRight: 0, width: 300, height: 300, backgroundColor: 'red', }, input: { backgroundColor: 'pink', width: 400, }, }); ```

| Before | After | | ----------- | ----------- | | | |

fabOnReact commented 1 year ago
Nested Text with different fontSize

CLICK TO OPEN SOURCECODE

```javascript const RNTesterApp = () => { const email1 = 'From vincenzoddragon+five@gmail.com'; const email2 = 'From vincenzoddragon+five@gmail.com'; return ( <> {email1} {email2} ); }; const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', padding: 8, backgroundColor: 'yellow', }, flexBrokenStyle: { flexDirection: 'row', backgroundColor: 'red', }, input: { backgroundColor: 'pink', }, nestedText: { fontSize: 30, }, }); ```

| Before | After | | ----------- | ----------- | | | |

fabOnReact commented 1 year ago
No regression detected with adjustFontSizeToFit

| Before | After | | ----------- | ----------- | | | |

fabOnReact commented 1 year ago
No regresssion when using flex shrink

CLICK TO OPEN TESTS RESULTS

```javascript const RNTesterApp = () => { const [flexShrink, setFlexShrink] = React.useState(1); const increaseShrink = () => { setFlexShrink(prevFlexShrink => prevFlexShrink + 1); }; const email = 'From vincenzoddragon+five@gmail.com From vincenzoddragon+five@gmail.com'; return ( <> {email} flexShrink is {flexShrink}

| Before | After | | ----------- | ----------- | | | |

fabOnReact commented 1 year ago
RNTester examples (old architecture)

1) FontSizeAdjustment, Wrap, Hyphenation | Before | After | | ----------- | ----------- | | | | 2) Padding | Before | After | | ----------- | ----------- | | | | 3. Text Metrics | Before | After | | ----------- | ----------- | | | | 4. Nested, Text Align | Before | After | | ----------- | ----------- | | | | 5. Number of Lines, allowFontScaling | Before | After | | ----------- | ----------- | | | | | Before | After | | ----------- | ----------- | | | |

fabOnReact commented 1 year ago
  1. Text Metrics
Before After
  1. Nested, Text Align
Before After
fabOnReact commented 1 year ago
  1. Number of Lines, allowFontScaling
Before After
Before After
fabOnReact commented 1 year ago
RNTester examples (new architecture, no changes added in new arch)

1. Dynamic Font Size Adjustment | Before | After | | ----------- | ----------- | |

fabOnReact commented 1 year ago
  1. Font Size Adjustment with Dynamic Layout
Before After
fabOnReact commented 1 year ago
  1. Wrap, Hyphenation, Padding
Before After
  1. Arabic Language (rtl)
Before After
  1. English Language (ltr)
Before After
fabOnReact commented 1 year ago
The text takes the full available space

CLICK TO OPEN SOURCECODE

```javascript import * as React from 'react'; import {Text, SafeAreaView, StyleSheet, Pressable, View} from 'react-native'; const RNTesterApp = () => { const email = 'From vincenzoddragon+five@gmail.com From vincenzoddrlxagon+five@gmail.com'; return ( <> {email} ); }; export default RNTesterApp; const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', padding: 8, backgroundColor: 'yellow', }, flexBrokenStyle: { flexDirection: 'row', }, flexBrokenStyle2: { alignSelf: 'flex-start', }, }); ```

| Before | After | | ----------- | ----------- | | | |