@marktiderman/genesis-ui-native 2.4.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { Box, FULL_SCREEN_DARK, Grid, Inline, NativeAccordion, NativeAccordionContent, NativeAccordionItem, NativeAccordionTrigger, NativeAvatar, NativeBanner, NativeChip, NativeChipGroup, NativeCombobox, NativeDatePicker, NativeDialog, NativeDialogContent, NativeDialogDescription, NativeDialogFooter, NativeDialogHeader, NativeDialogTitle, NativeDrawer, NativeDropdownMenu, NativeDropdownMenuContent, NativeDropdownMenuItem, NativeDropdownMenuTrigger, NativeFullScreenModal, NativeGlassSurface, NativeHeaderCard, NativeImage, NativeInlineAlert, NativeNumberInput, NativePagination, NativePopover, NativePopoverContent, NativePopoverTrigger, NativeProgress, NativeRadioGroup, NativeRadioGroupItem, NativeRangeSlider, NativeSearchBar, NativeSegmentedControl, NativeSheet, NativeSheetProvider, NativeSheetScrollView, NativeSlider, NativeStepper, NativeTabs, NativeTabsContent, NativeTabsList, NativeTabsTrigger, NativeTimePicker, NativeToastProvider, NativeToggle, NativeTooltip, NativeTooltipContent, NativeTooltipTrigger, Stack, spaceScale, spacingClass, toggleVariants, useLiquidGlass, useReduceTransparency, useToast } from './chunk-7VSW3XWJ.js';
1
+ export { Box, FULL_SCREEN_DARK, Grid, Inline, NativeAccordion, NativeAccordionContent, NativeAccordionItem, NativeAccordionTrigger, NativeAvatar, NativeBanner, NativeChip, NativeChipGroup, NativeCombobox, NativeDatePicker, NativeDialog, NativeDialogContent, NativeDialogDescription, NativeDialogFooter, NativeDialogHeader, NativeDialogTitle, NativeDrawer, NativeDropdownMenu, NativeDropdownMenuContent, NativeDropdownMenuItem, NativeDropdownMenuTrigger, NativeFullScreenModal, NativeGlassSurface, NativeHeaderCard, NativeImage, NativeInlineAlert, NativeNumberInput, NativePagination, NativePopover, NativePopoverContent, NativePopoverTrigger, NativeProgress, NativeRadioGroup, NativeRadioGroupItem, NativeRangeSlider, NativeSearchBar, NativeSegmentedControl, NativeSheet, NativeSheetProvider, NativeSheetScrollView, NativeSlider, NativeStepper, NativeTabs, NativeTabsContent, NativeTabsList, NativeTabsTrigger, NativeTimePicker, NativeToastProvider, NativeToggle, NativeTooltip, NativeTooltipContent, NativeTooltipTrigger, Stack, spaceScale, spacingClass, toggleVariants, useLiquidGlass, useReduceTransparency, useToast } from './chunk-RARJGZA3.js';
2
2
  export { NativeAlert, NativeAlertDescription, NativeAlertTitle, NativeCard, NativeCardContent, NativeCardDescription, NativeCardFooter, NativeCardHeader, NativeCardTitle, NativeCheckbox, NativeLabel, NativeSelect, NativeSelectContent, NativeSelectItem, NativeSelectTrigger, NativeSeparator, NativeSkeleton, NativeSwitch, NativeTextarea, alertVariants } from './chunk-FIITITXO.js';
3
3
  export { BrandExtensionsProvider, useGenesisExtension } from './chunk-D5RKSPMH.js';
4
4
  export { useReducedMotion } from './chunk-7PCWEY6R.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marktiderman/genesis-ui-native",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -118,6 +118,18 @@ describe("NativeSheet without a provider", () => {
118
118
  expect(onOpenChange).not.toHaveBeenCalled();
119
119
  });
120
120
 
121
+ it("fits its content on iOS with fitContent: a bottom panel over a scrim, not the page sheet", async () => {
122
+ Platform.OS = "ios";
123
+ const onOpenChange = vi.fn();
124
+ render(sheet({ onOpenChange, testID: "s", fitContent: true }));
125
+ const modal = await screen.findByRole("dialog");
126
+ expect(modal.getAttribute("data-presentation-style")).toBeNull();
127
+ expect(modal.getAttribute("data-transparent")).toBe("true");
128
+ expect(screen.getByTestId("s").textContent).toBe("body");
129
+ fireEvent.click(screen.getByTestId("s-backdrop"));
130
+ expect(onOpenChange).toHaveBeenCalledWith(false);
131
+ });
132
+
121
133
  it("renders nothing while closed", async () => {
122
134
  render(sheet({ open: false }));
123
135
  await act(async () => {});
@@ -146,6 +158,7 @@ describe("NativeSheet under NativeSheetProvider", () => {
146
158
  expect(present).toHaveBeenCalledTimes(1);
147
159
  // The given snap points are the sheet's only ones (v5 would add a content-height one).
148
160
  expect(modalProps).toHaveBeenLastCalledWith(expect.objectContaining({ snapPoints: ["25%"], enableDynamicSizing: false }));
161
+ expect((modalProps.mock.calls.at(-1)![0] as { maxDynamicContentSize?: number }).maxDynamicContentSize).toBeUndefined();
149
162
 
150
163
  // The user closing it reports; the app closing it doesn't report back.
151
164
  fireEvent.click(screen.getByTestId("gorhom-modal"));
@@ -157,6 +170,20 @@ describe("NativeSheet under NativeSheetProvider", () => {
157
170
  expect(onOpenChange).not.toHaveBeenCalled();
158
171
  });
159
172
 
173
+ it("lets the library size a sheet that fits its content", () => {
174
+ const { library, modalProps } = fakeLibrary();
175
+ render(
176
+ <NativeSheetProvider bottomSheet={library}>
177
+ <NativeSheet open onOpenChange={() => {}} fitContent>
178
+ <span>body</span>
179
+ </NativeSheet>
180
+ </NativeSheetProvider>,
181
+ );
182
+ expect(modalProps).toHaveBeenLastCalledWith(expect.objectContaining({ snapPoints: undefined, index: 0, enableDynamicSizing: true }));
183
+ // Capped below the full height, so long content never runs under the status bar.
184
+ expect((modalProps.mock.calls.at(-1)![0] as { maxDynamicContentSize?: number }).maxDynamicContentSize).toBeGreaterThan(0);
185
+ });
186
+
160
187
  it("doesn't report a dismiss that finishes after the app reopened the sheet", () => {
161
188
  const { library } = fakeLibrary();
162
189
  const onOpenChange = vi.fn();
@@ -20,6 +20,8 @@
20
20
  * `GestureHandlerRootView` at the root and Reanimated set up.
21
21
  * `snapPoints` and `initialSnapIndex` apply only to that path.
22
22
  *
23
+ * A short menu or form passes `fitContent`: the sheet is as tall as what is in it.
24
+ *
23
25
  * A sheet that is a screen of its own (a link can open it) belongs in the
24
26
  * router instead: an expo-router screen with `presentation: "formSheet"` and
25
27
  * `sheetAllowedDetents` (e.g. `[0.5, 1]`) is the system sheet with detents.
@@ -36,7 +38,7 @@ import {
36
38
  type ComponentType,
37
39
  type ReactNode,
38
40
  } from "react";
39
- import { AccessibilityInfo, Modal, Platform, Pressable, ScrollView, View, type ScrollViewProps, type ViewStyle } from "react-native";
41
+ import { AccessibilityInfo, Dimensions, KeyboardAvoidingView, Modal, Platform, Pressable, ScrollView, View, type ScrollViewProps, type ViewStyle } from "react-native";
40
42
  import { SafeAreaProvider, useSafeAreaInsets } from "react-native-safe-area-context";
41
43
  import { useThemeRoles } from "../hooks/use-theme-roles";
42
44
 
@@ -51,6 +53,14 @@ export interface NativeSheetProps {
51
53
  initialSnapIndex?: number;
52
54
  /** Keep the sheet open when the user taps the backdrop, swipes it down or presses Android back. Default false. */
53
55
  disableBackdropDismiss?: boolean;
56
+ /**
57
+ * As tall as its content (up to 90% of the screen) instead of the full page sheet, for a short
58
+ * menu or form. On iOS this is a bottom panel over a scrim, like Android's (a tap on the scrim
59
+ * or the VoiceOver escape gesture closes it; it doesn't follow a swipe down), and it moves above
60
+ * the keyboard. Under `NativeSheetProvider` the library sizes it (`enableDynamicSizing`) and
61
+ * `snapPoints` is ignored. Default false.
62
+ */
63
+ fitContent?: boolean;
54
64
  children: ReactNode;
55
65
  testID?: string;
56
66
  }
@@ -156,6 +166,7 @@ function LibrarySheet({
156
166
  snapPoints = ["50%", "90%"],
157
167
  initialSnapIndex = 0,
158
168
  disableBackdropDismiss = false,
169
+ fitContent = false,
159
170
  testID,
160
171
  children,
161
172
  }: NativeSheetProps & { library: NativeSheetLibrary }) {
@@ -198,10 +209,13 @@ function LibrarySheet({
198
209
  return (
199
210
  <BottomSheetModal
200
211
  ref={sheet}
201
- snapPoints={snapPoints}
202
- index={initialSnapIndex}
203
- // v5 sizes to the content by default and adds that as a snap point, which would shift the indexes.
204
- enableDynamicSizing={false}
212
+ snapPoints={fitContent ? undefined : snapPoints}
213
+ index={fitContent ? 0 : initialSnapIndex}
214
+ // v5 sizes to the content by default and adds that as a snap point, which would shift the
215
+ // indexes: only a sheet that fits its content asks for it, and then it is the only one.
216
+ enableDynamicSizing={fitContent}
217
+ // Long content would otherwise grow the sheet to the full height, under the status bar.
218
+ {...(fitContent ? { maxDynamicContentSize: Math.round(Dimensions.get("window").height * 0.9) } : {})}
205
219
  onDismiss={onDismiss}
206
220
  enablePanDownToClose={!disableBackdropDismiss}
207
221
  backdropComponent={backdrop}
@@ -238,9 +252,10 @@ function useReduceMotionAnswer(): boolean | null {
238
252
  * sheet (`presentationStyle="pageSheet"`), following the finger when swiped
239
253
  * down (`allowSwipeDismissal`); with `disableBackdropDismiss` a swipe only
240
254
  * asks and the sheet springs back. Android: a transparent modal with a scrim
241
- * and a panel at the bottom, drawn under the system bars.
255
+ * and a panel at the bottom, drawn under the system bars. `fitContent` on iOS: the same bottom
256
+ * panel, kept above the keyboard.
242
257
  */
243
- function ModalSheet({ open, onOpenChange, disableBackdropDismiss = false, testID, children }: NativeSheetProps) {
258
+ function ModalSheet({ open, onOpenChange, disableBackdropDismiss = false, fitContent = false, testID, children }: NativeSheetProps) {
244
259
  const reducedMotion = useReduceMotionAnswer();
245
260
  const roles = useThemeRoles();
246
261
  const requestClose = () => {
@@ -250,7 +265,8 @@ function ModalSheet({ open, onOpenChange, disableBackdropDismiss = false, testID
250
265
  const animationType = reducedMotion ? "none" : "slide";
251
266
  const id = testID ?? "native-sheet";
252
267
 
253
- if (Platform.OS === "ios") {
268
+ const ios = Platform.OS === "ios";
269
+ if (ios && !fitContent) {
254
270
  return (
255
271
  <Modal
256
272
  visible={visible}
@@ -283,7 +299,7 @@ function ModalSheet({ open, onOpenChange, disableBackdropDismiss = false, testID
283
299
  onRequestClose={requestClose}
284
300
  >
285
301
  <SafeAreaProvider>
286
- <View style={{ flex: 1, justifyContent: "flex-end" }}>
302
+ <KeyboardPanel ios={ios}>
287
303
  <Pressable
288
304
  testID={`${id}-backdrop`}
289
305
  accessibilityRole="button"
@@ -295,6 +311,7 @@ function ModalSheet({ open, onOpenChange, disableBackdropDismiss = false, testID
295
311
  />
296
312
  <SheetBody
297
313
  testID={id}
314
+ onAccessibilityEscape={disableBackdropDismiss ? undefined : requestClose}
298
315
  style={{
299
316
  maxHeight: "90%",
300
317
  borderTopLeftRadius: 28,
@@ -308,12 +325,25 @@ function ModalSheet({ open, onOpenChange, disableBackdropDismiss = false, testID
308
325
  />
309
326
  {children}
310
327
  </SheetBody>
311
- </View>
328
+ </KeyboardPanel>
312
329
  </SafeAreaProvider>
313
330
  </Modal>
314
331
  );
315
332
  }
316
333
 
334
+ /**
335
+ * The bottom panel's frame: on iOS it moves up with the keyboard, less the home indicator's
336
+ * inset the sheet already pads, so it sits on the keyboard without a gap.
337
+ */
338
+ function KeyboardPanel({ ios, children }: { ios: boolean; children: ReactNode }) {
339
+ const insets = useSafeAreaInsets();
340
+ return (
341
+ <KeyboardAvoidingView behavior={ios ? "padding" : undefined} keyboardVerticalOffset={ios ? -insets.bottom : 0} style={{ flex: 1, justifyContent: "flex-end" }}>
342
+ {children}
343
+ </KeyboardAvoidingView>
344
+ );
345
+ }
346
+
317
347
  /** The sheet's root, padded by the sheet's own bottom inset (the home indicator, the navigation bar). */
318
348
  function SheetBody({
319
349
  testID,