@@ -58,8 +58,8 @@ import {
5858} from "@react-navigation/native" ;
5959import { SymbolView } from "../../components/ui/AppSymbol" ;
6060import { msg , useGT , useMessages } from "gt-react-native" ;
61- import { useEffect , useRef , useState , type ReactNode } from "react" ;
62- import { Keyboard , Platform , Pressable , View } from "react-native" ;
61+ import { useEffect , useRef , useState , type ReactNode , type RefObject } from "react" ;
62+ import { Keyboard , Platform , Pressable , View , type ScrollViewInstance } from "react-native" ;
6363import { useSafeAreaInsets } from "react-native-safe-area-context" ;
6464import * as Arr from "effect/Array" ;
6565import * as Cause from "effect/Cause" ;
@@ -171,13 +171,22 @@ function SectionTitle(props: {
171171 ) ;
172172}
173173
174- function AddProjectShell ( props : { readonly children : ReactNode ; readonly title : string } ) {
174+ function AddProjectShell ( {
175+ children,
176+ title,
177+ scrollRef,
178+ } : {
179+ readonly children : ReactNode ;
180+ readonly title : string ;
181+ readonly scrollRef ?: RefObject < ScrollViewInstance | null > ;
182+ } ) {
175183 const insets = useSafeAreaInsets ( ) ;
176184
177185 return (
178186 // A collapsible wrapper lets formSheet resizing mistake the full-height view for a header and collapse the ScrollView.
179- < SettingsScreen title = { props . title } >
187+ < SettingsScreen title = { title } >
180188 < ScrollView
189+ ref = { scrollRef }
181190 keyboardShouldPersistTaps = "handled"
182191 // Dragging the list drops the keyboard, and the keyboard never covers search results.
183192 keyboardDismissMode = { Platform . OS === "ios" ? "interactive" : "on-drag" }
@@ -190,12 +199,22 @@ function AddProjectShell(props: { readonly children: ReactNode; readonly title:
190199 gap : Platform . OS === "android" ? 16 : 10 ,
191200 } }
192201 >
193- { props . children }
202+ { children }
194203 </ ScrollView >
195204 </ SettingsScreen >
196205 ) ;
197206}
198207
208+ /**
209+ * The screen's scroll view, and a way back to its top: a folder opened from deep in a long list
210+ * starts at its breadcrumbs, with the screen's button in view.
211+ */
212+ function useShellScroll ( ) {
213+ const scrollRef = useRef < ScrollViewInstance > ( null ) ;
214+ const scrollToTop = ( ) => scrollRef . current ?. scrollTo ( { y : 0 , animated : true } ) ;
215+ return { scrollRef, scrollToTop } ;
216+ }
217+
199218function ListSection ( props : { readonly children : ReactNode } ) {
200219 return (
201220 < View
@@ -969,6 +988,7 @@ export function AddProjectRepositoryScreen(props: {
969988}
970989
971990export function AddProjectNewScreen ( props : { readonly environmentId ?: string | string [ ] } ) {
991+ const shellScroll = useShellScroll ( ) ;
972992 const openNewTaskDraft = useOpenNewTaskDraft ( ) ;
973993 const navigation = useNavigation ( ) ;
974994 const environmentOptions = useEnvironmentOptions ( ) . filter (
@@ -1192,7 +1212,7 @@ export function AddProjectNewScreen(props: { readonly environmentId?: string | s
11921212 } ;
11931213
11941214 return (
1195- < AddProjectShell title = { gt ( "New project" ) } >
1215+ < AddProjectShell title = { gt ( "New project" ) } scrollRef = { shellScroll . scrollRef } >
11961216 { error ? < ErrorBanner message = { error } /> : null }
11971217 { environment ? (
11981218 < >
@@ -1366,6 +1386,7 @@ export function AddProjectNewScreen(props: { readonly environmentId?: string | s
13661386 readBrowseInteractionGeneration = { readBrowseInteractionGeneration }
13671387 isBrowseNavigating = { isBrowseNavigating }
13681388 onCreatingFolderChange = { setIsCreatingFolder }
1389+ onFolderNavigated = { shellScroll . scrollToTop }
13691390 missingFolderHint = {
13701391 customLocationMissing
13711392 ? gt ( "This folder does not exist yet. Create it with New folder first." )
@@ -1407,6 +1428,7 @@ export function AddProjectNewScreen(props: { readonly environmentId?: string | s
14071428}
14081429
14091430export function AddProjectLocalFolderScreen ( props : { readonly environmentId ?: string | string [ ] } ) {
1431+ const shellScroll = useShellScroll ( ) ;
14101432 const environment = useEnvironmentFromParam ( props . environmentId ) ;
14111433 const canCreateProject = useEnvironmentScope (
14121434 environment ?. environmentId ?? null ,
@@ -1457,7 +1479,7 @@ export function AddProjectLocalFolderScreen(props: { readonly environmentId?: st
14571479 } ;
14581480
14591481 return (
1460- < AddProjectShell title = { gt ( "Local folder" ) } >
1482+ < AddProjectShell title = { gt ( "Local folder" ) } scrollRef = { shellScroll . scrollRef } >
14611483 { error ? < ErrorBanner message = { error } /> : null }
14621484 { environment ? (
14631485 < >
@@ -1486,6 +1508,7 @@ export function AddProjectLocalFolderScreen(props: { readonly environmentId?: st
14861508 readBrowseInteractionGeneration = { readBrowseInteractionGeneration }
14871509 isBrowseNavigating = { isBrowseNavigating }
14881510 onCreatingFolderChange = { setIsCreatingFolder }
1511+ onFolderNavigated = { shellScroll . scrollToTop }
14891512 missingFolderHint = {
14901513 browse . willCreateFolder
14911514 ? gt ( "This folder does not exist yet. Adding the project creates it." )
@@ -1507,6 +1530,7 @@ export function AddProjectDestinationScreen(props: {
15071530 readonly repositoryName ?: string | string [ ] ;
15081531 readonly prompt ?: string | string [ ] ;
15091532} ) {
1533+ const shellScroll = useShellScroll ( ) ;
15101534 const openNewTaskDraft = useOpenNewTaskDraft ( ) ;
15111535 const startProjectClone = useAtomCommand ( sourceControlEnvironment . startProjectClone , {
15121536 reportFailure : false ,
@@ -1643,7 +1667,7 @@ export function AddProjectDestinationScreen(props: {
16431667 } ;
16441668
16451669 return (
1646- < AddProjectShell title = { gt ( "Clone destination" ) } >
1670+ < AddProjectShell title = { gt ( "Clone destination" ) } scrollRef = { shellScroll . scrollRef } >
16471671 { error ? < ErrorBanner message = { error } /> : null }
16481672 { repositoryTitle ? (
16491673 < View className = "rounded-[24px] bg-grouped-card px-4 py-3" >
@@ -1690,6 +1714,7 @@ export function AddProjectDestinationScreen(props: {
16901714 readBrowseInteractionGeneration = { readBrowseInteractionGeneration }
16911715 isBrowseNavigating = { isBrowseNavigating }
16921716 onCreatingFolderChange = { setIsCreatingFolder }
1717+ onFolderNavigated = { shellScroll . scrollToTop }
16931718 missingFolderHint = {
16941719 remoteUrl && isMissingBrowsePathFailure ( browse . browseState . failure )
16951720 ? gt ( "This folder does not exist yet. Cloning creates it." )
0 commit comments