Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Overflow And Scroll

Tags:

react-native

I started learning React Native. As far as I see, there is both an "overflow:scroll" style property and a ScrollView. Does using "overflow:scroll" in a View make it a ScrollView in React Native?

like image 961
John L. Avatar asked Sep 27 '16 10:09

John L.


People also ask

How do I scroll screen in React Native?

In the ScrollView, we can scroll the components in both direction vertically and horizontally. By default, the ScrollView container scrolls its components and views in vertical. To scroll its components in horizontal, it uses the props horizontal: true (default, horizontal: false).

How do you scroll text in React Native?

You can use ScrollView for this case. Just put your text inside it and set height to scroll view. Show activity on this post.

What is zIndex in React Native?

zIndex is the Expo and React Native analog of CSS's z-index property which lets the developer control the order in which components are displayed over one another.


2 Answers

if you want overflow: scroll in react native then you have to use these two props

  • scrollEnabled
  • onContentSizeChange

like this

import React, { Component } from "react";
import { ScrollView, View } from "react-native";
const { height } = Dimensions.get("window");

export class index extends Component {
  state = {
    screenHeight: 0,
  };
  onContentSizeChange = (contentWidth, contentHeight) => {
    this.setState({ screenHeight: contentHeight });
  };
  render() {
    const scrollEnabled = this.state.screenHeight > height;
    return (
      <ScrollView
        style={{ flex: 1 }}
        contentContainerStyle={styles.scrollview}
        scrollEnabled={scrollEnabled}
        onContentSizeChange={this.onContentSizeChange}
      >
        <View style={styles.content}></View>
      </ScrollView>
    );
  }
}

export default index;

like image 89
Muhammad Numan Avatar answered Sep 23 '22 00:09

Muhammad Numan


View does not have an overflow: scroll property, the docs only show:

overflow ReactPropTypes.oneOf(['visible', 'hidden'])

The only ways to make a scrollable View are to either use ScrollView or ListView.

like image 23
Nader Dabit Avatar answered Sep 23 '22 00:09

Nader Dabit