Message box issues (#218)

This commit is contained in:
Diego Mello 2018-01-25 12:04:20 -02:00 committed by Guilherme Gazzo
parent bf6b919cb3
commit 037caf5e17
6 changed files with 25 additions and 34 deletions

View File

@ -15,7 +15,6 @@
android:name="${applicationId}.permission.C2D_MESSAGE" android:name="${applicationId}.permission.C2D_MESSAGE"
android:protectionLevel="signature" /> android:protectionLevel="signature" />
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" /> <uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-sdk <uses-sdk
android:minSdkVersion="16" android:minSdkVersion="16"

View File

@ -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, SafeAreaView, Platform, FlatList, Text, TouchableOpacity, Keyboard } from 'react-native'; import { View, TextInput, SafeAreaView, FlatList, Text, TouchableOpacity, Keyboard } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialIcons'; import Icon from 'react-native-vector-icons/MaterialIcons';
import ImagePicker from 'react-native-image-picker'; import ImagePicker from 'react-native-image-picker';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
@ -50,7 +50,6 @@ export default class MessageBox extends React.PureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
height: 20,
messageboxHeight: 0, messageboxHeight: 0,
text: '', text: '',
mentions: [], mentions: [],
@ -71,17 +70,19 @@ export default class MessageBox extends React.PureComponent {
} }
} }
onChange() { onChangeText(text) {
this.setState({ text });
requestAnimationFrame(() => { requestAnimationFrame(() => {
const { start, end } = this.component._lastNativeSelection; const { start, end } = this.component._lastNativeSelection;
const cursor = Math.max(start, end); const cursor = Math.max(start, end);
const text = this.component._lastNativeText; const lastNativeText = this.component._lastNativeText;
const regexp = /(#|@)([a-z._-]+)$/im; const regexp = /(#|@)([a-z._-]+)$/im;
const result = text.substr(0, cursor).match(regexp); const result = lastNativeText.substr(0, cursor).match(regexp);
if (!result) { if (!result) {
return this.stopTrackingMention(); return this.stopTrackingMention();
@ -92,11 +93,6 @@ export default class MessageBox extends React.PureComponent {
}); });
} }
onChangeText(text) {
this.setState({ text });
}
get leftButtons() { get leftButtons() {
const { editing } = this.props; const { editing } = this.props;
if (editing) { if (editing) {
@ -147,10 +143,6 @@ export default class MessageBox extends React.PureComponent {
return icons; return icons;
} }
updateSize = (height) => {
this.setState({ height: height + (Platform.OS === 'ios' ? 0 : 0) });
}
addFile = () => { addFile = () => {
const options = { const options = {
maxHeight: 1960, maxHeight: 1960,
@ -407,7 +399,6 @@ export default class MessageBox extends React.PureComponent {
return <AnimatedContainer visible={showMentionsContainer} subview={usersList} messageboxHeight={messageboxHeight} />; return <AnimatedContainer visible={showMentionsContainer} subview={usersList} messageboxHeight={messageboxHeight} />;
} }
render() { render() {
const { height } = this.state;
return ( return (
<View> <View>
<SafeAreaView <SafeAreaView
@ -418,18 +409,16 @@ export default class MessageBox extends React.PureComponent {
{this.leftButtons} {this.leftButtons}
<TextInput <TextInput
ref={component => this.component = component} ref={component => this.component = component}
style={[styles.textBoxInput, { height }]} style={styles.textBoxInput}
returnKeyType='default' returnKeyType='default'
blurOnSubmit={false} blurOnSubmit={false}
placeholder='New Message' placeholder='New Message'
onChangeText={text => this.onChangeText(text)} onChangeText={text => this.onChangeText(text)}
onChange={event => this.onChange(event)}
value={this.state.text} value={this.state.text}
underlineColorAndroid='transparent' underlineColorAndroid='transparent'
defaultValue='' defaultValue=''
multiline multiline
placeholderTextColor='#9EA2A8' placeholderTextColor='#9EA2A8'
onContentSizeChange={e => this.updateSize(e.nativeEvent.contentSize.height)}
/> />
{this.rightButtons} {this.rightButtons}
</View> </View>

View File

@ -9,8 +9,6 @@ export default StyleSheet.create({
alignItems: 'center', alignItems: 'center',
borderTopWidth: 1, borderTopWidth: 1,
borderTopColor: '#D8D8D8', borderTopColor: '#D8D8D8',
paddingHorizontal: 15,
paddingVertical: 15,
zIndex: 2 zIndex: 2
}, },
safeAreaView: { safeAreaView: {
@ -23,14 +21,13 @@ export default StyleSheet.create({
flexGrow: 0 flexGrow: 0
}, },
textBoxInput: { textBoxInput: {
paddingVertical: 0, paddingHorizontal: 5,
paddingHorizontal: 10, textAlignVertical: 'center',
textAlignVertical: 'top',
maxHeight: 120, maxHeight: 120,
flexGrow: 1, flexGrow: 1,
width: 1, width: 1,
paddingTop: 0, paddingTop: 15,
paddingBottom: 0 paddingBottom: 15
}, },
editing: { editing: {
backgroundColor: '#fff5df' backgroundColor: '#fff5df'
@ -39,7 +36,7 @@ export default StyleSheet.create({
color: '#2F343D', color: '#2F343D',
fontSize: 20, fontSize: 20,
textAlign: 'center', textAlign: 'center',
paddingHorizontal: 5, padding: 15,
flex: 0 flex: 0
}, },
actionRow: { actionRow: {

View File

@ -1,9 +1,10 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Text, View, Button, SafeAreaView } from 'react-native'; import { Text, View, Button, SafeAreaView, Platform } from 'react-native';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import equal from 'deep-equal'; import equal from 'deep-equal';
import KeyboardSpacer from 'react-native-keyboard-spacer';
import { ListView } from './ListView'; import { ListView } from './ListView';
import * as actions from '../../actions'; import * as actions from '../../actions';
@ -16,14 +17,12 @@ import MessageActions from '../../containers/MessageActions';
import MessageErrorActions from '../../containers/MessageErrorActions'; import MessageErrorActions from '../../containers/MessageErrorActions';
import MessageBox from '../../containers/MessageBox'; import MessageBox from '../../containers/MessageBox';
import Typing from '../../containers/Typing'; import Typing from '../../containers/Typing';
import KeyboardView from '../../presentation/KeyboardView';
import Header from '../../containers/Header'; import Header from '../../containers/Header';
import RoomsHeader from './Header'; import RoomsHeader from './Header';
import Banner from './banner'; import Banner from './banner';
import styles from './styles'; import styles from './styles';
import debounce from '../../utils/debounce'; import debounce from '../../utils/debounce';
import scrollPersistTaps from '../../utils/scrollPersistTaps';
const ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1._id !== r2._id }); const ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1._id !== r2._id });
@ -196,8 +195,7 @@ export default class RoomView extends React.Component {
} }
render() { render() {
return ( return (
<KeyboardView contentContainerStyle={styles.container} keyboardVerticalOffset={64}> <View style={styles.container}>
<Banner /> <Banner />
<SafeAreaView style={styles.safeAreaView}> <SafeAreaView style={styles.safeAreaView}>
<ListView <ListView
@ -210,13 +208,15 @@ export default class RoomView extends React.Component {
dataSource={this.state.dataSource} dataSource={this.state.dataSource}
renderRow={item => this.renderItem(item)} renderRow={item => this.renderItem(item)}
initialListSize={10} initialListSize={10}
{...scrollPersistTaps} keyboardShouldPersistTaps='always'
keyboardDismissMode='on-drag'
/> />
</SafeAreaView> </SafeAreaView>
{this.renderFooter()} {this.renderFooter()}
<MessageActions room={this.room} /> <MessageActions room={this.room} />
<MessageErrorActions /> <MessageErrorActions />
</KeyboardView> {Platform.OS === 'ios' ? <KeyboardSpacer /> : null}
</View>
); );
} }
} }

5
package-lock.json generated
View File

@ -12542,6 +12542,11 @@
"react-native-iphone-x-helper": "1.0.1" "react-native-iphone-x-helper": "1.0.1"
} }
}, },
"react-native-keyboard-spacer": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/react-native-keyboard-spacer/-/react-native-keyboard-spacer-0.4.1.tgz",
"integrity": "sha1-RvGKMgQyCYol6p+on1FD3SVNMy0="
},
"react-native-loading-spinner-overlay": { "react-native-loading-spinner-overlay": {
"version": "0.5.2", "version": "0.5.2",
"resolved": "https://registry.npmjs.org/react-native-loading-spinner-overlay/-/react-native-loading-spinner-overlay-0.5.2.tgz", "resolved": "https://registry.npmjs.org/react-native-loading-spinner-overlay/-/react-native-loading-spinner-overlay-0.5.2.tgz",

View File

@ -45,6 +45,7 @@
"react-native-image-picker": "^0.26.7", "react-native-image-picker": "^0.26.7",
"react-native-img-cache": "^1.5.2", "react-native-img-cache": "^1.5.2",
"react-native-keyboard-aware-scroll-view": "^0.4.1", "react-native-keyboard-aware-scroll-view": "^0.4.1",
"react-native-keyboard-spacer": "^0.4.1",
"react-native-loading-spinner-overlay": "^0.5.2", "react-native-loading-spinner-overlay": "^0.5.2",
"react-native-meteor": "^1.2.0", "react-native-meteor": "^1.2.0",
"react-native-modal": "^4.1.1", "react-native-modal": "^4.1.1",