6

I can't seem to figure out why a screen in my Android app doesn't scroll at all in the Android emulator. Here's my code:

import React, { Component } from 'react';
import Dimensions from 'Dimensions';

import {
  Text,
  ScrollView,
  View,
  TouchableHighlight,
  StyleSheet
} from 'react-native';


const win = Dimensions.get('window');

class DeficiencyItem extends Component {

    render() {
        const touchable = {
                width:win.width/2-20,
                height:230,
                backgroundColor:'red',
              };
        return (
            <TouchableHighlight style={touchable}>
                <View>
                    <Text>Item Here</Text>
                </View>
            </TouchableHighlight>
        );
  }
}

export default class Items extends Component {
  static navigationOptions = {title:'hey'};

    constructor(props)
    {
        super(props);
    }

    render() {

        let deficiencies = [];
        for(let x = 0; x<12;x++)
        {
            let row = <DeficiencyItem key={x} />;
            deficiencies.push(row);
        }
        return (
            <View style={{flex:1}}>
              <ScrollView style={{
                margin:5,
                flexWrap: 'wrap',
                flexDirection:'row',
              }}>
               {deficiencies}
              </ScrollView>
            </View>
        );
  }
}

There are items exceeding the bottom limit of the view port. But touch drag to scroll in the emulator does nothing. What did I do wrong?

1
  • Tell me how can i also install react native Commented Oct 28, 2017 at 4:27

2 Answers 2

8

if there is no view outside scrollview than remove View element and add flex:1 to scrollview.

Scrollview should be parent view,

<ScrollView style={styles.container}>
  <View style={{flex:1}}>
    {deficiencies}
  </View>
</ScrollView>

container: {
    flex: 1,
  }
Sign up to request clarification or add additional context in comments.

1 Comment

This doesn't work for me. Could you take a look here? stackoverflow.com/questions/63437251/…
0

My ScrollView is nested in two other views. The issue was solved by providing a height to the scrollview. It's not necessary on iOS so, after adding Platform and Dimensions to react native imports, I do this:

 const { height } = Dimensions.get("screen");
 const styles = StyleSheet.create({
 scrollView: {
   // my outer views have flex:1 so no flex needed here
   alignItems: "center",
   justifyContent: "center", // or whatever you want
   width: "100%,
   height: Platform.OS === "android" ? height * 1.3 : height,
   // if it was just "height", there would be no extra space to scroll on android
 },

 // lots of other styles and stuff

 });

2 Comments

What should we use as the height? The screen height? I tried adding height: '50%' but it didn't work for me. Could you take a look here? stackoverflow.com/questions/63437251/…
This messes up with the height of the screen in different devices :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.