@baukit/navigation 0.7.4 → 0.8.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/README.md +29 -3
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/native.d.ts +4 -3
- package/dist/native.d.ts.map +1 -1
- package/dist/native.js +84 -16
- package/dist/native.js.map +1 -1
- package/dist/web.css +71 -7
- package/dist/web.d.ts +5 -3
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +63 -37
- package/dist/web.js.map +1 -1
- package/package.json +3 -3
- package/src/index.test.ts +13 -0
- package/src/index.ts +15 -1
- package/src/native.browser.test.tsx +45 -0
- package/src/native.test.tsx +287 -2
- package/src/native.tsx +112 -17
- package/src/web.browser.test.tsx +230 -12
- package/src/web.css +71 -7
- package/src/web.test.tsx +106 -1
- package/src/web.tsx +122 -61
package/src/native.test.tsx
CHANGED
|
@@ -24,6 +24,10 @@ for (const name of [
|
|
|
24
24
|
Reflect.get(nativeModules, name);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
jest.restoreAllMocks();
|
|
29
|
+
});
|
|
30
|
+
|
|
27
31
|
const labels = {
|
|
28
32
|
label: 'Primary',
|
|
29
33
|
collapseLabel: 'Collapse navigation',
|
|
@@ -47,6 +51,7 @@ const theme: NavigationTheme = {
|
|
|
47
51
|
background: '#fff',
|
|
48
52
|
text: '#111',
|
|
49
53
|
muted: '#595959',
|
|
54
|
+
danger: '#b3261e',
|
|
50
55
|
activeBackground: '#dbe9f8',
|
|
51
56
|
activeText: '#005fcc',
|
|
52
57
|
ancestorText: '#004799',
|
|
@@ -393,6 +398,7 @@ it('uses roving tab stops for Arrow, Home and End', async () => {
|
|
|
393
398
|
expect(screen.getByRole('link', { name: 'Home' })).toHaveProp('tabIndex', 0);
|
|
394
399
|
});
|
|
395
400
|
it('opens a profile menu, runs an entry and closes', async () => {
|
|
401
|
+
jest.replaceProperty(Platform, 'OS', 'android');
|
|
396
402
|
const action = jest.fn();
|
|
397
403
|
await render(
|
|
398
404
|
<AppNavigation
|
|
@@ -412,10 +418,18 @@ it('opens a profile menu, runs an entry and closes', async () => {
|
|
|
412
418
|
await fireEvent.press(screen.getByRole('button', { name: 'Account' }), event());
|
|
413
419
|
expect(screen.getByRole('menuitem', { name: 'Sign out' })).toBeOnTheScreen();
|
|
414
420
|
await fireEvent.press(screen.getByRole('menuitem', { name: 'Sign out' }), event());
|
|
421
|
+
await act(async () => {
|
|
422
|
+
await new Promise<void>((resolve) =>
|
|
423
|
+
requestAnimationFrame(() => {
|
|
424
|
+
resolve();
|
|
425
|
+
}),
|
|
426
|
+
);
|
|
427
|
+
});
|
|
415
428
|
expect(action).toHaveBeenCalledTimes(1);
|
|
416
429
|
expect(screen.queryByRole('menuitem')).toBeNull();
|
|
417
430
|
});
|
|
418
431
|
it('shows a full-width section picker and navigates directly to a subpage', async () => {
|
|
432
|
+
jest.replaceProperty(Platform, 'OS', 'android');
|
|
419
433
|
const navigate = jest.fn();
|
|
420
434
|
await render(
|
|
421
435
|
<SectionPicker
|
|
@@ -428,6 +442,13 @@ it('shows a full-width section picker and navigates directly to a subpage', asyn
|
|
|
428
442
|
);
|
|
429
443
|
await fireEvent.press(screen.getByRole('button', { name: 'Progress, Overview' }), event());
|
|
430
444
|
await fireEvent.press(screen.getByRole('menuitem', { name: 'History' }), event());
|
|
445
|
+
await act(async () => {
|
|
446
|
+
await new Promise<void>((resolve) =>
|
|
447
|
+
requestAnimationFrame(() => {
|
|
448
|
+
resolve();
|
|
449
|
+
}),
|
|
450
|
+
);
|
|
451
|
+
});
|
|
431
452
|
expect(navigate).toHaveBeenCalledWith('/progress/history');
|
|
432
453
|
expect(screen.queryByRole('menuitem')).toBeNull();
|
|
433
454
|
});
|
|
@@ -848,8 +869,14 @@ it.each([
|
|
|
848
869
|
},
|
|
849
870
|
);
|
|
850
871
|
|
|
851
|
-
function ReservedHeight({
|
|
852
|
-
|
|
872
|
+
function ReservedHeight({
|
|
873
|
+
theme,
|
|
874
|
+
slotHeight = 0,
|
|
875
|
+
}: {
|
|
876
|
+
readonly theme?: NavigationTheme;
|
|
877
|
+
readonly slotHeight?: number;
|
|
878
|
+
}) {
|
|
879
|
+
return <Text testID="reserved-height">{useNavigationBarHeight(24, theme, slotHeight)}</Text>;
|
|
853
880
|
}
|
|
854
881
|
|
|
855
882
|
it.each([1, 1.3, 2])('reserves compact navigation space at font scale %s', async (fontScale) => {
|
|
@@ -946,3 +973,261 @@ it('uses the same custom typography and spacing in the bar and height hook', asy
|
|
|
946
973
|
expect(screen.getByText('Account')).toHaveStyle({ fontSize: 18, lineHeight: 30 });
|
|
947
974
|
jest.restoreAllMocks();
|
|
948
975
|
});
|
|
976
|
+
|
|
977
|
+
it.each(['android', 'ios'] as const)(
|
|
978
|
+
'runs profile navigation and actions after %s dismissal',
|
|
979
|
+
async (platform) => {
|
|
980
|
+
jest.replaceProperty(Platform, 'OS', platform);
|
|
981
|
+
let dismiss: (() => void) | undefined;
|
|
982
|
+
const OriginalModal = nativeModules.Modal;
|
|
983
|
+
class ObservedModal extends OriginalModal {
|
|
984
|
+
override render() {
|
|
985
|
+
dismiss = this.props.onDismiss;
|
|
986
|
+
return super.render();
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
jest.spyOn(nativeModules, 'Modal', 'get').mockReturnValue(ObservedModal);
|
|
990
|
+
const frames: FrameRequestCallback[] = [];
|
|
991
|
+
jest.spyOn(globalThis, 'requestAnimationFrame').mockImplementation((callback) => {
|
|
992
|
+
frames.push(callback);
|
|
993
|
+
return frames.length;
|
|
994
|
+
});
|
|
995
|
+
jest.spyOn(globalThis, 'cancelAnimationFrame').mockImplementation(() => undefined);
|
|
996
|
+
const navigate = jest.fn(() => {
|
|
997
|
+
expect(screen.queryByRole('menu')).toBeNull();
|
|
998
|
+
});
|
|
999
|
+
const action = jest.fn(() => {
|
|
1000
|
+
expect(screen.queryByRole('menu')).toBeNull();
|
|
1001
|
+
});
|
|
1002
|
+
await render(
|
|
1003
|
+
<AppNavigation
|
|
1004
|
+
{...labels}
|
|
1005
|
+
items={items}
|
|
1006
|
+
pathname="/"
|
|
1007
|
+
theme={theme}
|
|
1008
|
+
onNavigate={navigate}
|
|
1009
|
+
profile={{
|
|
1010
|
+
label: 'Account',
|
|
1011
|
+
initials: 'AB',
|
|
1012
|
+
menu: [
|
|
1013
|
+
{ id: 'settings', label: 'Settings', href: '/settings' },
|
|
1014
|
+
{ id: 'signout', label: 'Sign out', onSelect: action },
|
|
1015
|
+
],
|
|
1016
|
+
}}
|
|
1017
|
+
/>,
|
|
1018
|
+
);
|
|
1019
|
+
for (const name of ['Settings', 'Sign out']) {
|
|
1020
|
+
await fireEvent.press(screen.getByRole('button', { name: 'Account' }), event());
|
|
1021
|
+
await fireEvent.press(screen.getByRole('menuitem', { name }), event());
|
|
1022
|
+
expect(navigate).toHaveBeenCalledTimes(name === 'Settings' ? 0 : 1);
|
|
1023
|
+
expect(action).not.toHaveBeenCalled();
|
|
1024
|
+
expect(screen.queryByRole('menu')).toBeNull();
|
|
1025
|
+
if (platform === 'ios') {
|
|
1026
|
+
expect(dismiss).toBeDefined();
|
|
1027
|
+
await act(() => {
|
|
1028
|
+
dismiss?.();
|
|
1029
|
+
});
|
|
1030
|
+
await act(() => {
|
|
1031
|
+
dismiss?.();
|
|
1032
|
+
});
|
|
1033
|
+
} else {
|
|
1034
|
+
expect(frames).toHaveLength(name === 'Settings' ? 1 : 2);
|
|
1035
|
+
await act(() => {
|
|
1036
|
+
frames.at(-1)?.(0);
|
|
1037
|
+
});
|
|
1038
|
+
await act(() => {
|
|
1039
|
+
frames.at(-1)?.(0);
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
expect(navigate).toHaveBeenCalledTimes(1);
|
|
1044
|
+
expect(navigate).toHaveBeenCalledWith('/settings');
|
|
1045
|
+
expect(action).toHaveBeenCalledTimes(1);
|
|
1046
|
+
jest.restoreAllMocks();
|
|
1047
|
+
},
|
|
1048
|
+
);
|
|
1049
|
+
|
|
1050
|
+
it('cancels a queued selection when navigation unmounts', async () => {
|
|
1051
|
+
jest.replaceProperty(Platform, 'OS', 'android');
|
|
1052
|
+
let frame: FrameRequestCallback | undefined;
|
|
1053
|
+
jest.spyOn(globalThis, 'requestAnimationFrame').mockImplementation((callback) => {
|
|
1054
|
+
frame = callback;
|
|
1055
|
+
return 42;
|
|
1056
|
+
});
|
|
1057
|
+
const cancel = jest.spyOn(globalThis, 'cancelAnimationFrame').mockImplementation(() => undefined);
|
|
1058
|
+
const navigate = jest.fn();
|
|
1059
|
+
const view = await render(
|
|
1060
|
+
<SectionPicker
|
|
1061
|
+
closeLabel="Close"
|
|
1062
|
+
item={section}
|
|
1063
|
+
pathname="/progress"
|
|
1064
|
+
theme={theme}
|
|
1065
|
+
onNavigate={navigate}
|
|
1066
|
+
/>,
|
|
1067
|
+
);
|
|
1068
|
+
await fireEvent.press(screen.getByRole('button', { name: 'Progress, Overview' }), event());
|
|
1069
|
+
await fireEvent.press(screen.getByRole('menuitem', { name: 'History' }), event());
|
|
1070
|
+
expect(navigate).not.toHaveBeenCalled();
|
|
1071
|
+
await view.unmount();
|
|
1072
|
+
expect(cancel).toHaveBeenCalledWith(42);
|
|
1073
|
+
await act(() => {
|
|
1074
|
+
frame?.(0);
|
|
1075
|
+
});
|
|
1076
|
+
expect(navigate).not.toHaveBeenCalled();
|
|
1077
|
+
jest.restoreAllMocks();
|
|
1078
|
+
});
|
|
1079
|
+
|
|
1080
|
+
it.each([false, true])(
|
|
1081
|
+
'renders danger menu text on the background, selected=%s',
|
|
1082
|
+
async (selected) => {
|
|
1083
|
+
await render(
|
|
1084
|
+
<AppNavigation
|
|
1085
|
+
{...labels}
|
|
1086
|
+
items={items}
|
|
1087
|
+
theme={theme}
|
|
1088
|
+
pathname={selected ? '/delete' : '/'}
|
|
1089
|
+
onNavigate={jest.fn()}
|
|
1090
|
+
profile={{
|
|
1091
|
+
label: 'Account',
|
|
1092
|
+
initials: 'AB',
|
|
1093
|
+
menu: [{ id: 'delete', label: 'Delete account', tone: 'danger', href: '/delete' }],
|
|
1094
|
+
}}
|
|
1095
|
+
/>,
|
|
1096
|
+
);
|
|
1097
|
+
await fireEvent.press(screen.getByRole('button', { name: 'Account' }), event());
|
|
1098
|
+
const entry = screen.getByRole('menuitem', { name: 'Delete account' });
|
|
1099
|
+
expect(entry).toHaveStyle({ backgroundColor: theme.background });
|
|
1100
|
+
expect(within(entry).getByText('Delete account')).toHaveStyle({ color: theme.danger });
|
|
1101
|
+
expect(entry).toHaveProp('accessibilityState', { disabled: false, selected });
|
|
1102
|
+
},
|
|
1103
|
+
);
|
|
1104
|
+
|
|
1105
|
+
it.each(
|
|
1106
|
+
[1, 2].flatMap((fontScale) => [
|
|
1107
|
+
{ width: 320, collapsed: false, fontScale },
|
|
1108
|
+
{ width: 1024, collapsed: false, fontScale },
|
|
1109
|
+
{ width: 1024, collapsed: true, fontScale },
|
|
1110
|
+
]),
|
|
1111
|
+
)(
|
|
1112
|
+
'renders brand and accessory at $width, collapsed=$collapsed, font scale $fontScale',
|
|
1113
|
+
async ({ width, collapsed, fontScale }) => {
|
|
1114
|
+
jest
|
|
1115
|
+
.spyOn(nativeModules, 'useWindowDimensions')
|
|
1116
|
+
.mockReturnValue({ width, height: 900, scale: 1, fontScale });
|
|
1117
|
+
const renderBrand = jest.fn(({ collapsed: small }: { collapsed: boolean }) => (
|
|
1118
|
+
<Text>{small ? 'B' : 'Baukit'}</Text>
|
|
1119
|
+
));
|
|
1120
|
+
const renderAccessory = jest.fn(() => <Text accessibilityRole="text">Workout active</Text>);
|
|
1121
|
+
const changed = jest.fn();
|
|
1122
|
+
await render(
|
|
1123
|
+
<AppNavigation
|
|
1124
|
+
{...labels}
|
|
1125
|
+
width={width}
|
|
1126
|
+
collapsed={collapsed}
|
|
1127
|
+
items={items}
|
|
1128
|
+
pathname="/"
|
|
1129
|
+
theme={theme}
|
|
1130
|
+
onNavigate={jest.fn()}
|
|
1131
|
+
renderBrand={renderBrand}
|
|
1132
|
+
renderAccessory={renderAccessory}
|
|
1133
|
+
onBarHeightChange={changed}
|
|
1134
|
+
/>,
|
|
1135
|
+
);
|
|
1136
|
+
const layout = width === 320 ? 'bar' : 'rail';
|
|
1137
|
+
expect(renderBrand).toHaveBeenCalledWith({ layout, collapsed });
|
|
1138
|
+
expect(renderAccessory).toHaveBeenCalledWith({ layout, collapsed });
|
|
1139
|
+
expect(screen.getByText(collapsed ? 'B' : 'Baukit')).toBeOnTheScreen();
|
|
1140
|
+
expect(screen.getByText('Workout active')).toBeOnTheScreen();
|
|
1141
|
+
if (layout === 'bar') {
|
|
1142
|
+
expect(screen.getByTestId('navigation-items')).toHaveStyle({
|
|
1143
|
+
height: getNavigationBarHeight(fontScale) - 1,
|
|
1144
|
+
});
|
|
1145
|
+
await fireEvent(screen.getByTestId('navigation-slots'), 'layout', {
|
|
1146
|
+
nativeEvent: { layout: { x: 0, y: 0, width: 320, height: 52 } },
|
|
1147
|
+
});
|
|
1148
|
+
expect(screen.getByTestId('primary-navigation')).toHaveStyle({
|
|
1149
|
+
minHeight: getNavigationBarHeight(fontScale, 0, { slotHeight: 52 }),
|
|
1150
|
+
});
|
|
1151
|
+
expect(changed).toHaveBeenLastCalledWith(
|
|
1152
|
+
getNavigationBarHeight(fontScale, 0, { slotHeight: 52 }),
|
|
1153
|
+
);
|
|
1154
|
+
} else expect(changed).not.toHaveBeenCalled();
|
|
1155
|
+
},
|
|
1156
|
+
);
|
|
1157
|
+
|
|
1158
|
+
it('drops a queued action if the menu reopens before the dismissal frame', async () => {
|
|
1159
|
+
jest.replaceProperty(Platform, 'OS', 'android');
|
|
1160
|
+
const frames: FrameRequestCallback[] = [];
|
|
1161
|
+
jest.spyOn(globalThis, 'requestAnimationFrame').mockImplementation((callback) => {
|
|
1162
|
+
frames.push(callback);
|
|
1163
|
+
return frames.length;
|
|
1164
|
+
});
|
|
1165
|
+
const cancel = jest.spyOn(globalThis, 'cancelAnimationFrame').mockImplementation(() => undefined);
|
|
1166
|
+
const action = jest.fn();
|
|
1167
|
+
await render(
|
|
1168
|
+
<AppNavigation
|
|
1169
|
+
{...labels}
|
|
1170
|
+
items={items}
|
|
1171
|
+
theme={theme}
|
|
1172
|
+
pathname="/"
|
|
1173
|
+
onNavigate={jest.fn()}
|
|
1174
|
+
profile={{
|
|
1175
|
+
label: 'Account',
|
|
1176
|
+
initials: 'AB',
|
|
1177
|
+
menu: [{ id: 'signout', label: 'Sign out', onSelect: action }],
|
|
1178
|
+
}}
|
|
1179
|
+
/>,
|
|
1180
|
+
);
|
|
1181
|
+
await fireEvent.press(screen.getByRole('button', { name: 'Account' }), event());
|
|
1182
|
+
await fireEvent.press(screen.getByRole('menuitem', { name: 'Sign out' }), event());
|
|
1183
|
+
await fireEvent.press(screen.getByRole('button', { name: 'Account' }), event());
|
|
1184
|
+
expect(cancel).toHaveBeenCalledWith(1);
|
|
1185
|
+
await act(() => {
|
|
1186
|
+
frames[0]?.(0);
|
|
1187
|
+
});
|
|
1188
|
+
expect(action).not.toHaveBeenCalled();
|
|
1189
|
+
await fireEvent.press(screen.getByRole('menuitem', { name: 'Sign out' }), event());
|
|
1190
|
+
await act(() => {
|
|
1191
|
+
frames[1]?.(0);
|
|
1192
|
+
});
|
|
1193
|
+
expect(action).toHaveBeenCalledTimes(1);
|
|
1194
|
+
});
|
|
1195
|
+
|
|
1196
|
+
it('reserves measured slot height through the native height hook at 200%', async () => {
|
|
1197
|
+
jest
|
|
1198
|
+
.spyOn(nativeModules, 'useWindowDimensions')
|
|
1199
|
+
.mockReturnValue({ width: 320, height: 900, scale: 1, fontScale: 2 });
|
|
1200
|
+
await render(<ReservedHeight slotHeight={64} />);
|
|
1201
|
+
expect(screen.getByTestId('reserved-height').props['children']).toBe(
|
|
1202
|
+
getNavigationBarHeight(2, 24, { slotHeight: 64 }),
|
|
1203
|
+
);
|
|
1204
|
+
});
|
|
1205
|
+
|
|
1206
|
+
it('removes slot height when conditional content disappears', async () => {
|
|
1207
|
+
jest
|
|
1208
|
+
.spyOn(nativeModules, 'useWindowDimensions')
|
|
1209
|
+
.mockReturnValue({ width: 320, height: 900, scale: 1, fontScale: 1 });
|
|
1210
|
+
const props = {
|
|
1211
|
+
...labels,
|
|
1212
|
+
items,
|
|
1213
|
+
theme,
|
|
1214
|
+
pathname: '/',
|
|
1215
|
+
onNavigate: jest.fn(),
|
|
1216
|
+
onBarHeightChange: jest.fn(),
|
|
1217
|
+
};
|
|
1218
|
+
await render(<AppNavigation {...props} renderBrand={() => <Text>Baukit</Text>} />);
|
|
1219
|
+
await fireEvent(screen.getByTestId('navigation-slots'), 'layout', {
|
|
1220
|
+
nativeEvent: { layout: { x: 0, y: 0, width: 320, height: 52 } },
|
|
1221
|
+
});
|
|
1222
|
+
expect(props.onBarHeightChange).toHaveBeenLastCalledWith(
|
|
1223
|
+
getNavigationBarHeight(1, 0, { slotHeight: 52 }),
|
|
1224
|
+
);
|
|
1225
|
+
await screen.rerender(
|
|
1226
|
+
<AppNavigation {...props} renderBrand={() => null} renderAccessory={() => false} />,
|
|
1227
|
+
);
|
|
1228
|
+
expect(screen.queryByTestId('navigation-slots')).toBeNull();
|
|
1229
|
+
expect(screen.getByTestId('primary-navigation')).toHaveStyle({
|
|
1230
|
+
minHeight: getNavigationBarHeight(),
|
|
1231
|
+
});
|
|
1232
|
+
expect(props.onBarHeightChange).toHaveBeenLastCalledWith(getNavigationBarHeight());
|
|
1233
|
+
});
|
package/src/native.tsx
CHANGED
|
@@ -44,6 +44,7 @@ import {
|
|
|
44
44
|
getNavigationBarLineHeight,
|
|
45
45
|
NAVIGATION_BAR_DIMENSIONS,
|
|
46
46
|
type NavigationBarMetrics,
|
|
47
|
+
type NavigationSlots,
|
|
47
48
|
NAVIGATION_DIMENSIONS,
|
|
48
49
|
navigationMatches,
|
|
49
50
|
nextSectionHref,
|
|
@@ -76,6 +77,7 @@ export interface NavigationTheme {
|
|
|
76
77
|
readonly background: string;
|
|
77
78
|
readonly text: string;
|
|
78
79
|
readonly muted: string;
|
|
80
|
+
readonly danger: string;
|
|
79
81
|
readonly activeBackground: string;
|
|
80
82
|
readonly activeText: string;
|
|
81
83
|
readonly ancestorText: string;
|
|
@@ -346,6 +348,30 @@ function Menu({
|
|
|
346
348
|
const closeRef = useRef<View>(null);
|
|
347
349
|
const pendingFocus = useRef<(() => void) | null>(null);
|
|
348
350
|
const presented = useRef(false);
|
|
351
|
+
const pendingSelection = useRef<(() => void) | null>(null);
|
|
352
|
+
const finishSelection = useCallback(() => {
|
|
353
|
+
const selection = pendingSelection.current;
|
|
354
|
+
pendingSelection.current = null;
|
|
355
|
+
selection?.();
|
|
356
|
+
}, []);
|
|
357
|
+
useEffect(() => {
|
|
358
|
+
if (visible) {
|
|
359
|
+
pendingSelection.current = null;
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
if (Platform.OS === 'ios' || pendingSelection.current === null) return;
|
|
363
|
+
// Android removes an unanimated Modal in the close commit and has no onDismiss event.
|
|
364
|
+
const frame = requestAnimationFrame(finishSelection);
|
|
365
|
+
return () => {
|
|
366
|
+
cancelAnimationFrame(frame);
|
|
367
|
+
};
|
|
368
|
+
}, [visible, finishSelection]);
|
|
369
|
+
useEffect(
|
|
370
|
+
() => () => {
|
|
371
|
+
pendingSelection.current = null;
|
|
372
|
+
},
|
|
373
|
+
[],
|
|
374
|
+
);
|
|
349
375
|
const [webPresented, setWebPresented] = useState(false);
|
|
350
376
|
const [webPosition, setWebPosition] = useState<ViewStyle>();
|
|
351
377
|
const deferFocus = useCallback((task: () => void) => {
|
|
@@ -485,7 +511,7 @@ function Menu({
|
|
|
485
511
|
<FocusablePressable
|
|
486
512
|
theme={theme}
|
|
487
513
|
selected={entry === activeEntry}
|
|
488
|
-
{...{ dataSet: { active: entry === activeEntry ? 'page' : 'false' } }}
|
|
514
|
+
{...{ dataSet: { active: entry === activeEntry ? 'page' : 'false', tone: entry.tone } }}
|
|
489
515
|
{...roving.itemProps(index)}
|
|
490
516
|
key={entry.id}
|
|
491
517
|
accessibilityRole="menuitem"
|
|
@@ -497,22 +523,35 @@ function Menu({
|
|
|
497
523
|
disabled={entry.disabled}
|
|
498
524
|
{...(entry.href === undefined ? {} : webLink(entry.href, entry === activeEntry))}
|
|
499
525
|
onPress={(event) => {
|
|
500
|
-
if (isModifiedPress(event)) return;
|
|
526
|
+
if (isModifiedPress(event) || pendingSelection.current !== null) return;
|
|
527
|
+
event.preventDefault();
|
|
528
|
+
pendingSelection.current =
|
|
529
|
+
entry.href !== undefined
|
|
530
|
+
? () => {
|
|
531
|
+
onNavigate(entry.href);
|
|
532
|
+
}
|
|
533
|
+
: entry.onSelect;
|
|
501
534
|
closeAndRestore();
|
|
502
|
-
if (entry.href !== undefined) follow(entry.href, event, onNavigate);
|
|
503
|
-
else entry.onSelect();
|
|
504
535
|
}}
|
|
505
536
|
style={[
|
|
506
537
|
styles.menuItem,
|
|
507
538
|
{
|
|
508
539
|
paddingHorizontal: theme.spacing,
|
|
509
|
-
backgroundColor:
|
|
540
|
+
backgroundColor:
|
|
541
|
+
entry === activeEntry && entry.tone !== 'danger'
|
|
542
|
+
? theme.activeBackground
|
|
543
|
+
: theme.background,
|
|
510
544
|
},
|
|
511
545
|
]}
|
|
512
546
|
>
|
|
513
547
|
<Text
|
|
514
548
|
style={{
|
|
515
|
-
color:
|
|
549
|
+
color:
|
|
550
|
+
entry.tone === 'danger'
|
|
551
|
+
? theme.danger
|
|
552
|
+
: entry === activeEntry
|
|
553
|
+
? theme.activeText
|
|
554
|
+
: theme.text,
|
|
516
555
|
...textStyle(theme, entry === activeEntry),
|
|
517
556
|
}}
|
|
518
557
|
>
|
|
@@ -541,6 +580,9 @@ function Menu({
|
|
|
541
580
|
transparent
|
|
542
581
|
animationType="none"
|
|
543
582
|
onRequestClose={onClose}
|
|
583
|
+
onDismiss={() => {
|
|
584
|
+
if (!visible) finishSelection();
|
|
585
|
+
}}
|
|
544
586
|
onShow={() => {
|
|
545
587
|
if (!visible) return;
|
|
546
588
|
presented.current = true;
|
|
@@ -669,9 +711,13 @@ function Profile({
|
|
|
669
711
|
);
|
|
670
712
|
}
|
|
671
713
|
|
|
672
|
-
export function useNavigationBarHeight(
|
|
714
|
+
export function useNavigationBarHeight(
|
|
715
|
+
bottomInset = 0,
|
|
716
|
+
theme?: NavigationTheme,
|
|
717
|
+
slotHeight = 0,
|
|
718
|
+
): number {
|
|
673
719
|
const { fontScale } = useWindowDimensions();
|
|
674
|
-
return getNavigationBarHeight(fontScale, bottomInset, barMetrics(theme));
|
|
720
|
+
return getNavigationBarHeight(fontScale, bottomInset, { ...barMetrics(theme), slotHeight });
|
|
675
721
|
}
|
|
676
722
|
|
|
677
723
|
function useCompactBarScroll(selectedIndex: number) {
|
|
@@ -715,7 +761,7 @@ function useCompactBarScroll(selectedIndex: number) {
|
|
|
715
761
|
};
|
|
716
762
|
}
|
|
717
763
|
|
|
718
|
-
export interface AppNavigationProps extends CollapseProps {
|
|
764
|
+
export interface AppNavigationProps extends CollapseProps, NavigationSlots {
|
|
719
765
|
readonly items: readonly NavigationItem<NavigationIcon>[];
|
|
720
766
|
readonly profile?: NavigationProfile;
|
|
721
767
|
readonly pathname: string;
|
|
@@ -742,6 +788,7 @@ export function AppNavigation(props: AppNavigationProps) {
|
|
|
742
788
|
collapseLabel,
|
|
743
789
|
expandLabel,
|
|
744
790
|
} = props;
|
|
791
|
+
const [slotHeight, setSlotHeight] = useState(0);
|
|
745
792
|
const [profileOpen, setProfileOpen] = useState(false);
|
|
746
793
|
const profileTriggerRef = useRef<View>(null);
|
|
747
794
|
const profileMenuId = useId();
|
|
@@ -751,6 +798,19 @@ export function AppNavigation(props: AppNavigationProps) {
|
|
|
751
798
|
const bar = getNavigationLayout(props.width ?? dimensions.width) === 'bar';
|
|
752
799
|
const state = useNavigationState(items, pathname, props);
|
|
753
800
|
const collapsed = !bar && state.collapsed;
|
|
801
|
+
const slotState = { layout: bar ? ('bar' as const) : ('rail' as const), collapsed };
|
|
802
|
+
const brand = props.renderBrand?.(slotState);
|
|
803
|
+
const accessory = props.renderAccessory?.(slotState);
|
|
804
|
+
const hasBrand = brand != null && typeof brand !== 'boolean';
|
|
805
|
+
const hasAccessory = accessory != null && typeof accessory !== 'boolean';
|
|
806
|
+
const hasSlots = hasBrand || hasAccessory;
|
|
807
|
+
const barHeight = getNavigationBarHeight(dimensions.fontScale, insets.bottom, {
|
|
808
|
+
...barMetrics(theme),
|
|
809
|
+
slotHeight: hasSlots ? slotHeight : 0,
|
|
810
|
+
});
|
|
811
|
+
useEffect(() => {
|
|
812
|
+
if (bar) props.onBarHeightChange?.(barHeight);
|
|
813
|
+
}, [bar, barHeight, props.onBarHeightChange]);
|
|
754
814
|
const id = useId();
|
|
755
815
|
const visible = items.flatMap((item) =>
|
|
756
816
|
!bar && !collapsed && state.openIds.includes(item.id)
|
|
@@ -788,11 +848,7 @@ export function AppNavigation(props: AppNavigationProps) {
|
|
|
788
848
|
paddingBottom: insets.bottom ?? 0,
|
|
789
849
|
...(bar
|
|
790
850
|
? {
|
|
791
|
-
minHeight:
|
|
792
|
-
dimensions.fontScale,
|
|
793
|
-
insets.bottom,
|
|
794
|
-
barMetrics(theme),
|
|
795
|
-
),
|
|
851
|
+
minHeight: barHeight,
|
|
796
852
|
}
|
|
797
853
|
: {}),
|
|
798
854
|
paddingLeft: insets.left ?? 0,
|
|
@@ -805,6 +861,30 @@ export function AppNavigation(props: AppNavigationProps) {
|
|
|
805
861
|
props.style,
|
|
806
862
|
]}
|
|
807
863
|
>
|
|
864
|
+
{hasSlots ? (
|
|
865
|
+
<View
|
|
866
|
+
testID="navigation-slots"
|
|
867
|
+
style={[
|
|
868
|
+
styles.slots,
|
|
869
|
+
bar && styles.barSlots,
|
|
870
|
+
{ padding: theme.spacing, gap: theme.spacing },
|
|
871
|
+
]}
|
|
872
|
+
onLayout={(event) => {
|
|
873
|
+
if (bar) setSlotHeight(event.nativeEvent.layout.height);
|
|
874
|
+
}}
|
|
875
|
+
>
|
|
876
|
+
{!hasBrand ? null : (
|
|
877
|
+
<View testID="navigation-brand" style={[styles.slot, bar && styles.barBrand]}>
|
|
878
|
+
{brand}
|
|
879
|
+
</View>
|
|
880
|
+
)}
|
|
881
|
+
{!hasAccessory ? null : (
|
|
882
|
+
<View testID="navigation-accessory" style={styles.slot}>
|
|
883
|
+
{accessory}
|
|
884
|
+
</View>
|
|
885
|
+
)}
|
|
886
|
+
</View>
|
|
887
|
+
) : null}
|
|
808
888
|
{!bar ? (
|
|
809
889
|
<Target
|
|
810
890
|
label={collapsed ? expandLabel : collapseLabel}
|
|
@@ -826,7 +906,18 @@ export function AppNavigation(props: AppNavigationProps) {
|
|
|
826
906
|
horizontal={bar}
|
|
827
907
|
scrollEnabled
|
|
828
908
|
showsHorizontalScrollIndicator={false}
|
|
829
|
-
style={
|
|
909
|
+
style={
|
|
910
|
+
bar
|
|
911
|
+
? [
|
|
912
|
+
styles.barItems,
|
|
913
|
+
{
|
|
914
|
+
height:
|
|
915
|
+
getNavigationBarHeight(dimensions.fontScale, 0, barMetrics(theme)) -
|
|
916
|
+
NAVIGATION_BAR_DIMENSIONS.border,
|
|
917
|
+
},
|
|
918
|
+
]
|
|
919
|
+
: styles.railItems
|
|
920
|
+
}
|
|
830
921
|
contentContainerStyle={bar ? styles.barContent : undefined}
|
|
831
922
|
>
|
|
832
923
|
{items.map((item, index) => {
|
|
@@ -1041,14 +1132,18 @@ const styles = StyleSheet.create({
|
|
|
1041
1132
|
collapsedTarget: { justifyContent: 'center' },
|
|
1042
1133
|
barTarget: { flexDirection: 'column', alignItems: 'center', justifyContent: 'center', flex: 1 },
|
|
1043
1134
|
bar: {
|
|
1044
|
-
flexDirection: '
|
|
1135
|
+
flexDirection: 'column',
|
|
1045
1136
|
minHeight: NAVIGATION_DIMENSIONS.nativeBar,
|
|
1046
1137
|
borderTopWidth: NAVIGATION_BAR_DIMENSIONS.border,
|
|
1047
1138
|
width: '100%',
|
|
1048
1139
|
},
|
|
1049
1140
|
rail: { borderRightWidth: 1, height: '100%' },
|
|
1141
|
+
slots: { flexShrink: 0 },
|
|
1142
|
+
barSlots: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' },
|
|
1143
|
+
slot: { minWidth: 0, flexShrink: 1 },
|
|
1144
|
+
barBrand: { flexShrink: 0 },
|
|
1050
1145
|
railItems: { flex: 1 },
|
|
1051
|
-
barItems: { width: '100%' },
|
|
1146
|
+
barItems: { width: '100%', flexGrow: 0, flexShrink: 0 },
|
|
1052
1147
|
barContent: { flexDirection: 'row', flexGrow: 1, minWidth: '100%' },
|
|
1053
1148
|
barSection: { flex: 1, minWidth: NAVIGATION_DIMENSIONS.target },
|
|
1054
1149
|
children: { marginLeft: 20, paddingLeft: 8, borderLeftWidth: 1 },
|