diff --git a/src/Meteor.js b/src/Meteor.js index 33ad56e..faa179e 100644 --- a/src/Meteor.js +++ b/src/Meteor.js @@ -14,6 +14,7 @@ import call from './Call'; import Mixin from './components/Mixin'; import ListView from './components/ListView'; +import MeteorComplexListView from './components/ComplexListView'; import User from './user/User'; import Accounts from './user/Accounts'; @@ -21,6 +22,7 @@ import Accounts from './user/Accounts'; module.exports = { Accounts: Accounts, MeteorListView: ListView, + MeteorComplexListView: MeteorComplexListView, collection: collection, FSCollection: FSCollection, getData() { diff --git a/src/components/ComplexListView.js b/src/components/ComplexListView.js new file mode 100644 index 0000000..3953ad7 --- /dev/null +++ b/src/components/ComplexListView.js @@ -0,0 +1,55 @@ +'use strict'; + +import React, { + Component, + PropTypes, + ListView +} from 'react-native'; + + +import Data from '../Data'; + + +export default class MeteorListView extends Component { + static propTypes = { + elements: PropTypes.func.isRequired, + renderRow: PropTypes.func.isRequired + }; + constructor(props) { + super(props); + + this.state = { + ds: new ListView.DataSource({ + rowHasChanged: (row1, row2) => row1!==row2, + }) + }; + } + componentWillMount() { + + const { elements } = this.props; + + this.onChange = ()=>{ + const elems = elements(); + this.setState({ + ds: this.state.ds.cloneWithRows(elems) + }); + }; + + this.onChange(); + Data.onChange(this.onChange); + + } + componentWillUnmount() { + Data.offChange(this.onChange); + } + render() { + const { ds } = this.state; + + return ( + + ); + } +} \ No newline at end of file