Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@discord-gists
discord-gists / CustomPanelGestureDetection.kt
Last active March 2, 2022 19:16
a simplified code example for how Discord's Android app supports custom panel gesture detection
class OverlappingPanelsLayout : FrameLayout {
private var scrollingSlopPx: Float = 0f
private var velocityTracker: VelocityTracker? = null
private var isScrollingHorizontally = false
private var xFromInterceptActionDown: Float = 0f
private var yFromInterceptActionDown: Float = 0f
... // initialize scrollingSlopPx and VelocityTracker
@discord-gists
discord-gists / PanelsHorizontalScrollingInChildViews.kt
Last active March 2, 2022 19:22
a simplified code example of how Discord's Android app selectively allows child views of OverlappingPanelsLayout to handle their own horizontal scrolls
class PanelsChildGestureRegionObserver : View.OnLayoutChangeListener {
...
override fun onLayoutChange(
view: View?,
left: Int,
top: Int,
right: Int,
bottom: Int,
oldLeft: Int,
oldTop: Int,
@discord-gists
discord-gists / PanelsPreLayoutViewUpdates.kt
Last active August 30, 2020 15:35
a simplified code example of how Discord's Android app maintains panel states through device rotations while applying view updates before onLayout
class OverlappingPanelsLayout: FrameLayout {
private lateinit var startPanel: View
private lateinit var centerPanel: View
private lateinit var endPanel: View
private var pendingUpdate: (() -> Unit)? = null
...
private fun openStartPanel() {