@@ -50,12 +50,21 @@ class T3ReviewDiffView(context: Context, appContext: AppContext) : ExpoView(cont
5050 private val verticalScroller = OverScroller (context)
5151 private val horizontalScroller = OverScroller (context)
5252 private var dragAxis: DragAxis ? = null
53+ private var scrollEnabled = true
5354 private var horizontalDragTarget: HorizontalPanTarget ? = null
5455 private var lastTouchX = 0f
5556 private var lastTouchY = 0f
5657 private var velocityTracker: VelocityTracker ? = null
5758
5859 init {
60+ canvasView.onContentHeightChanged = { height ->
61+ onDebug(
62+ mapOf (
63+ " message" to " metrics" ,
64+ " contentHeight" to height / resources.displayMetrics.density
65+ )
66+ )
67+ }
5968 canvasView.onRowTap = { row, gesture, target -> handleRowTap(row, gesture, target) }
6069 canvasView.onVisibleRowsChanged = { first, last ->
6170 onDebug(
@@ -198,6 +207,14 @@ class T3ReviewDiffView(context: Context, appContext: AppContext) : ExpoView(cont
198207 scrollToY(canvasView.rowTop(index), animated)
199208 }
200209
210+ fun setScrollEnabled (enabled : Boolean ) {
211+ scrollEnabled = enabled
212+ if (! enabled) {
213+ verticalScroller.forceFinished(true )
214+ canvasView.setVerticalOffset(0 )
215+ }
216+ }
217+
201218 fun scrollToTop (animated : Boolean ) {
202219 scrollToY(0 , animated)
203220 }
@@ -212,7 +229,7 @@ class T3ReviewDiffView(context: Context, appContext: AppContext) : ExpoView(cont
212229 horizontalDragTarget = canvasView.horizontalPanTarget(event.y)
213230 lastTouchX = event.x
214231 lastTouchY = event.y
215- parent?.requestDisallowInterceptTouchEvent(true )
232+ parent?.requestDisallowInterceptTouchEvent(scrollEnabled )
216233 return false
217234 }
218235 MotionEvent .ACTION_MOVE -> {
@@ -221,14 +238,15 @@ class T3ReviewDiffView(context: Context, appContext: AppContext) : ExpoView(cont
221238 val deltaY = event.y - lastTouchY
222239 if (max(abs(deltaX), abs(deltaY)) > touchSlop) {
223240 dragAxis = if (abs(deltaY) >= abs(deltaX)) {
224- DragAxis .VERTICAL
241+ if (scrollEnabled) DragAxis .VERTICAL else null
225242 } else {
226243 horizontalDragTarget
227244 ?.takeIf { canvasView.maxHorizontalOffset(it) > 0 }
228245 ?.let { DragAxis .HORIZONTAL }
229246 }
230247 }
231248 }
249+ if (dragAxis == DragAxis .HORIZONTAL ) parent?.requestDisallowInterceptTouchEvent(true )
232250 return dragAxis != null
233251 }
234252 MotionEvent .ACTION_UP , MotionEvent .ACTION_CANCEL -> return dragAxis != null
@@ -751,6 +769,7 @@ private class DiffCanvasView(context: Context) : View(context) {
751769 }
752770 var onRowTap: ((DiffRow , String , RowTapTarget ) -> Unit )? = null
753771 var onVisibleRowsChanged: ((Int , Int ) -> Unit )? = null
772+ var onContentHeightChanged: ((Int ) -> Unit )? = null
754773
755774 fun prepareRows () = drawing.prepareRows(tokensByRowId, style, width)
756775 fun useCodeLayouts (layouts : CodeLayoutCache ) {
@@ -876,6 +895,7 @@ private class DiffCanvasView(context: Context) : View(context) {
876895 setVerticalOffset(verticalOffset)
877896 setHorizontalOffset(horizontalOffset)
878897 clampHeaderPathOffsets()
898+ onContentHeightChanged?.invoke(rowOffsets.last())
879899 }
880900
881901 private fun rowHeight (row : DiffRow ): Int = when (row.kind) {
@@ -1198,14 +1218,7 @@ private class DiffCanvasView(context: Context) : View(context) {
11981218 }
11991219 val selected = selectedRowIds.contains(row.id)
12001220 if (selected) {
1201- fill(
1202- canvas,
1203- withAlpha(theme.hunkText, 56 ),
1204- 0f ,
1205- top.toFloat(),
1206- width.toFloat(),
1207- bottom.toFloat(),
1208- )
1221+ // Keep the diff and syntax colors intact; selection lives in the gutter.
12091222 fill(
12101223 canvas,
12111224 withAlpha(theme.hunkText, 242 ),
0 commit comments