[FIX] Prevent mass is typing dispatchs (#651)

This commit is contained in:
Diego Mello 2019-02-25 13:22:48 -03:00 committed by GitHub
parent a1f49d7127
commit bf212bfc4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 6 deletions

View File

@ -216,7 +216,7 @@ dependencies {
implementation 'com.facebook.fresco:animated-gif:1.10.0' implementation 'com.facebook.fresco:animated-gif:1.10.0'
implementation 'com.facebook.fresco:animated-webp:1.10.0' implementation 'com.facebook.fresco:animated-webp:1.10.0'
implementation 'com.facebook.fresco:webpsupport:1.10.0' implementation 'com.facebook.fresco:webpsupport:1.10.0'
implementation 'com.google.android.gms:play-services-gcm:16.0.0' implementation 'com.google.android.gms:play-services-gcm:16.1.0'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.5@aar') { implementation('com.crashlytics.sdk.android:crashlytics:2.9.5@aar') {
transitive = true; transitive = true;
} }

View File

@ -155,10 +155,8 @@ export default class MessageBox extends Component {
} }
onChangeText(text) { onChangeText(text) {
const { typing } = this.props;
this.setInput(text); this.setInput(text);
typing(text.length > 0); this.handleTyping(text.length > 0);
requestAnimationFrame(() => { requestAnimationFrame(() => {
const { start, end } = this.component._lastNativeSelection; const { start, end } = this.component._lastNativeSelection;
@ -420,6 +418,27 @@ export default class MessageBox extends Component {
} }
} }
handleTyping = (isTyping) => {
const { typing } = this.props;
if (!isTyping) {
if (this.typingTimeout) {
clearTimeout(this.typingTimeout);
this.typingTimeout = false;
}
typing(false);
return;
}
if (this.typingTimeout) {
return;
}
this.typingTimeout = setTimeout(() => {
typing(true);
this.typingTimeout = false;
}, 1000);
}
setInput = (text) => { setInput = (text) => {
this.text = text; this.text = text;
this.component.setNativeProps({ text }); this.component.setNativeProps({ text });
@ -516,14 +535,14 @@ export default class MessageBox extends Component {
submit = async() => { submit = async() => {
const { const {
typing, message: editingMessage, editRequest, onSubmit message: editingMessage, editRequest, onSubmit
} = this.props; } = this.props;
const message = this.text; const message = this.text;
this.clearInput(); this.clearInput();
this.closeEmoji(); this.closeEmoji();
this.stopTrackingMention(); this.stopTrackingMention();
typing(false); this.handleTyping(false);
if (message.trim() === '') { if (message.trim() === '') {
return; return;
} }