1

I have a ListView component which is receiving state updates through redux. The component code is:

import React, {
  Component,
  PropTypes,
  View,
  Text,
  StyleSheet,
  ListView
} from 'react-native';

export default class Feed extends Component {

  constructor(props) {
    super(props);
    this.ds = new ListView.DataSource({rowHasChanged: (row1, row2) => row1 !== row2});
    this.state = {
      dataSource: this.ds.cloneWithRows(this.props.items),
    }
  }

  componentWillReceiveProps(nextProps) {
    this.setState({
      dataSource: this.ds.cloneWithRows(nextProps.items)
    });
  }

  renderRow(rowData) {
    console.log('my data');
    console.log(rowData.body.text);

    return(
      <View>
        <Text>{rowData.body.text}</Text>
      </View>
    );
  }

  render() {
    const style = StyleSheet.create({
      helloWorld: {
        color: 'red',
        textAlign: 'center',
      }
    });
    return (
      <View>
        <ListView dataSource={this.state.dataSource} renderRow={(rowData) => {this.renderRow(rowData)}} />
      </View>
    );
  }
}

Feed.propTypes = {
  items: PropTypes.array.isRequired,
}

The List data is coming from an external callout. When the callout is complete the property items is updated and passed through (using redux in the containing component). The console tells me that renderRow is called with the new data but I am receiving a blank screen still. Any ideas? Expecting this to be something stupid.

1
  • This should work, my code is pretty much identical to this.. Only thing I could think of: how large is your container for the View component wrapped around you ListView?Does it have sufficent space to show the row items? Commented Apr 11, 2016 at 13:27

2 Answers 2

2

Not sure if it's a good solution but I solved it using:

removeClippedSubviews={false} 

in Listview Component

Sign up to request clarification or add additional context in comments.

1 Comment

Works like a charm, saved my day! :)
1

There's a trivial bug in your renderRow prop:

<ListView
  dataSource={this.state.dataSource}
  renderRow={(rowData) => {this.renderRow(rowData)}}
/>

The function (rowData) => {this.renderRow(rowData)} doesn't return anything. Change it to (rowData) => this.renderRow(rowData).

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.