@marktiderman/genesis-ui-native 3.10.0 → 3.11.0
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/data/index.d.ts +10 -2
- package/dist/data/index.js +9 -4
- package/dist/data/index.js.map +1 -1
- package/package.json +3 -3
- package/src/data/resource-view/NativeResourceView.tsx +17 -2
- package/src/data/resource-view/__tests__/native-resource-gallery.test.tsx +8 -0
- package/src/data/resource-view/index.ts +1 -0
- package/src/data/resource-view/mapping.ts +4 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marktiderman/genesis-ui-native",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.11.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -83,8 +83,8 @@
|
|
|
83
83
|
"@expo/ui": ">=58.0.0",
|
|
84
84
|
"@gorhom/bottom-sheet": ">=5.0.0",
|
|
85
85
|
"@hookform/resolvers": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0",
|
|
86
|
-
"@marktiderman/genesis-core": "^2.
|
|
87
|
-
"@marktiderman/genesis-design-system": "^1.
|
|
86
|
+
"@marktiderman/genesis-core": "^2.15.0",
|
|
87
|
+
"@marktiderman/genesis-design-system": "^1.11.0",
|
|
88
88
|
"@react-native-community/datetimepicker": ">=8.0.0",
|
|
89
89
|
"@shopify/flash-list": ">=2.0.0",
|
|
90
90
|
"@tanstack/react-query": "^5.0.0",
|
|
@@ -67,6 +67,9 @@ export type NativeResourceSwipeableProps = Omit<InboxPageSlotMap["swipeable"], "
|
|
|
67
67
|
/** How rows show: a list (the default) or cards in columns, as the web's `mode`. */
|
|
68
68
|
export type NativeResourceViewMode = "list" | "grid";
|
|
69
69
|
|
|
70
|
+
/** The view types the phone draws: list, grid and gallery (ADR 0021). @stability Beta */
|
|
71
|
+
export type NativeResourceViewType = NativeResourceViewMode | "gallery";
|
|
72
|
+
|
|
70
73
|
/**
|
|
71
74
|
* Spread onto your card's Pressable: the press (the screen's `onRowPress`, else the peek), the
|
|
72
75
|
* long press (the row's actions), and the label and actions screen readers use. The same wiring
|
|
@@ -118,9 +121,15 @@ export interface NativeResourceViewProps<T extends Row = Row> extends NativeReso
|
|
|
118
121
|
/**
|
|
119
122
|
* `"grid"`: cards in `numColumns` columns, as the web's `mode="grid"`. Sections, paging, pull to
|
|
120
123
|
* refresh, the empty and error states, long press, accessibility and swipe actions all stay.
|
|
121
|
-
* Default `"list"`.
|
|
124
|
+
* Default `"list"`. Prefer `type`; `mode` stays as its alias.
|
|
122
125
|
*/
|
|
123
126
|
mode?: NativeResourceViewMode;
|
|
127
|
+
/**
|
|
128
|
+
* The view type (ADR 0021), as the web's `<ResourceView type>`: `"list"` (default), `"grid"`, or
|
|
129
|
+
* `"gallery"` (the grid as photos, from the view's `gallery` block). The phone has no board or
|
|
130
|
+
* calendar yet. Wins over `mode`.
|
|
131
|
+
*/
|
|
132
|
+
type?: NativeResourceViewType;
|
|
124
133
|
/** Columns in grid mode (React Native's FlatList name). Default 2. */
|
|
125
134
|
numColumns?: number;
|
|
126
135
|
/**
|
|
@@ -466,7 +475,8 @@ function Screen<T extends Row = Row>(props: NativeResourceViewProps<T>) {
|
|
|
466
475
|
header,
|
|
467
476
|
emptyState,
|
|
468
477
|
searchable,
|
|
469
|
-
mode = "list",
|
|
478
|
+
mode: modeProp = "list",
|
|
479
|
+
type,
|
|
470
480
|
numColumns: columnsProp,
|
|
471
481
|
gallery: screenGallery,
|
|
472
482
|
renderCard,
|
|
@@ -474,6 +484,11 @@ function Screen<T extends Row = Row>(props: NativeResourceViewProps<T>) {
|
|
|
474
484
|
testID = "native-resource-view",
|
|
475
485
|
...options
|
|
476
486
|
} = props;
|
|
487
|
+
// `type` is the view type's name (ADR 0021); `mode` its alias. A gallery is the grid as photos.
|
|
488
|
+
const mode: NativeResourceViewMode = type === "gallery" ? "grid" : (type ?? modeProp);
|
|
489
|
+
if (type === "gallery" && !view.definition.gallery && !screenGallery?.image) {
|
|
490
|
+
throw new Error(`NativeResourceView(${view.resource}): type="gallery" needs a gallery block: the view's gallery.image, or gallery={{ image }}`);
|
|
491
|
+
}
|
|
477
492
|
void _zone;
|
|
478
493
|
const state = useNativeResourceView<T>(view, options);
|
|
479
494
|
const keyExtractor = useCallback((row: T) => recordKey(view as AnyResourceView<Row>, row), [view]);
|
|
@@ -122,4 +122,12 @@ describe("NativeResourceView gallery", () => {
|
|
|
122
122
|
await waitFor(() => expect(tile("p1")).not.toBeNull());
|
|
123
123
|
expect(tile("p3")).not.toBeNull();
|
|
124
124
|
});
|
|
125
|
+
|
|
126
|
+
it("takes the view type as `type` (ADR 0021): gallery is the grid as photos, and needs a gallery block", async () => {
|
|
127
|
+
render(<NativeResourceView view={view} type="gallery" onRowPress={() => undefined} />, { wrapper: wrap(provider()) });
|
|
128
|
+
await measured();
|
|
129
|
+
await waitFor(() => expect(tile("p1")).not.toBeNull());
|
|
130
|
+
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
131
|
+
expect(() => render(<NativeResourceView view={plain} type="gallery" />, { wrapper: wrap(provider()) })).toThrow(/needs a gallery block/);
|
|
132
|
+
});
|
|
125
133
|
});
|
|
@@ -228,11 +228,11 @@ export interface NativeFormField {
|
|
|
228
228
|
/** Choices that fit a segmented control; more go to a list. */
|
|
229
229
|
const SEGMENTED_MAX = 4;
|
|
230
230
|
|
|
231
|
-
function kindFor(display: DisplayHint, options: unknown[] | undefined,
|
|
231
|
+
function kindFor(display: DisplayHint, options: unknown[] | undefined, control?: string): NativeFormFieldKind {
|
|
232
232
|
if (options) return options.length <= SEGMENTED_MAX ? "segmented" : "select";
|
|
233
|
-
// A phone number shows as text, so only the contract's `
|
|
233
|
+
// A phone number shows as text, so only the contract's `control: "tel"` (or its older `widget`) makes it one (as on the
|
|
234
234
|
// web); a column's name is never read as a type.
|
|
235
|
-
if (
|
|
235
|
+
if (control === "tel" && display === "text") return "tel";
|
|
236
236
|
switch (display) {
|
|
237
237
|
case "boolean":
|
|
238
238
|
return "switch";
|
|
@@ -311,7 +311,7 @@ export function formFieldsFor<T extends Row>(
|
|
|
311
311
|
return {
|
|
312
312
|
key: f.field.name,
|
|
313
313
|
label: f.label,
|
|
314
|
-
kind: link ? ("link" as const) : kindFor(f.display, options, f.field.widget),
|
|
314
|
+
kind: link ? ("link" as const) : kindFor(f.display, options, f.field.control ?? f.field.widget),
|
|
315
315
|
display: f.display,
|
|
316
316
|
required: !readOnly && f.required,
|
|
317
317
|
readOnly,
|