Merge remote-tracking branch 'origin/develop' into reload-when-returns
This commit is contained in:
commit
4f9638b151
|
@ -30,22 +30,9 @@ export default class Banner extends React.PureComponent {
|
||||||
authenticating: PropTypes.bool,
|
authenticating: PropTypes.bool,
|
||||||
offline: PropTypes.bool
|
offline: PropTypes.bool
|
||||||
}
|
}
|
||||||
componentWillMount() {
|
|
||||||
this.setState({
|
|
||||||
slow: false
|
|
||||||
});
|
|
||||||
this.timer = setTimeout(() => this.setState({ slow: true }), 5000);
|
|
||||||
}
|
|
||||||
componentWillUnmount() {
|
|
||||||
clearTimeout(this.timer);
|
|
||||||
}
|
|
||||||
render() {
|
render() {
|
||||||
const { connecting, authenticating, offline } = this.props;
|
const { connecting, authenticating, offline } = this.props;
|
||||||
|
|
||||||
if (!this.state.slow) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (offline) {
|
if (offline) {
|
||||||
return (
|
return (
|
||||||
<View style={[styles.bannerContainer, { backgroundColor: 'red' }]}>
|
<View style={[styles.bannerContainer, { backgroundColor: 'red' }]}>
|
||||||
|
|
|
@ -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, SafeAreaView } from 'react-native';
|
import { View, TextInput, StyleSheet, SafeAreaView, Platform } 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';
|
||||||
|
@ -22,14 +22,19 @@ const styles = StyleSheet.create({
|
||||||
},
|
},
|
||||||
textBoxInput: {
|
textBoxInput: {
|
||||||
height: 40,
|
height: 40,
|
||||||
alignSelf: 'stretch',
|
minHeight: 40,
|
||||||
flexGrow: 1
|
maxHeight: 120,
|
||||||
|
flexGrow: 1,
|
||||||
|
paddingHorizontal: 10,
|
||||||
|
paddingTop: 12
|
||||||
},
|
},
|
||||||
actionButtons: {
|
actionButtons: {
|
||||||
color: '#aaa',
|
color: '#aaa',
|
||||||
paddingTop: 10,
|
paddingTop: 10,
|
||||||
paddingBottom: 10,
|
paddingBottom: 10,
|
||||||
fontSize: 20
|
paddingHorizontal: 8,
|
||||||
|
fontSize: 20,
|
||||||
|
alignSelf: 'flex-end'
|
||||||
},
|
},
|
||||||
editing: {
|
editing: {
|
||||||
backgroundColor: '#fff5df'
|
backgroundColor: '#fff5df'
|
||||||
|
@ -57,6 +62,13 @@ export default class MessageBox extends React.Component {
|
||||||
clearInput: PropTypes.func
|
clearInput: PropTypes.func
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
height: 40
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
if (this.props.message !== nextProps.message && nextProps.message) {
|
if (this.props.message !== nextProps.message && nextProps.message) {
|
||||||
this.component.setNativeProps({ text: nextProps.message.msg });
|
this.component.setNativeProps({ text: nextProps.message.msg });
|
||||||
|
@ -111,6 +123,10 @@ export default class MessageBox extends React.Component {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateSize = (height) => {
|
||||||
|
this.setState({ height: height + (Platform.OS === 'ios' ? 20 : 0) });
|
||||||
|
}
|
||||||
|
|
||||||
editCancel() {
|
editCancel() {
|
||||||
this.props.editCancel();
|
this.props.editCancel();
|
||||||
this.component.setNativeProps({ text: '' });
|
this.component.setNativeProps({ text: '' });
|
||||||
|
@ -125,20 +141,27 @@ export default class MessageBox extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { height } = this.state;
|
||||||
return (
|
return (
|
||||||
<View style={[styles.textBox, (this.props.editing ? styles.editing : null)]}>
|
<View style={[styles.textBox, (this.props.editing ? styles.editing : null)]}>
|
||||||
<SafeAreaView style={styles.safeAreaView}>
|
<SafeAreaView style={styles.safeAreaView}>
|
||||||
{this.renderLeftButton()}
|
{this.renderLeftButton()}
|
||||||
<TextInput
|
<TextInput
|
||||||
ref={component => this.component = component}
|
ref={component => this.component = component}
|
||||||
style={styles.textBoxInput}
|
style={[styles.textBoxInput, { height }]}
|
||||||
returnKeyType='send'
|
returnKeyType='default'
|
||||||
onSubmitEditing={event => this.submit(event.nativeEvent.text)}
|
|
||||||
blurOnSubmit={false}
|
blurOnSubmit={false}
|
||||||
placeholder='New message'
|
placeholder='New message'
|
||||||
onChangeText={text => this.props.typing(text.length > 0)}
|
onChangeText={text => this.props.typing(text.length > 0)}
|
||||||
underlineColorAndroid='transparent'
|
underlineColorAndroid='transparent'
|
||||||
defaultValue=''
|
defaultValue=''
|
||||||
|
multiline
|
||||||
|
onContentSizeChange={e => this.updateSize(e.nativeEvent.contentSize.height)}
|
||||||
|
/>
|
||||||
|
<Icon
|
||||||
|
style={styles.actionButtons}
|
||||||
|
name='send'
|
||||||
|
onPress={() => this.submit(this.component._lastNativeText)}
|
||||||
/>
|
/>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
</View>
|
</View>
|
||||||
|
|
|
@ -28,7 +28,7 @@ const AuthRoutes = StackNavigator(
|
||||||
screen: RoomView,
|
screen: RoomView,
|
||||||
navigationOptions({ navigation }) {
|
navigationOptions({ navigation }) {
|
||||||
return {
|
return {
|
||||||
title: navigation.state.params.title || 'Room'
|
title: navigation.state.params.name || navigation.state.params.room.name || 'Room'
|
||||||
// [drawerIconPosition]: (<DrawerMenuButton navigation={navigation} />)÷
|
// [drawerIconPosition]: (<DrawerMenuButton navigation={navigation} />)÷
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,3 +21,23 @@ export function goBack() {
|
||||||
config.navigator.dispatch(action);
|
config.navigator.dispatch(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function goRoom({ rid, name }, counter = 0) {
|
||||||
|
// about counter: we can call this method before navigator be set. so we have to wait, if we tried a lot, we give up ...
|
||||||
|
if (!rid || !name || counter > 10) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!config.navigator) {
|
||||||
|
return setTimeout(() => goRoom({ rid, name }, counter + 1), 200);
|
||||||
|
}
|
||||||
|
const action = NavigationActions.reset({
|
||||||
|
index: 1,
|
||||||
|
actions: [
|
||||||
|
NavigationActions.navigate({ routeName: 'RoomsList' }),
|
||||||
|
NavigationActions.navigate({ routeName: 'Room', params: { room: { rid, name }, rid, name } })
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
return config.navigator.dispatch(action);
|
||||||
|
}
|
||||||
|
|
15
app/push.js
15
app/push.js
|
@ -1,6 +1,15 @@
|
||||||
import PushNotification from 'react-native-push-notification';
|
import PushNotification from 'react-native-push-notification';
|
||||||
import { AsyncStorage } from 'react-native';
|
import { AsyncStorage } from 'react-native';
|
||||||
|
import EJSON from 'ejson';
|
||||||
|
import { goRoom } from './containers/routes/NavigationService';
|
||||||
|
|
||||||
|
const handleNotification = (notification) => {
|
||||||
|
if (notification.usernInteraction) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { rid, name } = EJSON.parse(notification.ejson);
|
||||||
|
return rid && name && goRoom({ rid, name });
|
||||||
|
};
|
||||||
PushNotification.configure({
|
PushNotification.configure({
|
||||||
|
|
||||||
// (optional) Called when Token is generated (iOS and Android)
|
// (optional) Called when Token is generated (iOS and Android)
|
||||||
|
@ -9,9 +18,7 @@ PushNotification.configure({
|
||||||
},
|
},
|
||||||
|
|
||||||
// (required) Called when a remote or local notification is opened or received
|
// (required) Called when a remote or local notification is opened or received
|
||||||
onNotification(notification) {
|
onNotification: handleNotification,
|
||||||
console.log('NOTIFICATION:', notification);
|
|
||||||
},
|
|
||||||
|
|
||||||
// ANDROID ONLY: GCM Sender ID (optional - not required for local notifications, but is need to receive remote push notifications)
|
// ANDROID ONLY: GCM Sender ID (optional - not required for local notifications, but is need to receive remote push notifications)
|
||||||
senderID: '673693445664',
|
senderID: '673693445664',
|
||||||
|
@ -25,7 +32,7 @@ PushNotification.configure({
|
||||||
|
|
||||||
// Should the initial notification be popped automatically
|
// Should the initial notification be popped automatically
|
||||||
// default: true
|
// default: true
|
||||||
popInitialNotification: false,
|
popInitialNotification: true,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (optional) default: true
|
* (optional) default: true
|
||||||
|
|
|
@ -22,5 +22,5 @@ const root = function* root() {
|
||||||
state()
|
state()
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
// Consider using takeEvery
|
|
||||||
export default root;
|
export default root;
|
||||||
|
|
|
@ -70,7 +70,6 @@ export default class RoomView extends React.Component {
|
||||||
editCancel: PropTypes.func,
|
editCancel: PropTypes.func,
|
||||||
rid: PropTypes.string,
|
rid: PropTypes.string,
|
||||||
server: PropTypes.string,
|
server: PropTypes.string,
|
||||||
sid: PropTypes.string,
|
|
||||||
name: PropTypes.string,
|
name: PropTypes.string,
|
||||||
Site_Url: PropTypes.string,
|
Site_Url: PropTypes.string,
|
||||||
Message_TimeFormat: PropTypes.string,
|
Message_TimeFormat: PropTypes.string,
|
||||||
|
@ -79,12 +78,9 @@ export default class RoomView extends React.Component {
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.sid = props.navigation.state.params.room.sid;
|
|
||||||
this.rid =
|
this.rid =
|
||||||
props.rid ||
|
props.rid ||
|
||||||
props.navigation.state.params.room.rid ||
|
props.navigation.state.params.room.rid;
|
||||||
realm.objectForPrimaryKey('subscriptions', this.sid).rid;
|
|
||||||
|
|
||||||
this.data = realm
|
this.data = realm
|
||||||
.objects('messages')
|
.objects('messages')
|
||||||
|
@ -92,7 +88,6 @@ export default class RoomView extends React.Component {
|
||||||
.sorted('ts', true);
|
.sorted('ts', true);
|
||||||
this.room = realm.objects('subscriptions').filtered('rid = $0', this.rid);
|
this.room = realm.objects('subscriptions').filtered('rid = $0', this.rid);
|
||||||
this.state = {
|
this.state = {
|
||||||
slow: false,
|
|
||||||
dataSource: ds.cloneWithRows([]),
|
dataSource: ds.cloneWithRows([]),
|
||||||
loaded: true,
|
loaded: true,
|
||||||
joined: typeof props.rid === 'undefined'
|
joined: typeof props.rid === 'undefined'
|
||||||
|
@ -103,19 +98,15 @@ export default class RoomView extends React.Component {
|
||||||
this.props.navigation.setParams({
|
this.props.navigation.setParams({
|
||||||
title:
|
title:
|
||||||
this.props.name ||
|
this.props.name ||
|
||||||
this.props.navigation.state.params.room.name ||
|
this.props.navigation.state.params.name ||
|
||||||
realm.objectForPrimaryKey('subscriptions', this.sid).name
|
this.props.navigation.state.params.room.name
|
||||||
});
|
});
|
||||||
this.timer = setTimeout(() => this.setState({ slow: true }), 5000);
|
|
||||||
this.props.openRoom({ rid: this.rid });
|
this.props.openRoom({ rid: this.rid });
|
||||||
this.data.addListener(this.updateState);
|
this.data.addListener(this.updateState);
|
||||||
}
|
}
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.updateState();
|
this.updateState();
|
||||||
}
|
}
|
||||||
componentDidUpdate() {
|
|
||||||
return !this.props.loading && clearTimeout(this.timer);
|
|
||||||
}
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
clearTimeout(this.timer);
|
clearTimeout(this.timer);
|
||||||
this.data.removeAllListeners();
|
this.data.removeAllListeners();
|
||||||
|
@ -160,7 +151,7 @@ export default class RoomView extends React.Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
renderBanner = () =>
|
renderBanner = () =>
|
||||||
(this.state.slow && this.props.loading ? (
|
(this.props.loading ? (
|
||||||
<View style={styles.bannerContainer}>
|
<View style={styles.bannerContainer}>
|
||||||
<Text style={styles.bannerText}>Loading new messages...</Text>
|
<Text style={styles.bannerText}>Loading new messages...</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
|
@ -11,6 +11,7 @@ import realm from '../lib/realm';
|
||||||
import RocketChat from '../lib/rocketchat';
|
import RocketChat from '../lib/rocketchat';
|
||||||
import RoomItem from '../presentation/RoomItem';
|
import RoomItem from '../presentation/RoomItem';
|
||||||
import Banner from '../containers/Banner';
|
import Banner from '../containers/Banner';
|
||||||
|
import { goRoom } from '../containers/routes/NavigationService';
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {
|
||||||
|
@ -191,11 +192,7 @@ export default class RoomsListView extends React.Component {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
_onPressItem = (id, item = {}) => {
|
_onPressItem = (item = {}) => {
|
||||||
const navigateToRoom = (room) => {
|
|
||||||
this.props.navigation.navigate('Room', { room, title: room.name });
|
|
||||||
};
|
|
||||||
|
|
||||||
const clearSearch = () => {
|
const clearSearch = () => {
|
||||||
this.setState({
|
this.setState({
|
||||||
searchText: ''
|
searchText: ''
|
||||||
|
@ -220,16 +217,16 @@ export default class RoomsListView extends React.Component {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}))
|
}))
|
||||||
.then(sub => navigateToRoom({ sid: sub._id, name: sub.name }))
|
.then(sub => goRoom({ room: sub, name: sub.name }))
|
||||||
.then(() => clearSearch());
|
.then(() => clearSearch());
|
||||||
} else {
|
} else {
|
||||||
clearSearch();
|
clearSearch();
|
||||||
navigateToRoom({ rid: item._id, name: item.name });
|
goRoom(item);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
navigateToRoom({ sid: id, name: item.name });
|
goRoom(item);
|
||||||
clearSearch();
|
clearSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,7 +261,7 @@ export default class RoomsListView extends React.Component {
|
||||||
type={item.t}
|
type={item.t}
|
||||||
baseUrl={this.props.Site_Url}
|
baseUrl={this.props.Site_Url}
|
||||||
dateFormat='MM-DD-YYYY HH:mm:ss'
|
dateFormat='MM-DD-YYYY HH:mm:ss'
|
||||||
onPress={() => this._onPressItem(item._id, item)}
|
onPress={() => this._onPressItem(item)}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
"babel-plugin-transform-decorators-legacy": "^1.3.4",
|
"babel-plugin-transform-decorators-legacy": "^1.3.4",
|
||||||
"babel-plugin-transform-remove-console": "^6.8.5",
|
"babel-plugin-transform-remove-console": "^6.8.5",
|
||||||
"babel-polyfill": "^6.26.0",
|
"babel-polyfill": "^6.26.0",
|
||||||
|
"ejson": "^2.1.2",
|
||||||
"moment": "^2.19.2",
|
"moment": "^2.19.2",
|
||||||
"prop-types": "^15.6.0",
|
"prop-types": "^15.6.0",
|
||||||
"react": "16.1.1",
|
"react": "16.1.1",
|
||||||
|
|
Loading…
Reference in New Issue