4

I'm having no trouble create a ListView, but I find that if i want to render that ListView inside of a View it breaks and the scroll no longer works.

I understand that two elements can't be next to one another without being wrapped in a parent View but that breaks my ListView. My ListView is rendered the following way, within a React Component named Main.

renderMeeting(meeting) {
  return (
    <TouchableHighlight>
      <View>
        <View style={styles.container}>
          <View style={styles.imaging}>
                <Image source={{uri: meeting.Picture}} style={styles.thumbnail} />
          </View>
          <View style={styles.rightContainer}>
                <Text style={styles.meetingTime}>
                  {meeting.Time}
                </Text>
            <View style={styles.firstRow}>
                <Text style={styles.meetingName}>
                  {meeting.Name}
                </Text>
                <Text style={styles.Title}>
                  {meeting.Title}
                </Text>
                <Text style={styles.Company}>
                  @ {meeting.Company}
                </Text>
            </View>
            <View>
                <Text style={styles.meetingDescription}>
                  {meeting.Description}
                </Text>
            </View>
          </View>
        </View>
        <View style={styles.borderLine} />
      </View>
    </TouchableHighlight>
);
  }

  render() {
  return(
    <ListView
        dataSource={this.state.dataSource}
        renderRow={this.renderMeeting.bind(this)}
        style={styles.listView} />  
      ); 
  }

};

When my render method in index.ios.js just returns this Main component, it works just fine:

render() {
  return (
    <Main>
  );
}

However, if I attempt to wrap Main within a View, it does not work:

render() {
  return (
    <View>
      <Main>
    </View>
  );
}

If I want anything to float over the ListView or if I want to have it only be half page I can't seem to get it to work as long as this component is anywhere is a parent view.

0

1 Answer 1

3

Probably what's happening is the outer view is ending up with a 0 height. You should be able to fix things by giving it a flex style of 1.

render() {
  return (
  <View style={styles.container}>
    <Main>
  </View>
  );
}

Using flex: 1 as a style seems to do the trick for container views like this so it could look something like this:

var styles = StyleSheet.create({
  container: {
    flex: 1
  }
});
Sign up to request clarification or add additional context in comments.

Comments

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.