From bf212bfc4d783217fde968212bd4ca05b2b7af75 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Mon, 25 Feb 2019 13:22:48 -0300 Subject: [PATCH] [FIX] Prevent mass is typing dispatchs (#651) --- android/app/build.gradle | 2 +- app/containers/MessageBox/index.js | 29 ++++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index f66c063a6..176b90524 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -216,7 +216,7 @@ dependencies { implementation 'com.facebook.fresco:animated-gif:1.10.0' implementation 'com.facebook.fresco:animated-webp: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') { transitive = true; } diff --git a/app/containers/MessageBox/index.js b/app/containers/MessageBox/index.js index 5e9e84354..1d8392fa1 100644 --- a/app/containers/MessageBox/index.js +++ b/app/containers/MessageBox/index.js @@ -155,10 +155,8 @@ export default class MessageBox extends Component { } onChangeText(text) { - const { typing } = this.props; - this.setInput(text); - typing(text.length > 0); + this.handleTyping(text.length > 0); requestAnimationFrame(() => { 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) => { this.text = text; this.component.setNativeProps({ text }); @@ -516,14 +535,14 @@ export default class MessageBox extends Component { submit = async() => { const { - typing, message: editingMessage, editRequest, onSubmit + message: editingMessage, editRequest, onSubmit } = this.props; const message = this.text; this.clearInput(); this.closeEmoji(); this.stopTrackingMention(); - typing(false); + this.handleTyping(false); if (message.trim() === '') { return; }