diff --git a/app/src/main/java/com/urik/keyboard/ui/keyboard/components/KeyboardLayoutManager.kt b/app/src/main/java/com/urik/keyboard/ui/keyboard/components/KeyboardLayoutManager.kt index ca87e87..dab9f52 100644 --- a/app/src/main/java/com/urik/keyboard/ui/keyboard/components/KeyboardLayoutManager.kt +++ b/app/src/main/java/com/urik/keyboard/ui/keyboard/components/KeyboardLayoutManager.kt @@ -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 = emptyMap() private val keyHintRenderer = KeyHintRenderer(context) @@ -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 @@ -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) } @@ -1935,6 +1949,7 @@ class KeyboardLayoutManager( backgroundJob.cancel() backgroundJob = SupervisorJob() backgroundScope = CoroutineScope(Dispatchers.IO + backgroundJob) + effectiveLayout = null returnActiveButtonsToPool() buttonPool.clear() buttonPendingCallbacks.forEach { (_, pending) -> diff --git a/app/src/main/java/com/urik/keyboard/ui/keyboard/components/SwipeKeyboardView.kt b/app/src/main/java/com/urik/keyboard/ui/keyboard/components/SwipeKeyboardView.kt index ba1d8ff..5f2ce46 100644 --- a/app/src/main/java/com/urik/keyboard/ui/keyboard/components/SwipeKeyboardView.kt +++ b/app/src/main/java/com/urik/keyboard/ui/keyboard/components/SwipeKeyboardView.kt @@ -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, @@ -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 @@ -1725,6 +1736,7 @@ class SwipeKeyboardView if (distance > gestureThreshold) { isGestureActive = true + parent?.requestDisallowInterceptTouchEvent(true) keyboardLayoutManager?.cancelAllPendingCallbacks() keyboardLayoutManager?.dismissVariationPopup() keyboardLayoutManager?.triggerHapticFeedback() @@ -1751,6 +1763,10 @@ class SwipeKeyboardView val wasGesture = isGestureActive val wasSwipe = isSwipeActive + if (wasGesture || wasSwipe) { + parent?.requestDisallowInterceptTouchEvent(false) + } + isGestureActive = false gestureKey = null isSwipeActive = false @@ -1812,6 +1828,10 @@ class SwipeKeyboardView val wasGesture = isGestureActive val currentGestureKey = gestureKey + if (wasGesture || isSwipeActive) { + parent?.requestDisallowInterceptTouchEvent(false) + } + hasTouchStart = false isGestureActive = false gestureKey = null