Message button (#660)

* Remove touchable opacity when scrolling messages
* Tap on disable messages closes keyboard
* Unify vibration
* Vibrate only on Android
This commit is contained in:
Diego Mello 2019-02-27 11:47:15 -03:00 committed by GitHub
parent f3ddf60a57
commit 8c1b57eb26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 11890 additions and 131 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,6 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { import { Alert, Clipboard, Share } from 'react-native';
Alert, Clipboard, Vibration, Share
} from 'react-native';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import ActionSheet from 'react-native-action-sheet'; import ActionSheet from 'react-native-action-sheet';
import * as moment from 'moment'; import * as moment from 'moment';
@ -17,6 +15,7 @@ import {
toggleStarRequest as toggleStarRequestAction toggleStarRequest as toggleStarRequestAction
} from '../actions/messages'; } from '../actions/messages';
import { showToast } from '../utils/info'; import { showToast } from '../utils/info';
import { vibrate } from '../utils/vibration';
import RocketChat from '../lib/rocketchat'; import RocketChat from '../lib/rocketchat';
import I18n from '../i18n'; import I18n from '../i18n';
@ -126,7 +125,7 @@ export default class MessageActions extends React.Component {
} }
setTimeout(() => { setTimeout(() => {
this.showActionSheet(); this.showActionSheet();
Vibration.vibrate(50); vibrate();
}); });
} }

View File

@ -1,7 +1,7 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { import {
View, Text, ViewPropTypes, Image as ImageRN View, Text, ViewPropTypes, Image as ImageRN, TouchableWithoutFeedback
} from 'react-native'; } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialIcons'; import Icon from 'react-native-vector-icons/MaterialIcons';
import moment from 'moment'; import moment from 'moment';
@ -199,7 +199,7 @@ export default class Message extends PureComponent {
if (header) { if (header) {
return ( return (
<User <User
onPress={this._onPress} onPress={this.onPress}
timeFormat={timeFormat} timeFormat={timeFormat}
username={(useRealName && author.name) || author.username} username={(useRealName && author.name) || author.username}
alias={alias} alias={alias}
@ -348,59 +348,53 @@ export default class Message extends PureComponent {
editing, style, header, archived, onLongPress, reactionsModal, closeReactions, msg, ts, reactions, author, user, timeFormat, customEmojis, baseUrl editing, style, header, archived, onLongPress, reactionsModal, closeReactions, msg, ts, reactions, author, user, timeFormat, customEmojis, baseUrl
} = this.props; } = this.props;
const accessibilityLabel = I18n.t('Message_accessibility', { user: author.username, time: moment(ts).format(timeFormat), message: msg }); const accessibilityLabel = I18n.t('Message_accessibility', { user: author.username, time: moment(ts).format(timeFormat), message: msg });
const disabled = this.isInfoMessage() || this.hasError() || archived;
return ( return (
<View style={styles.root}> <View style={styles.root}>
{this.renderError()} {this.renderError()}
<LongPressGestureHandler <TouchableWithoutFeedback
onHandlerStateChange={({ nativeEvent }) => nativeEvent.state === State.ACTIVE && onLongPress()} onLongPress={!disabled && onLongPress}
onPress={this.onPress}
> >
<RectButton <View
enabled={!(this.isInfoMessage() || this.hasError() || archived)} style={[styles.container, header && styles.marginBottom, editing && styles.editing, style]}
style={[styles.container, header && styles.marginBottom]} accessibilityLabel={accessibilityLabel}
onPress={this.onPress}
activeOpacity={0.8}
underlayColor='#e1e5e8'
> >
<View <View style={styles.flex}>
style={[styles.message, editing && styles.editing, style]} {this.renderAvatar()}
accessibilityLabel={accessibilityLabel} <View
> style={[
<View style={styles.flex}> styles.messageContent,
{this.renderAvatar()} header && styles.messageContentWithHeader,
<View this.hasError() && header && styles.messageContentWithHeader,
style={[ this.hasError() && !header && styles.messageContentWithError,
styles.messageContent, this.isTemp() && styles.temp
header && styles.messageContentWithHeader, ]}
this.hasError() && header && styles.messageContentWithHeader, >
this.hasError() && !header && styles.messageContentWithError, {this.renderUsername()}
this.isTemp() && styles.temp {this.renderContent()}
]} {this.renderAttachment()}
> {this.renderUrl()}
{this.renderUsername()} {this.renderReactions()}
{this.renderContent()} {this.renderBroadcastReply()}
{this.renderAttachment()}
{this.renderUrl()}
{this.renderReactions()}
{this.renderBroadcastReply()}
</View>
</View> </View>
{reactionsModal
? (
<ReactionsModal
isVisible={reactionsModal}
reactions={reactions}
user={user}
customEmojis={customEmojis}
baseUrl={baseUrl}
close={closeReactions}
/>
)
: null
}
</View> </View>
</RectButton> {reactionsModal
</LongPressGestureHandler> ? (
<ReactionsModal
isVisible={reactionsModal}
reactions={reactions}
user={user}
customEmojis={customEmojis}
baseUrl={baseUrl}
close={closeReactions}
/>
)
: null
}
</View>
</TouchableWithoutFeedback>
</View> </View>
); );
} }

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 { Vibration, ViewPropTypes } from 'react-native'; import { ViewPropTypes } from 'react-native';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import equal from 'deep-equal'; import equal from 'deep-equal';
@ -10,6 +10,7 @@ import {
toggleReactionPicker as toggleReactionPickerAction, toggleReactionPicker as toggleReactionPickerAction,
replyBroadcast as replyBroadcastAction replyBroadcast as replyBroadcastAction
} from '../../actions/messages'; } from '../../actions/messages';
import { vibrate } from '../../utils/vibration';
@connect(state => ({ @connect(state => ({
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', baseUrl: state.settings.Site_Url || state.server ? state.server.server : '',
@ -119,7 +120,7 @@ export default class MessageContainer extends React.Component {
onReactionLongPress = () => { onReactionLongPress = () => {
this.setState({ reactionsModal: true }); this.setState({ reactionsModal: true });
Vibration.vibrate(50); vibrate();
} }
get timeFormat() { get timeFormat() {

View File

@ -6,8 +6,12 @@ export default StyleSheet.create({
}, },
container: { container: {
paddingVertical: 5, paddingVertical: 5,
flexDirection: 'row', width: '100%',
width: '100%' paddingLeft: 10,
paddingRight: 15,
flexDirection: 'column',
transform: [{ scaleY: -1 }],
flex: 1
}, },
messageContent: { messageContent: {
flex: 1, flex: 1,
@ -23,13 +27,6 @@ export default StyleSheet.create({
flexDirection: 'row', flexDirection: 'row',
flex: 1 flex: 1
}, },
message: {
paddingLeft: 10,
paddingRight: 15,
flexDirection: 'column',
transform: [{ scaleY: -1 }],
flex: 1
},
textInfo: { textInfo: {
fontStyle: 'italic', fontStyle: 'italic',
color: '#a0a0a0', color: '#a0a0a0',

11
app/utils/vibration.js Normal file
View File

@ -0,0 +1,11 @@
import { Vibration } from 'react-native';
import { isAndroid } from './deviceInfo';
const vibrate = () => {
if (isAndroid) {
Vibration.vibrate(30);
}
};
export { vibrate };

View File

@ -1,8 +1,6 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { import { FlatList, View } from 'react-native';
FlatList, View, Vibration
} from 'react-native';
import ActionSheet from 'react-native-action-sheet'; import ActionSheet from 'react-native-action-sheet';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import SafeAreaView from 'react-native-safe-area-view'; import SafeAreaView from 'react-native-safe-area-view';
@ -18,6 +16,7 @@ import database from '../../lib/realm';
import { showToast } from '../../utils/info'; import { showToast } from '../../utils/info';
import log from '../../utils/log'; import log from '../../utils/log';
import { isAndroid } from '../../utils/deviceInfo'; import { isAndroid } from '../../utils/deviceInfo';
import { vibrate } from '../../utils/vibration';
import I18n from '../../i18n'; import I18n from '../../i18n';
import SearchBox from '../../containers/SearchBox'; import SearchBox from '../../containers/SearchBox';
import protectedFunction from '../../lib/methods/helpers/protectedFunction'; import protectedFunction from '../../lib/methods/helpers/protectedFunction';
@ -184,7 +183,7 @@ export default class RoomMembersView extends LoggedView {
this.actionSheetOptions.push(I18n.t('Mute')); this.actionSheetOptions.push(I18n.t('Mute'));
} }
this.setState({ userLongPressed: user }); this.setState({ userLongPressed: user });
Vibration.vibrate(50); vibrate();
this.showActionSheet(); this.showActionSheet();
} }