Skip to content
Snippets Groups Projects
Unverified Commit 5b7efc4a authored by Diego Sampaio's avatar Diego Sampaio
Browse files

Proper fix for keyboard

parent 61306131
No related branches found
No related tags found
No related merge requests found
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 (
<KeyboardAvoidingView style={styles.view}>
<KeyboardAvoidingView style={styles.view} behavior={Platform.OS === 'ios' && 'padding'}>
<TextInput
style={styles.input}
onChangeText={username => this.setState({ username })}
......
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 (
<View style={[styles.roomItem, extraStyle]}>
<Image style={styles.avatar} source={{ uri: `http://localhost:3000/avatar/${ this.props.item.u.username }` }} />
<Image style={styles.avatar} source={{ uri: `${ this.props.baseUrl }/avatar/${ this.props.item.u.username }` }} />
<View style={styles.texts}>
<Text onPress={this._onPress} style={styles.username}>
{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 {
<RoomItem
id={item._id}
item={item}
baseUrl={this.url}
/>
);
......@@ -147,7 +153,7 @@ export default class RoomView extends React.Component {
render() {
return (
<KeyboardAvoidingView style={styles.container}>
<KeyboardAvoidingView style={styles.container} behavior={Platform.OS === 'ios' && 'padding'} keyboardVerticalOffset={64}>
<FlatList
ref={ref => this.listView = ref}
style={styles.list}
......
......@@ -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) => {
......
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 (
<KeyboardAvoidingView style={styles.view} behavior='padding'>
<KeyboardAvoidingView style={styles.view} behavior={Platform.OS === 'ios' && 'padding'}>
<TextInput
style={styles.input}
onChangeText={text => this.setState({ text })}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment