hippie
hippie

Reputation: 669

ReactNative ScrollView inside a View

Im trying to make a scrollview inside a View in ReactNative. For some reason i cant scroll in the ScrollView.

render() {
    return (
      <View>
        <View>
          <Text>Top</Text>
        </View>
        <ScrollView >
          <Text>Line 1</Text>
          <Text>Line 2</Text>
          <Text>Line 3</Text>
          <Text>Line 4</Text>
          <Text>Line 5</Text>
          <Text>Line 6</Text>
          <Text>Line 7</Text>
          ...
        </ScrollView>
      </View>
    );
  }

What is wrong here? Im testing on Android

Thanks, Magnus

Upvotes: 1

Views: 3750

Answers (2)

harisman nug
harisman nug

Reputation: 56

don't forget to import scrollview from react native like this :import { Text, View, ScrollView } from 'react-native';

    render() {
        return (
          <View style={styles.container}> // style in firstview
            <View>
              <Text>Top</Text>
            </View>
            <ScrollView contentContainerStyle={styles.Scroll}>// and give style in scrollview
              <Text>Line 1</Text>
              <Text>Line 2</Text>
              <Text>Line 3</Text>
              <Text>Line 4</Text>
              <Text>Line 5</Text>
              <Text>Line 6</Text>
              <Text>Line 7</Text>
            </ScrollView>
          </View>
        );
      }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: 'orange',
        justifyContent: 'center',
        // alignItems: 'center'
    },
    Scroll: {
      height: 1000,
      paddingVertical: 30,
  }
});

Upvotes: 2

hasseio
hasseio

Reputation: 609

You should give the ScrollView a height. From the example in the docs;

<ScrollView style={styles.scrollView}>
...
...
var styles = StyleSheet.create({
  scrollView: {
    height: 300,
  },
});

Upvotes: 5

Related Questions