import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react' import { ActivityIndicator, Animated, Easing, Text, View } from 'react-native' import { colors, spacing } from '../theme/mobile-theme' import { useMobileColorScheme } from '../theme/use-mobile-color-scheme' import { useMobileTranslation } from '../i18n/use-mobile-translation' import { useReducedMotionEnabled } from '../platform/use-reduced-motion' import { SHEET_CURVE } from '../components/sheet-motion-values' import { MobileSourceControlChangesHeader } from './MobileSourceControlChangesHeader' import { MobileCommitFailurePanel } from './MobileCommitFailurePanel' import { MobileSourceControlFileList } from './MobileSourceControlFileList' import type { MobileSourceControlState } from './use-mobile-source-control-state' import { styles } from './mobile-source-control-styles' import { hubStyles } from './mobile-source-control-hub-styles' const CLEAN_FADE_MS = 240 const REDUCED_CLEAN_FADE_MS = 150 // The clean state settles in when a commit empties the list; on load it is simply there. function CleanStateFade({ animate, children }: { animate: boolean; children: ReactNode }) { const reducedMotion = useReducedMotionEnabled() === true const shown = useRef(new Animated.Value(animate ? 0 : 1)).current useEffect(() => { if (!animate) { return } Animated.timing(shown, { toValue: 1, duration: reducedMotion ? REDUCED_CLEAN_FADE_MS : CLEAN_FADE_MS, easing: Easing.bezier(...SHEET_CURVE), useNativeDriver: true }).start() }, [animate, reducedMotion, shown]) const scale = reducedMotion ? 1 : shown.interpolate({ inputRange: [0, 1], outputRange: [0.97, 1] }) return ( {children} ) } type Props = { state: Omit stageAllInBar: boolean /** Clears the next-step bar the panel floats over the list. */ bottomInset: number onOpenCommits: () => void } export function MobileSourceControlContent({ state, stageAllInBar, bottomInset, onOpenCommits }: Props) { useMobileColorScheme() const t = useMobileTranslation() const { busyAction, hasVisibleChanges } = state // Commit runners keep busyAction set ('commit…') until the refreshed status has landed. const [listShown, setListShown] = useState(hasVisibleChanges) const [cleanedByCommit, setCleanedByCommit] = useState(false) if (listShown !== hasVisibleChanges) { setListShown(hasVisibleChanges) setCleanedByCommit(!hasVisibleChanges && busyAction?.startsWith('commit') === true) } // Pick only what the list reads, so commit-message keystrokes never re-render its rows. const { connState, status, branchLabel, branchCompareResult, actionError, commitFailureRecovery, commitFailureRecoveryAction, openBranchPicker, abortConflictOperation, sections, shouldShowBranchCompareSection, branchEntries, branchCompareState, stageablePaths, unstageablePaths, stageAll, unstageAll, openDiffForFile, resolveConflict, runGitAction, setDiscardTarget } = state const header = useMemo( () => ( ), [ abortConflictOperation, branchCompareResult, branchLabel, busyAction, onOpenCommits, openBranchPicker, status ] ) const list = useMemo( () => ( ), [ bottomInset, branchCompareResult, branchCompareState, branchEntries, busyAction, header, openDiffForFile, stageAllInBar, resolveConflict, runGitAction, sections, setDiscardTarget, shouldShowBranchCompareSection, stageAll, stageablePaths, status, unstageAll, unstageablePaths ] ) // Outside the list, so a failure stays in view however far the rows are scrolled. const feedback = connState !== 'connected' || commitFailureRecovery || actionError ? ( {connState !== 'connected' ? ( // Retained rows look actionable offline; show reconnect state beside them. {t('sourceControl.content.reconnecting', 'Reconnecting to desktop...')} ) : null} {commitFailureRecovery ? ( ) : actionError ? ( {actionError} ) : null} ) : null if (!hasVisibleChanges) { return ( {feedback} {header} {t('sourceControl.content.emptyTitle', 'No local changes')} {t('sourceControl.content.emptyMessage', 'Working tree is clean.')} ) } return ( {feedback} {list} ) }