import React from 'react';
import { View, Text, FlatList, StyleSheet, Image } from 'react-native';
import realm from './realm';
import { loadMessagesForRoom } from './meteor';
import Markdown from 'react-native-simple-markdown';
const styles = StyleSheet.create({
roomItem: {
borderColor: '#aaa',
padding: 14,
flexDirection: 'row'
},
avatar: {
backgroundColor: '#ccc',
width: 40,
height: 40,
marginRight: 10,
borderRadius: 5
},
username: {
fontWeight: 'bold',
marginBottom: 5
},
container: {
flex: 1
},
separator: {
height: 1,
// width: "86%",
backgroundColor: '#CED0CE'
// marginLeft: "14%"
}
});
class RoomItem extends React.PureComponent {
_onPress = () => {
this.props.onPressItem(this.props.id);
};
render() {
return (
{this.props.item.u.username}
{this.props.item.msg}
);
}
}
export class RoomView extends React.Component {
static navigationOptions = ({ navigation }) => ({
title: realm.objectForPrimaryKey('subscriptions', navigation.state.params.sid).name
// title: navigation.state.params.rid
});
_onPressItem(id) {
console.log('pressed', id);
}
renderItem = ({item}) => (
);
constructor(props) {
super(props);
this.rid = realm.objectForPrimaryKey('subscriptions', props.navigation.state.params.sid).rid;
// this.rid = 'GENERAL';
loadMessagesForRoom(this.rid);
const getState = () => {
return {
selected: new Map(),
dataSource: realm.objects('messages').filtered('rid = $0', this.rid)
};
};
realm.addListener('change', () => this.setState(getState()));
this.state = getState();
}
renderSeparator = () => {
return (
);
};
render() {
return (
item._id}
ItemSeparatorComponent={this.renderSeparator}
/>
);
}
}