Proper fix for keyboard

This commit is contained in:
Diego Sampaio 2017-08-07 15:42:02 -03:00
parent 613061312f
commit 5b7efc4a08
No known key found for this signature in database
GPG Key ID: E060152B30502562
4 changed files with 27 additions and 22 deletions

View File

@ -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 (
<KeyboardAvoidingView style={styles.view}>
<KeyboardAvoidingView style={styles.view} behavior={Platform.OS === 'ios' && 'padding'}>
<TextInput
style={styles.input}
onChangeText={username => this.setState({ username })}

View File

@ -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 (
<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({
dataSource: this.getMessages()
});
};
updateState = () => (this.setState(this.getState()))
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}

View File

@ -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) => {

View File

@ -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 (
<KeyboardAvoidingView style={styles.view} behavior='padding'>
<KeyboardAvoidingView style={styles.view} behavior={Platform.OS === 'ios' && 'padding'}>
<TextInput
style={styles.input}
onChangeText={text => this.setState({ text })}