Repository navigation
Programmatically change the current detent of an already-open formSheet #4698
SummaryWith What I've tried
Use caseA button inside the sheet expands it to the largest detent (e.g. "show more"), while the user should still be able to freely drag between all detents afterward. QuestionIs this achievable already and I'm missing something? If not, would an imperative API be feasible e.g. wrapping iOS's Thanks for any help |
Replies: 3 comments 1 reply
|
From the current For now, the reliable options are to let the user drag/select the detent, or close and reopen with the desired References: FormSheet props and the current component implementation. |
|
I would also like this feature very much. I have an app which combines sheets with an expo-maps background, which needs to shrink the sheet once the user interacts with the map. I opened a PR for this: #4793 It adds a const sheetRef = useRef<FormSheetCommands>(null);
<FormSheet ref={sheetRef} isOpen={isOpen} detents={[0.3, 0.6, 1.0]}>
<Button title="Show more" onPress={() => sheetRef.current?.selectDetent('last')} />
</FormSheet>Afterwards the sheet can still be dragged between all detents, and Note that this targets the new |
|
@barry166 Was there a reason this feature was not implemented? |
From the current
FormSheetsource, there is no supported imperative API for selecting a new detent after the sheet is already open.initialDetentIndexis only applied on the closed → open transition, andonDetentChangedis a notification callback; changing that prop (or temporarily narrowingdetents) is not a stable way to select a detent while preserving the full set.For now, the reliable options are to let the user drag/select the detent, or close and reopen with the desired
initialDetentIndex(which may not be suitable if you must preserve the presentation). An imperative ref/command that maps to iOSselectedDetentIdentifier(and the Android equivalent) would require a library change.R…