question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Long Text doesn't render correctly when in ScrollView

See original GitHub issue

Environment

React Native Environment Info: System: OS: macOS High Sierra 10.13.6 CPU: (8) x64 Intel® Core™ 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>
);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
KaviduAlokacommented, Feb 10, 2020

Add flexShrink: 1

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

2reactions
triplea24commented, Jan 7, 2019

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>
);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Large amount of text not rendering properly in a scroll view
Got the same problem and here is a solution. Try to separate large <Text> component into several smaller <Text> components.
Read more >
Common bugs in React Native ScrollView and how to fix them
React Native's ScrollView component is ubiquitous, but its implementation can sometimes lead to mistakes. Learn what to look out for here.
Read more >
UIStackView not laying out as expected in a UIScrollView
I'm attempting to put a (vertical) UIStackView in a UIScrollView, but it doesn't seem to want to scroll. Instead it it squishing all...
Read more >
React Native Scrollview 101: The Best Practices Guide - Waldo
Read this deep and comprehensive guide on React Native's scrolling containers, which are called ScrollViews.
Read more >
ScrollView - Android Developers
FOCUS_DOWN If the reference refers to a view that does not exist or is part of a ... Defines text displayed in a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found