feat(mobile): redesigned Changes tab with file-first rows and swipe to discard (#37214)

Rows lead with the file name and put its folder under it, so names stop
truncating. The whole row opens the diff, one quiet button stages or
unstages, and discard moves to a left swipe that still asks first. A
status line, a Commits row and a conflict banner with Abort sit above
Uncommitted and Staged sections that carry Stage all and Unstage all.
The rarer git actions move into the header's grouped menu.
This commit is contained in:
Kelvin Amoaba
2026-11-01 23:17:10 +00:00
committed by GitHub
parent a7d6926f77
commit f7047a8fc7
42 changed files with 1837 additions and 2400 deletions
@@ -1,10 +1,8 @@
import { SectionList, View } from 'react-native'
import type { ReactNode } from 'react'
import { ActivityIndicator, Pressable, SectionList, Text, View } from 'react-native'
import { SectionHeader } from '../components/list/ListGroup'
import {
BranchCompareHeader,
BranchFileRow,
makeRenderFileRow
} from './MobileSourceControlFileRows'
import { colors } from '../theme/mobile-theme'
import { BranchFileRow, ChangeFileRow, type FileRowState } from './MobileSourceControlFileRows'
import type {
MobileBranchEntryView,
MobileGitStatusEntryView
@@ -20,57 +18,124 @@ function isWorkingTreeEntry(entry: FileEntry): entry is MobileGitStatusEntryView
return typeof entry.stageActionId === 'string'
}
type FileSection = { key: string; title: string; data: readonly FileEntry[] }
type FileSection = {
key: string
title: string
trailing?: ReactNode
data: readonly FileEntry[]
}
export type FileListState = Pick<
MobileSourceControlState,
| 'sections'
| 'shouldShowBranchCompareSection'
| 'branchCompareSummaryText'
| 'branchEntries'
| 'branchCompareState'
| 'branchCompareResult'
| 'busyAction'
| 'openDiffForFile'
| 'resolveConflict'
| 'runGitAction'
| 'setDiscardTarget'
>
export type FileListState = FileRowState &
Pick<
MobileSourceControlState,
| 'sections'
| 'status'
| 'shouldShowBranchCompareSection'
| 'branchEntries'
| 'branchCompareState'
| 'branchCompareResult'
| 'stageablePaths'
| 'unstageablePaths'
| 'stageAll'
| 'unstageAll'
>
export function MobileSourceControlFileList({
state,
header,
bottomInset
}: {
state: FileListState
/** Clears the floating commit bar, which grows with its message. */
/** The status line, Commits row and conflict banner above the sections. */
header: ReactNode
/** Clears the next-step bar the panel floats over the list. */
bottomInset: number
}) {
const colorScheme = useMobileColorScheme()
const t = useMobileTranslation()
const sections: FileSection[] = state.sections.map((section) => ({
...section,
key: section.id
}))
const busy = state.busyAction !== null
const merging = state.status?.conflictOperation === 'merge'
// A capped all-staged prefix can hide unstaged rows.
const canStageAll = state.stageablePaths.length > 0 || state.status?.didHitLimit === true
const sectionAction = (label: string, onPress: () => void, enabled: boolean) => (
<Pressable
onPress={onPress}
disabled={busy || !enabled}
hitSlop={8}
accessibilityRole="button"
style={({ pressed }) => [
(busy || !enabled) && styles.iconButtonDisabled,
pressed && styles.sectionActionPressed
]}
>
<Text style={styles.sectionAction}>{label}</Text>
</Pressable>
)
// A capped listing can hide every unstaged file behind a staged prefix; keep Stage all reachable.
const cappedWithoutUnstaged =
state.status?.didHitLimit === true &&
!state.sections.some((section) => section.id === 'unstaged')
const stageAllOnStaged =
cappedWithoutUnstaged && state.sections.some((section) => section.id === 'staged')
const stageAllOnConflicts = cappedWithoutUnstaged && !stageAllOnStaged
const stageAllAction = sectionAction(
t('sourceControl.fileList.stageAll', 'Stage all'),
() => void state.stageAll(),
canStageAll
)
const sections: FileSection[] = state.sections.map((section) => {
const title =
merging && section.id === 'staged'
? t('sourceControl.fileList.mergedCleanly', 'Merged cleanly')
: section.title
return {
key: section.id,
title: `${title} ${section.data.length}`,
trailing:
section.id === 'unstaged' || (section.id === 'conflicts' && stageAllOnConflicts) ? (
stageAllAction
) : section.id === 'staged' ? (
<View style={styles.sectionActions}>
{stageAllOnStaged ? stageAllAction : null}
{merging
? null
: sectionAction(
t('sourceControl.fileList.unstageAll', 'Unstage all'),
() => void state.unstageAll(),
state.unstageablePaths.length > 0
)}
</View>
) : undefined,
data: section.data
}
})
const compare = state.branchCompareResult
if (state.shouldShowBranchCompareSection) {
const ready = state.branchCompareState.kind === 'ready' && compare?.summary.status === 'ready'
sections.push({
key: 'committed',
title: t('sourceControl.fileList.committedSection', 'Committed on Branch'),
data:
state.branchCompareState.kind === 'ready' &&
state.branchCompareResult?.summary.status === 'ready'
? state.branchEntries
: []
title: t('sourceControl.fileList.onThisBranch', 'On this branch {{count}}', {
count: state.branchEntries.length
}),
trailing: compare?.summary.baseRef ? (
<Text style={styles.sectionMeta}>
{t('sourceControl.fileList.versusBase', 'vs {{base}}', {
base: compare.summary.baseRef.replace(/^origin\//, '')
})}
</Text>
) : undefined,
data: ready ? state.branchEntries : []
})
}
const renderFileRow = makeRenderFileRow(state, t)
return (
<SectionList<FileEntry, FileSection>
style={hubStyles.tabBody}
sections={sections}
extraData={colorScheme}
ListHeaderComponent={<>{header}</>}
renderItem={({ item }) =>
isWorkingTreeEntry(item) ? (
renderFileRow({ item })
<ChangeFileRow item={item} state={state} />
) : (
<BranchFileRow entry={item} state={state} />
)
@@ -78,17 +143,43 @@ export function MobileSourceControlFileList({
keyExtractor={(item) =>
`${isWorkingTreeEntry(item) ? item.area : 'committed'}:${item.path}:${item.oldPath ?? ''}`
}
renderSectionHeader={({ section }) =>
section.key === 'committed' ? (
<BranchCompareHeader state={state} />
) : (
renderSectionHeader={({ section }) => (
<View>
<View style={styles.sectionHeaderBleed}>
<SectionHeader title={section.title} trailing={String(section.data.length)} />
<SectionHeader title={section.title} trailing={section.trailing} />
</View>
)
}
{section.key === 'committed' ? <BranchCompareState state={state} /> : null}
</View>
)}
stickySectionHeadersEnabled={false}
contentContainerStyle={[styles.listContent, { paddingBottom: bottomInset }]}
/>
)
}
// Loading or failure under "On this branch", where its rows would be.
function BranchCompareState({ state }: { state: FileListState }) {
useMobileColorScheme()
const t = useMobileTranslation()
const { branchCompareState, branchCompareResult } = state
const message =
branchCompareState.kind === 'error'
? branchCompareState.message
: branchCompareResult && branchCompareResult.summary.status !== 'ready'
? (branchCompareResult.summary.errorMessage ??
t('sourceControl.fileRows.committedUnavailable', 'Committed changes unavailable.'))
: null
if (branchCompareState.kind !== 'loading' && message === null) {
return null
}
return (
<View style={styles.branchStateRow}>
{branchCompareState.kind === 'loading' ? (
<ActivityIndicator size="small" color={colors.textSecondary} />
) : null}
<Text style={styles.branchStateText}>
{message ?? t('sourceControl.fileRows.loadingCommitted', 'Loading committed changes...')}
</Text>
</View>
)
}