Skip to content

Commit 5abe8a0

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-27944
2 parents 003df33 + 80a2351 commit 5abe8a0

9 files changed

Lines changed: 457 additions & 22 deletions
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { describe, expect, it } from "vite-plus/test";
2+
3+
import { resolveHighlightLanguage } from "./highlightLanguage";
4+
5+
describe("resolveHighlightLanguage", () => {
6+
it.each([
7+
["src/init.luau", "lua"],
8+
["styles/page.xsl", "xml"],
9+
["styles/page.xslt", "xml"],
10+
])("%s highlights as %s", (path, language) => {
11+
expect(resolveHighlightLanguage({ path })).toBe(language);
12+
});
13+
});

‎apps/mobile/src/lib/highlightLanguage.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import "@t3tools/client-runtime/assembly-highlighting";
2-
import { getFiletypeFromFileName } from "@pierre/diffs/utils/getFiletypeFromFileName";
2+
import {
3+
getFiletypeFromFileName,
4+
setCustomExtension,
5+
} from "@pierre/diffs/utils/getFiletypeFromFileName";
36

47
import { HIGHLIGHTS_LANGUAGE_IDS } from "./highlights.generated";
58

9+
// Highlights has no lexer for these dialects, so they use their base language's.
10+
setCustomExtension("luau", "lua");
11+
setCustomExtension("xsl", "xml");
12+
setCustomExtension("xslt", "xml");
13+
614
/** The native lexer ID for a @pierre/highlights language name, or 0 (plain text). */
715
export function highlightLanguageId(language: string): number {
816
return Object.hasOwn(HIGHLIGHTS_LANGUAGE_IDS, language) ? HIGHLIGHTS_LANGUAGE_IDS[language]! : 0;
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import type { NativeStackHeaderItem } from "@react-navigation/native-stack";
2+
import { act } from "react";
3+
import { createRoot } from "react-dom/client";
4+
import type { StackHeaderConfigProps } from "react-native-screens";
5+
import { expect, it, vi } from "vite-plus/test";
6+
7+
const bridge = vi.hoisted(() => ({ ios: undefined as StackHeaderConfigProps["ios"] }));
8+
9+
vi.mock("react-native", () => ({ StyleSheet: { flatten: (style: unknown) => style } }));
10+
vi.mock("react-native-keyboard-controller", () => ({
11+
KeyboardController: { dismiss: vi.fn() },
12+
useKeyboardState: () => false,
13+
}));
14+
vi.mock("../lib/useMobileNavigationTheme", () => ({
15+
useMobileNavigationTheme: () => ({ colors: { card: "white" } }),
16+
}));
17+
vi.mock("./native-layout-metrics", () => ({
18+
useDeviceType: () => "phone",
19+
useNativeLayoutMetrics: () => null,
20+
}));
21+
vi.mock("react-native-screens", () => ({
22+
Stack: {
23+
HeaderConfig: ({ ios }: StackHeaderConfigProps) => {
24+
bridge.ios = ios;
25+
return null;
26+
},
27+
},
28+
}));
29+
30+
import { V5StackHeader } from "./V5StackHeader.ios";
31+
32+
it.each(["leadingItems", "trailingItems", "toolbarItems"] as const)(
33+
"updates native enabled state after permissions change in %s",
34+
(placement) => {
35+
bridge.ios = undefined;
36+
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
37+
const root = createRoot(document.createElement("div"));
38+
const onPress = () => {};
39+
try {
40+
for (const disabled of [true, false, undefined, true]) {
41+
const items: NativeStackHeaderItem[] = [
42+
{ type: "button", label: "Files", disabled, onPress },
43+
{
44+
type: "menu",
45+
label: "Terminal",
46+
disabled,
47+
menu: { items: [{ type: "action", label: "Open terminal", onPress }] },
48+
},
49+
];
50+
act(() =>
51+
root.render(
52+
<V5StackHeader
53+
canGoBack={false}
54+
options={{
55+
unstable_headerLeftItems: () => (placement === "leadingItems" ? items : []),
56+
unstable_headerRightItems: () => (placement === "trailingItems" ? items : []),
57+
unstable_headerToolbarItems: () => (placement === "toolbarItems" ? items : []),
58+
}}
59+
/>,
60+
),
61+
);
62+
const nativeItems = (bridge.ios as StackHeaderConfigProps["ios"])?.[placement];
63+
expect(nativeItems).toHaveLength(2);
64+
for (const item of nativeItems ?? []) {
65+
if (item.type !== "item" || "render" in item)
66+
throw new Error("Expected a native bar item");
67+
// RNSHeaderContentFactory sets UIBarButtonItem.enabled to !item.disabled.
68+
expect(!item.disabled).toBe(!disabled);
69+
}
70+
}
71+
} finally {
72+
act(() => root.unmount());
73+
vi.unstubAllGlobals();
74+
}
75+
},
76+
);

‎apps/mobile/src/native/V5StackHeader.ios.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ function convertItems(items: NativeStackHeaderItem[], prefix: string): HeaderIte
124124
axisBehavior: item.axisBehavior,
125125
icon: convertIcon(item.icon),
126126
menu: item.disabled ? undefined : convertMenu(item.menu, `${id}:menu`),
127+
disabled: item.disabled,
127128
variant: item.variant,
128129
tintColor: item.tintColor,
129130
hidesSharedBackground: item.hidesSharedBackground,
@@ -137,6 +138,7 @@ function convertItems(items: NativeStackHeaderItem[], prefix: string): HeaderIte
137138
axisBehavior: item.axisBehavior,
138139
icon: convertIcon(item.icon),
139140
onPress: item.disabled ? undefined : item.onPress,
141+
disabled: item.disabled,
140142
visibilityPriority:
141143
item.visibilityPriority === "default" ? "standard" : item.visibilityPriority,
142144
variant: item.variant,

‎apps/mobile/vite.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const reactTests = [
2727
"src/features/threads/UsageLimitRecoveryCard.test.tsx",
2828
"src/features/threads/NewTaskDraftRouteScreen.test.tsx",
2929
"src/native/NativeHeaderToolbar.test.tsx",
30+
"src/native/V5StackHeader.ios.test.tsx",
3031
"src/native/useRestingTopOffset.test.tsx",
3132
"src/native/useRetryingImageSource.test.tsx",
3233
"src/state/queries.debounce.test.tsx",

0 commit comments

Comments
 (0)