Skip to content

ScrollView does not show its content properly with some styling #14815

@luqiuyuan

Description

@luqiuyuan

Is this a bug report?

Yes

Have you read the Bugs section of the Contributing to React Native Guide?

Yes

Environment

  1. react-native -v:
    react-native-cli: 2.0.1
    react-native: 0.45.1

  2. node -v:
    v8.1.2

  3. npm -v:
    5.0.3

  4. yarn --version (if you use Yarn):
    not use yarn

Then, specify:

  1. Target Platform (e.g. iOS, Android):
    iOS and Android

  2. Development Operating System (e.g. macOS Sierra, Windows 10):
    macOS Sierra

  3. Build tools (Xcode or Android Studio version, iOS or Android SDK version, if relevant):
    Xcode 8.3.3
    Android Studio 2.3
    iOS version 10.3.2
    Android SDK version 23

Steps to Reproduce

  1. Create a new RN project with react-native init APP
  2. Replace the initial codes withe the codes below (The codes might seem unnecessarily complicated, but it was extracted and simplified from a real project as a minimal version to reproduce the issue.):
import React, { Component } from 'react';
import {
  AppRegistry,
  Text,
  View,
  ScrollView
} from 'react-native';

export default class App extends Component {
  render() {
    return (
      <View style={{flex:1, paddingTop:50}}>
        <ScrollView contentContainerStyle={{borderWidth:1, borderColor:'red'}}>
          <View style={{flexDirection:'row'}}>
            <View style={{alignItems:'flex-start', backgroundColor:'gray', padding:20}}>
              <View>
                <Text>
                  {'\n'}
                </Text>
              </View>
            </View>
          </View>
          <View style={{height:50}} />
          <View style={{flexDirection:'row'}}>
            <View style={{alignItems:'flex-start', backgroundColor:'gray', padding:20}}>
              <View>
                <Text>
                  row 2
                </Text>
              </View>
            </View>
          </View>
        </ScrollView>
      </View>
    );
  }
}

AppRegistry.registerComponent('App', () => App);
  1. Run the project on iOS or Android

Expected Behavior

The codes above simply show two rows in a scroll view. In the first row, it shows a Text component with a linefeed '\n', while in the second row, it shows a Text component with a string 'row 2'.

The expected behaviour is shown as the screenshot below:

img_0280

Where the red border shows the border of the content container of the scroll view.

Actual Behavior

The actual behaviour is shown below in order of iOS and Android:

img_0277

screenshot_2017-07-03-23-22-29

As you can see, the second row is kicked out of the content container of the scroll view on iOS. On Android, the second row does not even show at all.

Reproducible Demo

I created an expo demo to show the issue. Just scan the QR code and you will see the issue on the first screen.

https://snack.expo.io/By2lZquNZ

Notes

I have some notes here to help relieve the work of debugging:

  1. Replacing the linefeed '\n' with empty string, the issue remains.
  2. In the first row, replacing the linefeed '\n' with any other non-empty string will get rid of this issue.
  3. Removing flexDirection:'row' or alignItems:'flex-start' from the first row will get rid of this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions