Skip to content

Commit bed9239

Browse files
feat(mobile): guided reviews for pull requests (#18267)
1 parent 5495cc4 commit bed9239

42 files changed

Lines changed: 1696 additions & 309 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/modules/t3-review-diff/android/src/main/java/expo/modules/t3reviewdiff/T3ReviewDiffModule.kt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class T3ReviewDiffModule : Module() {
4141
Prop("contentWidth") { view: T3ReviewDiffView, contentWidth: Double ->
4242
view.setContentWidth(contentWidth.toFloat())
4343
}
44+
Prop("scrollEnabled") { view: T3ReviewDiffView, enabled: Boolean ->
45+
view.setScrollEnabled(enabled)
46+
}
4447
Prop("initialRowIndex") { view: T3ReviewDiffView, initialRowIndex: Double ->
4548
view.setInitialRowIndex(initialRowIndex)
4649
}

‎apps/mobile/modules/t3-review-diff/android/src/main/java/expo/modules/t3reviewdiff/T3ReviewDiffView.kt‎

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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),

‎apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffModule.swift‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ public class T3ReviewDiffModule: Module {
6161
view.setInitialRowIndex(initialRowIndex)
6262
}
6363

64+
Prop("scrollEnabled") { (view: T3ReviewDiffView, enabled: Bool) in
65+
view.setScrollEnabled(enabled)
66+
}
67+
68+
Prop("bounces") { (view: T3ReviewDiffView, bounces: Bool) in
69+
view.setBounces(bounces)
70+
}
71+
72+
Prop("refreshEnabled") { (view: T3ReviewDiffView, enabled: Bool) in
73+
view.setRefreshEnabled(enabled)
74+
}
75+
6476
Prop("refreshing") { (view: T3ReviewDiffView, refreshing: Bool) in
6577
view.setRefreshing(refreshing)
6678
}

‎apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swift‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ public final class T3ReviewDiffView: ExpoView, UIScrollViewDelegate {
365365
scrollView.showsHorizontalScrollIndicator = false
366366
scrollView.backgroundColor = contentView.theme.background
367367
pullRefreshControl.addTarget(self, action: #selector(handlePullToRefresh), for: .valueChanged)
368-
scrollView.refreshControl = pullRefreshControl
369368
addSubview(scrollView)
370369

371370
contentView.backgroundColor = contentView.theme.background
@@ -701,14 +700,14 @@ public final class T3ReviewDiffView: ExpoView, UIScrollViewDelegate {
701700
applyPendingScrollIfNeeded()
702701
emitVisibleFileIfNeeded()
703702

704-
let debugKey = "\(rows.count):\(Int(bounds.width)):\(Int(bounds.height)):\(Int(height))"
703+
let debugKey = "\(rows.count):\(Int(bounds.width)):\(Int(bounds.height)):\(Int(contentView.contentHeight))"
705704
if debugKey != lastMetricsDebugKey {
706705
lastMetricsDebugKey = debugKey
707706
emitDebug("metrics", [
708707
"rows": rows.count,
709708
"boundsWidth": Double(bounds.width),
710709
"boundsHeight": Double(bounds.height),
711-
"contentHeight": Double(height),
710+
"contentHeight": Double(contentView.contentHeight),
712711
"contentWidth": Double(style.contentWidth),
713712
"fileHeaderHeight": Double(style.fileHeaderHeight),
714713
"rowHeight": Double(style.rowHeight),
@@ -840,6 +839,20 @@ public final class T3ReviewDiffView: ExpoView, UIScrollViewDelegate {
840839
setVerticalContentOffset(0, animated: animated)
841840
}
842841

842+
func setScrollEnabled(_ enabled: Bool) {
843+
scrollView.isScrollEnabled = enabled
844+
}
845+
846+
func setBounces(_ bounces: Bool) {
847+
scrollView.bounces = bounces
848+
scrollView.alwaysBounceVertical = bounces
849+
}
850+
851+
func setRefreshEnabled(_ enabled: Bool) {
852+
if !enabled { pullRefreshControl.endRefreshing() }
853+
scrollView.refreshControl = enabled ? pullRefreshControl : nil
854+
}
855+
843856
@objc private func handlePullToRefresh() {
844857
onPullToRefresh([:])
845858
}
@@ -2429,10 +2442,7 @@ private final class ReviewDiffContentView: UIView, UIGestureRecognizerDelegate {
24292442
return
24302443
}
24312444

2432-
let selectionColor = theme.hunkText.withAlphaComponent(0.22)
2433-
selectionColor.setFill()
2434-
context.fill(rect)
2435-
2445+
// Keep the diff and syntax colors intact; selection lives in the gutter.
24362446
theme.hunkText.withAlphaComponent(0.95).setFill()
24372447
context.fill(CGRect(x: 0, y: rect.minY, width: style.changeBarWidth, height: rect.height))
24382448
}

‎apps/mobile/src/Stack.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { PullRequestGuideStopScreen } from "./features/pull-requests/guide/PullRequestGuideScreen";
12
import { PullRequestInlineCommentScreen } from "./features/pull-requests/PullRequestInlineCommentScreen";
23
import { PullRequestDiscussionScreen } from "./features/pull-requests/PullRequestDiscussionScreen";
34
import {
@@ -722,6 +723,10 @@ const RootStackConfig = createWorkspaceStackNavigator({
722723
},
723724
options: GLASS_HEADER_OPTIONS,
724725
}),
726+
PullRequestGuideStop: createNativeStackScreen({
727+
screen: PullRequestGuideStopScreen,
728+
options: GLASS_HEADER_OPTIONS,
729+
}),
725730
PullRequestFile: createNativeStackScreen({
726731
screen: PullRequestFileRouteScreen,
727732
options: GLASS_HEADER_OPTIONS,

‎apps/mobile/src/features/diffs/nativeReviewDiffSurface.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ export interface NativeReviewDiffViewProps extends ViewProps {
124124
readonly rowHeight: number;
125125
readonly contentWidth: number;
126126
readonly initialRowIndex?: number;
127+
/** Disable the native vertical scroller when an excerpt grows inside a page. */
128+
readonly scrollEnabled?: boolean;
129+
readonly bounces?: boolean;
127130
readonly refreshing?: boolean;
128131
readonly nativeViewRef?: Ref<NativeReviewDiffViewHandle>;
129132
readonly onPullToRefresh?: (event: NativeSyntheticEvent<Record<string, never>>) => void;
@@ -167,6 +170,7 @@ type NativeReviewDiffRawViewProps = Omit<
167170
NativeReviewDiffViewProps,
168171
"nativeViewRef" | "rowsJson" | "tokensJson" | "tokensPatchJson"
169172
> & {
173+
readonly refreshEnabled: boolean;
170174
readonly ref?: Ref<NativeReviewDiffViewRef>;
171175
};
172176

@@ -270,7 +274,11 @@ function NativeReviewDiffView(props: NativeReviewDiffViewProps) {
270274
return null;
271275
}
272276

273-
return createElement(RawNativeView, { ...nativeProps, ref: nativeRef });
277+
return createElement(RawNativeView, {
278+
...nativeProps,
279+
refreshEnabled: props.onPullToRefresh !== undefined,
280+
ref: nativeRef,
281+
});
274282
}
275283

276284
export function resolveNativeReviewDiffView(): ComponentType<NativeReviewDiffViewProps> | null {
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { Pressable, View } from "react-native";
2+
import { AppText as Text } from "../../components/AppText";
3+
import { SymbolView } from "../../components/AppSymbol";
4+
import { ControlPillMenu } from "../../components/ControlPillMenu";
5+
import type { ActivityFilter } from "./pullRequestActivityFilter";
6+
7+
export function PullRequestActivityFilters({
8+
value,
9+
onChange,
10+
hiddenCount,
11+
}: {
12+
readonly value: ActivityFilter;
13+
readonly onChange: (value: ActivityFilter) => void;
14+
readonly hiddenCount: number;
15+
}) {
16+
const kinds = [
17+
{ id: "all", title: "All activity" },
18+
{ id: "comments", title: "Comments" },
19+
{ id: "commits", title: "Commits" },
20+
] as const;
21+
return (
22+
<View className="mb-4 flex-row items-center justify-between gap-3">
23+
<ControlPillMenu
24+
title="Activity"
25+
actions={kinds.map((kind) => ({ ...kind, state: value.kind === kind.id ? "on" : "off" }))}
26+
onPressAction={({ nativeEvent }) => {
27+
const kind = kinds.find((item) => item.id === nativeEvent.event);
28+
if (kind) onChange({ ...value, kind: kind.id });
29+
}}
30+
>
31+
<Pressable
32+
accessibilityRole="button"
33+
accessibilityLabel={`Activity type, ${kinds.find((kind) => kind.id === value.kind)?.title}`}
34+
className="min-h-11 flex-row items-center gap-2 active:opacity-60"
35+
>
36+
<Text className="text-sm font-t3-semibold">
37+
{kinds.find((kind) => kind.id === value.kind)?.title}
38+
</Text>
39+
<SymbolView name="chevron.down" size={11} tintColorClassName="accent-icon-muted" />
40+
</Pressable>
41+
</ControlPillMenu>
42+
<View className="flex-row items-center gap-3">
43+
<ControlPillMenu
44+
title="Show in activity"
45+
actions={[
46+
{ id: "bots", title: "Bot comments", state: value.bots ? "on" : "off" },
47+
{
48+
id: "resolved",
49+
title: "Resolved or dismissed",
50+
state: value.resolved ? "on" : "off",
51+
},
52+
]}
53+
onPressAction={({ nativeEvent: { event } }) => {
54+
if (event === "bots" || event === "resolved")
55+
onChange({ ...value, [event]: !value[event] });
56+
}}
57+
>
58+
<Pressable
59+
accessibilityRole="button"
60+
accessibilityLabel={`Filter activity, ${hiddenCount} hidden`}
61+
className="min-h-11 flex-row items-center gap-1.5 active:opacity-60"
62+
>
63+
{hiddenCount > 0 ? (
64+
<Text className="text-xs text-foreground-muted">{hiddenCount} hidden</Text>
65+
) : null}
66+
<SymbolView
67+
name="line.3.horizontal.decrease"
68+
size={18}
69+
tintColorClassName="accent-icon-muted"
70+
/>
71+
</Pressable>
72+
</ControlPillMenu>
73+
<Pressable
74+
accessibilityRole="button"
75+
accessibilityLabel={value.newestFirst ? "Newest first" : "Oldest first"}
76+
onPress={() => onChange({ ...value, newestFirst: !value.newestFirst })}
77+
className="h-11 flex-row items-center gap-1 active:opacity-60"
78+
>
79+
<SymbolView
80+
name={value.newestFirst ? "arrow.down" : "arrow.up"}
81+
size={18}
82+
tintColorClassName="accent-icon-muted"
83+
/>
84+
<Text className="text-xs text-foreground-muted">
85+
{value.newestFirst ? "Newest" : "Oldest"}
86+
</Text>
87+
</Pressable>
88+
</View>
89+
</View>
90+
);
91+
}

‎apps/mobile/src/features/pull-requests/PullRequestControls.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import Animated from "react-native-reanimated";
2+
import { PR_ROW_LAYOUT } from "./pullRequestAnimations";
13
import { useNavigation } from "@react-navigation/native";
24
import type { PullRequestDetail } from "@t3tools/contracts";
35
import type { ReactNode } from "react";
@@ -21,9 +23,12 @@ import { usePullRequestAgentActions } from "./usePullRequestAgentActions";
2123

2224
export function PullRequestCardGroup(props: { readonly children: ReactNode }) {
2325
return (
24-
<View className="overflow-hidden rounded-[22px] border-continuous bg-grouped-card">
26+
<Animated.View
27+
layout={PR_ROW_LAYOUT}
28+
className="overflow-hidden rounded-[22px] border-continuous bg-grouped-card"
29+
>
2530
{props.children}
26-
</View>
31+
</Animated.View>
2732
);
2833
}
2934

0 commit comments

Comments
 (0)