-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathMentionHandler.kt
More file actions
40 lines (33 loc) · 1.11 KB
/
Copy pathMentionHandler.kt
File metadata and controls
40 lines (33 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.swmansion.enriched.events
import com.facebook.react.bridge.ReactContext
import com.facebook.react.uimanager.UIManagerHelper
import com.swmansion.enriched.EnrichedTextInputView
class MentionHandler(private val view: EnrichedTextInputView) {
private var previousText: String? = null
private var previousIndicator: String? = null
fun endMention() {
val indicator = previousIndicator
if (indicator == null) return
emitEvent(indicator, null)
previousIndicator = null
}
fun onMention(indicator: String, text: String?) {
emitEvent(indicator, text)
previousIndicator = indicator
}
private fun emitEvent(indicator: String, text: String?) {
// Do not emit events too often
if (previousText == text) return
previousText = text
val context = view.context as ReactContext
val surfaceId = UIManagerHelper.getSurfaceId(context)
val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, view.id)
dispatcher?.dispatchEvent(OnMentionEvent(
surfaceId,
view.id,
indicator,
text,
view.experimentalSynchronousEvents,
))
}
}