Rocket.Chat.ReactNative/app/views/roomsList.js

65 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-08-03 18:23:43 +00:00
import React from 'react';
2017-08-05 18:16:32 +00:00
import PropTypes from 'prop-types';
2017-08-09 01:40:55 +00:00
import { View, FlatList, StyleSheet } from 'react-native';
import realm from '../lib/realm';
2017-08-09 02:27:22 +00:00
import RocketChat from '../lib/meteor';
2017-08-03 18:23:43 +00:00
2017-08-09 01:40:55 +00:00
import RoomItem from '../components/RoomItem';
2017-08-03 18:23:43 +00:00
const styles = StyleSheet.create({
container: {
flex: 1
},
separator: {
height: 1,
// width: "86%",
backgroundColor: '#CED0CE'
// marginLeft: "14%"
}
});
2017-08-09 01:40:55 +00:00
export default class RoomsListView extends React.Component {
2017-08-05 18:16:32 +00:00
static propTypes = {
navigation: PropTypes.object.isRequired
2017-08-03 18:23:43 +00:00
}
constructor(props) {
super(props);
2017-08-07 18:42:02 +00:00
this.state = {
2017-08-09 02:27:22 +00:00
dataSource: realm.objects('subscriptions').filtered('_server.id = $0', RocketChat.currentServer).sorted('name')
2017-08-07 18:42:02 +00:00
};
}
2017-08-03 18:23:43 +00:00
2017-08-05 18:16:32 +00:00
_onPressItem = (id) => {
const { navigate } = this.props.navigation;
navigate('Room', { sid: id });
}
2017-08-03 18:23:43 +00:00
2017-08-05 18:16:32 +00:00
renderItem = ({ item }) => (
<RoomItem
id={item._id}
onPressItem={this._onPressItem}
title={item.name}
/>
);
renderSeparator = () => (
<View style={styles.separator} />
);
2017-08-03 18:23:43 +00:00
render() {
return (
<View style={styles.container}>
<FlatList
style={styles.list}
data={this.state.dataSource}
renderItem={this.renderItem}
keyExtractor={item => item._id}
ItemSeparatorComponent={this.renderSeparator}
/>
</View>
);
}
}