Skip to content

Commit

Permalink
MeteorComplexListView
Browse files Browse the repository at this point in the history
  • Loading branch information
Théo mathieu committed Mar 24, 2016
1 parent 5e2ba9c commit 48125bc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Meteor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ 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';


module.exports = {
Accounts: Accounts,
MeteorListView: ListView,
MeteorComplexListView: MeteorComplexListView,
collection: collection,
FSCollection: FSCollection,
getData() {
Expand Down
55 changes: 55 additions & 0 deletions src/components/ComplexListView.js
Original file line number Diff line number Diff line change
@@ -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 (
<ListView
{...this.props}
dataSource={ds}
/>
);
}
}

0 comments on commit 48125bc

Please sign in to comment.