diff --git a/app/login.js b/app/login.js index df8f71cd8..9735c05f6 100644 --- a/app/login.js +++ b/app/login.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { View, TextInput, StyleSheet, KeyboardAvoidingView } from 'react-native'; +import { View, TextInput, StyleSheet, KeyboardAvoidingView, Platform } from 'react-native'; import realm from './realm'; import { loginWithPassword, loadSubscriptions, Accounts } from './meteor'; @@ -56,7 +56,7 @@ export default class LoginView extends React.Component { render() { return ( - + this.setState({ username })} diff --git a/app/room.js b/app/room.js index d1f4c3bdb..fac263aba 100644 --- a/app/room.js +++ b/app/room.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { View, KeyboardAvoidingView, Text, TextInput, FlatList, StyleSheet, Image } from 'react-native'; +import { View, KeyboardAvoidingView, Text, TextInput, FlatList, StyleSheet, Image, Platform } from 'react-native'; // import Markdown from 'react-native-simple-markdown'; import realm from './realm'; import { loadMessagesForRoom, sendMessage } from './meteor'; @@ -67,7 +67,7 @@ class RoomItem extends React.PureComponent { return ( - + {this.props.item.u.username} @@ -98,21 +98,26 @@ export default class RoomView extends React.Component { this.rid = realm.objectForPrimaryKey('subscriptions', props.navigation.state.params.sid).rid; // this.rid = 'GENERAL'; - this.state = this.getState(); + this.state = { + text: '', + dataSource: this.getMessages() + }; - loadMessagesForRoom(this.rid); - - this.state = this.getState(); + this.url = realm.objectForPrimaryKey('settings', 'Site_Url').value; } - getState = () => ({ - ...this.state, - dataSource: realm.objects('messages').filtered('rid = $0', this.rid).sorted('ts', true) - }); + getMessages = () => { + return realm.objects('messages').filtered('rid = $0', this.rid).sorted('ts', true); + } - updateState = () => (this.setState(this.getState())) + updateState = () => { + this.setState({ + dataSource: this.getMessages() + }); + }; - componentDidMount() { + componentWillMount() { + loadMessagesForRoom(this.rid); realm.addListener('change', this.updateState); } @@ -124,6 +129,7 @@ export default class RoomView extends React.Component { ); @@ -147,7 +153,7 @@ export default class RoomView extends React.Component { render() { return ( - + this.listView = ref} style={styles.list} diff --git a/app/rooms.js b/app/rooms.js index 18a85238c..937060176 100644 --- a/app/rooms.js +++ b/app/rooms.js @@ -48,14 +48,13 @@ export default class RoomsView extends React.Component { constructor(props) { super(props); - const getState = () => ({ - selected: new Map(), + this.state = { dataSource: realm.objects('subscriptions').sorted('name') - }); + }; + } + componentWillMount() { realm.addListener('change', () => this.setState(getState())); - - this.state = getState(); } _onPressItem = (id) => { diff --git a/app/servers/new.js b/app/servers/new.js index de72bcda8..76dcdaf40 100644 --- a/app/servers/new.js +++ b/app/servers/new.js @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import Zeroconf from 'react-native-zeroconf'; -import { View, Text, TextInput, Button, StyleSheet, KeyboardAvoidingView } from 'react-native'; +import { View, Text, TextInput, Button, StyleSheet, KeyboardAvoidingView, Platform } from 'react-native'; import { NavigationActions } from 'react-navigation' import realm from '../realm'; @@ -76,7 +76,7 @@ export default class NewServerView extends React.Component { render() { return ( - + this.setState({ text })}