I need to use setSystemGestureExclusionRects to prevent Android's "swipe from edge of device to trigger back navigation", for my app's painter-like feature. However, though it works perfectly on android simulator, it does not work for many real devices.
Reproducible sample: https://github.com/fzyzcjy/android_gesture_exclusion_example
binding.root.doOnNextLayout {
val exclusions = listOf(Rect(0, it.bottom - 200, 100, it.bottom))
ViewCompat.setSystemGestureExclusionRects(binding.root, exclusions)
}
Expected behavior: When dragging horizontally from left to right near the left-bottom of the left edge of the device (i.e. the exclusions region in the code), android system should not trigger back navigation.
Experiments:
- Android simulator, android 30: Expected behavior
- Android simulator, android 29: Expected behavior
- Real Redmi device, android 29: Unexpected behavior (seems the
setSystemGestureExclusionRectsdoes not work at all) - Real Honor device, android 29: Unexpected behavior (same as above)