Proper fix for keyboard
This commit is contained in:
parent
613061312f
commit
5b7efc4a08
|
@ -1,6 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
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 realm from './realm';
|
||||||
import { loginWithPassword, loadSubscriptions, Accounts } from './meteor';
|
import { loginWithPassword, loadSubscriptions, Accounts } from './meteor';
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ export default class LoginView extends React.Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<KeyboardAvoidingView style={styles.view}>
|
<KeyboardAvoidingView style={styles.view} behavior={Platform.OS === 'ios' && 'padding'}>
|
||||||
<TextInput
|
<TextInput
|
||||||
style={styles.input}
|
style={styles.input}
|
||||||
onChangeText={username => this.setState({ username })}
|
onChangeText={username => this.setState({ username })}
|
||||||
|
|
32
app/room.js
32
app/room.js
|
@ -1,6 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
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 Markdown from 'react-native-simple-markdown';
|
||||||
import realm from './realm';
|
import realm from './realm';
|
||||||
import { loadMessagesForRoom, sendMessage } from './meteor';
|
import { loadMessagesForRoom, sendMessage } from './meteor';
|
||||||
|
@ -67,7 +67,7 @@ class RoomItem extends React.PureComponent {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[styles.roomItem, extraStyle]}>
|
<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}>
|
<View style={styles.texts}>
|
||||||
<Text onPress={this._onPress} style={styles.username}>
|
<Text onPress={this._onPress} style={styles.username}>
|
||||||
{this.props.item.u.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 = realm.objectForPrimaryKey('subscriptions', props.navigation.state.params.sid).rid;
|
||||||
// this.rid = 'GENERAL';
|
// this.rid = 'GENERAL';
|
||||||
|
|
||||||
this.state = this.getState();
|
this.state = {
|
||||||
|
text: '',
|
||||||
|
dataSource: this.getMessages()
|
||||||
|
};
|
||||||
|
|
||||||
loadMessagesForRoom(this.rid);
|
this.url = realm.objectForPrimaryKey('settings', 'Site_Url').value;
|
||||||
|
|
||||||
this.state = this.getState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getState = () => ({
|
getMessages = () => {
|
||||||
...this.state,
|
return realm.objects('messages').filtered('rid = $0', this.rid).sorted('ts', true);
|
||||||
dataSource: 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);
|
realm.addListener('change', this.updateState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,6 +129,7 @@ export default class RoomView extends React.Component {
|
||||||
<RoomItem
|
<RoomItem
|
||||||
id={item._id}
|
id={item._id}
|
||||||
item={item}
|
item={item}
|
||||||
|
baseUrl={this.url}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -147,7 +153,7 @@ export default class RoomView extends React.Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<KeyboardAvoidingView style={styles.container}>
|
<KeyboardAvoidingView style={styles.container} behavior={Platform.OS === 'ios' && 'padding'} keyboardVerticalOffset={64}>
|
||||||
<FlatList
|
<FlatList
|
||||||
ref={ref => this.listView = ref}
|
ref={ref => this.listView = ref}
|
||||||
style={styles.list}
|
style={styles.list}
|
||||||
|
|
|
@ -48,14 +48,13 @@ export default class RoomsView extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
const getState = () => ({
|
this.state = {
|
||||||
selected: new Map(),
|
|
||||||
dataSource: realm.objects('subscriptions').sorted('name')
|
dataSource: realm.objects('subscriptions').sorted('name')
|
||||||
});
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillMount() {
|
||||||
realm.addListener('change', () => this.setState(getState()));
|
realm.addListener('change', () => this.setState(getState()));
|
||||||
|
|
||||||
this.state = getState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_onPressItem = (id) => {
|
_onPressItem = (id) => {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import Zeroconf from 'react-native-zeroconf';
|
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 { NavigationActions } from 'react-navigation'
|
||||||
|
|
||||||
import realm from '../realm';
|
import realm from '../realm';
|
||||||
|
@ -76,7 +76,7 @@ export default class NewServerView extends React.Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<KeyboardAvoidingView style={styles.view} behavior='padding'>
|
<KeyboardAvoidingView style={styles.view} behavior={Platform.OS === 'ios' && 'padding'}>
|
||||||
<TextInput
|
<TextInput
|
||||||
style={styles.input}
|
style={styles.input}
|
||||||
onChangeText={text => this.setState({ text })}
|
onChangeText={text => this.setState({ text })}
|
||||||
|
|
Loading…
Reference in New Issue