Skip to content

Commit 7e10c1b

Browse files
LUwUciferBrayanDSO
authored andcommitted
Fix(Whiteboard): Side System Gesture Exclusion
1 parent 67eccf6 commit 7e10c1b

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/whiteboard/WhiteboardToolbar.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@
1616
package com.ichi2.anki.ui.windows.reviewer.whiteboard
1717

1818
import android.content.Context
19+
import android.graphics.Rect
1920
import android.util.AttributeSet
2021
import android.view.LayoutInflater
2122
import android.view.MotionEvent
2223
import android.view.View
2324
import android.view.ViewConfiguration
2425
import android.view.animation.DecelerateInterpolator
2526
import android.widget.LinearLayout
27+
import androidx.core.view.ViewCompat
28+
import androidx.core.view.marginLeft
29+
import androidx.core.view.marginRight
2630
import androidx.core.view.updateLayoutParams
2731
import androidx.recyclerview.widget.LinearLayoutManager
2832
import com.ichi2.anki.databinding.ViewWhiteboardToolbarBinding
@@ -66,6 +70,32 @@ class WhiteboardToolbar : LinearLayout {
6670
var onBrushLongClick: ((index: Int) -> Unit)? = null
6771
var onToolbarVisibilityChanged: ((isShown: Boolean) -> Unit)? = null
6872

73+
/**
74+
* Disables gesture swipe of docked whiteboard toolbar on the side on layout change
75+
* While this code does attempt to set exclusion rect when ToolbarAlignment.BOTTOM,
76+
* no effect occurs as bottom screen gestures cannot be opted out of
77+
* https://developer.android.com/develop/ui/views/touch-and-input/gestures/gesturenav#kotlin
78+
*/
79+
private val boundingBox: Rect = Rect()
80+
private val exclusions = listOf(boundingBox)
81+
82+
override fun onLayout(
83+
changed: Boolean,
84+
left: Int,
85+
top: Int,
86+
right: Int,
87+
bottom: Int,
88+
) {
89+
super.onLayout(changed, left, top, right, bottom)
90+
if (!changed) return
91+
when (currentAlignment) {
92+
ToolbarAlignment.LEFT -> boundingBox.set(left - marginLeft, top, right, bottom)
93+
ToolbarAlignment.RIGHT -> boundingBox.set(left, top, right + marginRight, bottom)
94+
ToolbarAlignment.BOTTOM -> boundingBox.set(0, 0, 0, 0)
95+
}
96+
ViewCompat.setSystemGestureExclusionRects(this, exclusions)
97+
}
98+
6999
/**
70100
* Updates the internal layout based on the toolbar alignment.
71101
* Switches the RecyclerView orientation and the main layout orientation.

0 commit comments

Comments
 (0)