Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class KeyboardLayoutManager(
private var showLanguageSwitchKey = false
private var hasMultipleImes = false

var effectiveLayout: KeyboardLayout? = null
private set

@Volatile
private var customKeyMappings: Map<String, String> = emptyMap()
private val keyHintRenderer = KeyHintRenderer(context)
Expand Down Expand Up @@ -715,6 +718,23 @@ class KeyboardLayoutManager(
): View {
returnActiveButtonsToPool()

val processedRows =
layout.rows.map { row ->
if (shouldInjectGlobeButton(row)) {
injectGlobeButton(row)
} else {
row
}
}

effectiveLayout =
KeyboardLayout(
mode = layout.mode,
rows = processedRows,
isRTL = layout.isRTL,
script = layout.script,
)

val keyboardContainer =
LinearLayout(context).apply {
orientation = LinearLayout.VERTICAL
Expand All @@ -734,14 +754,8 @@ class KeyboardLayoutManager(
contentDescription = context.getString(R.string.keyboard_description)
}

layout.rows.forEach { row ->
val processedRow =
if (shouldInjectGlobeButton(row)) {
injectGlobeButton(row)
} else {
row
}
val rowView = createRowView(processedRow, state)
processedRows.forEach { row ->
val rowView = createRowView(row, state)
keyboardContainer.addView(rowView)
}

Expand Down Expand Up @@ -1935,6 +1949,7 @@ class KeyboardLayoutManager(
backgroundJob.cancel()
backgroundJob = SupervisorJob()
backgroundScope = CoroutineScope(Dispatchers.IO + backgroundJob)
effectiveLayout = null
returnActiveButtonsToPool()
buttonPool.clear()
buttonPendingCallbacks.forEach { (_, pending) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,10 @@ class SwipeKeyboardView
val keyboardView = keyboardLayoutManager?.createKeyboardView(layout, state)

if (keyboardView is ViewGroup) {
keyboardLayoutManager?.effectiveLayout?.let { effective ->
currentLayout = effective
}

addView(
keyboardView,
childCount - 1,
Expand Down Expand Up @@ -1681,6 +1685,13 @@ class SwipeKeyboardView
}
}

override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
if (!isDestroyed && (isGestureActive || isSwipeActive)) {
return onTouchEvent(ev)
}
return super.dispatchTouchEvent(ev)
}

override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
if (isDestroyed) return false

Expand Down Expand Up @@ -1725,6 +1736,7 @@ class SwipeKeyboardView

if (distance > gestureThreshold) {
isGestureActive = true
parent?.requestDisallowInterceptTouchEvent(true)
keyboardLayoutManager?.cancelAllPendingCallbacks()
keyboardLayoutManager?.dismissVariationPopup()
keyboardLayoutManager?.triggerHapticFeedback()
Expand All @@ -1751,6 +1763,10 @@ class SwipeKeyboardView
val wasGesture = isGestureActive
val wasSwipe = isSwipeActive

if (wasGesture || wasSwipe) {
parent?.requestDisallowInterceptTouchEvent(false)
}

isGestureActive = false
gestureKey = null
isSwipeActive = false
Expand Down Expand Up @@ -1812,6 +1828,10 @@ class SwipeKeyboardView
val wasGesture = isGestureActive
val currentGestureKey = gestureKey

if (wasGesture || isSwipeActive) {
parent?.requestDisallowInterceptTouchEvent(false)
}

hasTouchStart = false
isGestureActive = false
gestureKey = null
Expand Down
Loading