Skip to content
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

Long Text doesn't render correctly when in ScrollView #22713

Closed
3 tasks done
zuccha opened this issue Dec 19, 2018 · 12 comments
Closed
3 tasks done

Long Text doesn't render correctly when in ScrollView #22713

zuccha opened this issue Dec 19, 2018 · 12 comments

Comments

@zuccha
Copy link

zuccha commented Dec 19, 2018

Environment

React Native Environment Info:
System:
OS: macOS High Sierra 10.13.6
CPU: (8) x64 Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
Memory: 1.82 GB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 10.11.0 - ~/.nvm/versions/node/v10.11.0/bin/node
Yarn: 1.12.3 - /usr/local/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.11.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
Android SDK:
API Levels: 25, 26, 27, 28
Build Tools: 26.0.3, 27.0.3, 28.0.2
System Images: android-26 | Google APIs Intel x86 Atom, android-27 | Google Play Intel x86 Atom
IDEs:
Android Studio: 3.1 AI-173.4907809
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
react: 16.6.3 => 16.6.3
react-native: 0.57.8 => 0.57.8
npmGlobalPackages:
react-native-cli: 2.0.1

Description

When placing a Text component into a ScrollView on iOS, if Text contains too many characters, then no text is rendered, however the Text component occupies the correct amount of space (i.e., the view scrolls). The number of characters for breaking the Text component varies depending on the device, but it is usually around 25,000.

N.B.: The bug is not present if we replace ScrollView with View.

This bug is not present on Android.

Wrong behaviour (no text, but the view scrolls):
wrong

Correct behaviour (text and the view scrolls):
correct

Reproducible Demo

To reproduce the bug, run the following code on iOS

import React from 'react';
import { Text, ScrollView } from 'react-native';

export default () => (
  <ScrollView>
    <Text>{'a'.repeat(25000)}</Text>
  </ScrollView>
);
@triplea24
Copy link

Hi @zuccha, You should add some style to the ScrollView's container so it can stretch and completely fit in the screen.

Just replace it with this snippet:

export default () => (
  <ScrollView contentContainerStyle={{ flex: 1}}>
    <Text style={{ flex: 1}}>{'a'.repeat(25000)}</Text>
  </ScrollView>
);

@zuccha
Copy link
Author

zuccha commented Jan 12, 2019

Hi @triplea24 thank for your help. I tried with flex: 1, but that way the ScrollView is not scrollable anymore. It is easy to see by putting two long texts one after the other

import React from 'react';
import { Text, ScrollView } from 'react-native';

export default () => (
  <ScrollView contentContainerStyle={{flex:1}}>
    <Text>{'a'.repeat(25000)}</Text>
    <Text>{'b'.repeat(25000)}</Text>
  </ScrollView>
);

The texts should have the same length, but I can't scroll through the 'b's. However, if I remove the flex: 1, the text disappears (but the view has the correct size). I don't think it's a problem of size (again, the view has the correct size).

@LucasMonteiro1
Copy link

Same problem

@grigorii-lapshin
Copy link

Have same problem but with even with text half of the specified length

@danilobuerger
Copy link
Contributor

The bug seems to be related to the height of the content. So with a smaller font size, more text can be displayed.

@danilobuerger
Copy link
Contributor

Seems to be a long standing issue: #9077

@hramos hramos removed the Bug Report label Feb 6, 2019
@alangumer
Copy link

alangumer commented Mar 1, 2019

Same problem here, agreed with @zuccha seems like the issue is with the Text component, the View size is correct.
@zuccha did you find a workaround this?

The workaround I found is to use a WebView

<WebView style={styles.transcript} source={{html: `<p style="font-size:48px;text-align:center">${slide.description}</p>`}} />

@ericlewis
Copy link
Contributor

I did some investigation in to this bug, and it appears to be related to Yoga, or the way we calculate heights using NSTextStorage. I wasn’t able to dig in much further.

@CatapultJesse
Copy link

@CatapultJesse
Copy link

Related Issue: https://github.com/faceabook/react-native/issues/19453

@rickhanlonii
Copy link
Member

Dupe of #19453 👌

@KaviduAloka
Copy link

Add flexShrink: 1

<Text style={{ flexShrink: 1 }}>

@facebook facebook locked as resolved and limited conversation to collaborators Mar 19, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Mar 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests