Skip to content

Commit b1703fc

Browse files
committed
fix: align Expo preview navigation spec with Android consumer delegate
1 parent e8b4195 commit b1703fc

3 files changed

Lines changed: 65 additions & 0 deletions

File tree

apps/ExpoApp57/brownfield.navigation.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,14 @@ export interface BrownfieldNavigationSpec {
2222
* @param userId - The user's unique identifier
2323
*/
2424
navigateToReferrals(userId: string): void;
25+
26+
/**
27+
* Ask the native host to confirm an action. Resolves with the user's choice.
28+
*/
29+
requestNativeConfirmation(title: string): Promise<boolean>;
30+
31+
/**
32+
* Show a native banner. The native host calls onDismiss when the banner is dismissed.
33+
*/
34+
showNativeBanner(message: string, onDismiss: () => void): void;
2535
}

scripts/__tests__/check-expo-preview.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import assert from 'node:assert/strict';
22
import test from 'node:test';
33

44
import {
5+
ensureConsumerNavigationSpec,
56
findLatestPreviewVersion,
67
replaceHomeScreenTitle,
78
replaceTemplateAppReferences,
@@ -94,6 +95,29 @@ test('rewrites brownfield.config.json for ExpoApp57 template', () => {
9495
assert.doesNotMatch(output, /expoapp57/);
9596
});
9697

98+
test('adds consumer road-test navigation methods when missing from template', () => {
99+
const input = `export interface BrownfieldNavigationSpec {
100+
navigateToSettings(user: UserType): void;
101+
navigateToReferrals(userId: string): void;
102+
}`;
103+
104+
const output = ensureConsumerNavigationSpec(input);
105+
106+
assert.match(output, /requestNativeConfirmation/);
107+
assert.match(output, /showNativeBanner/);
108+
});
109+
110+
test('does not duplicate consumer road-test navigation methods', () => {
111+
const input = `export interface BrownfieldNavigationSpec {
112+
navigateToReferrals(userId: string): void;
113+
requestNativeConfirmation(title: string): Promise<boolean>;
114+
}`;
115+
116+
const output = ensureConsumerNavigationSpec(input);
117+
118+
assert.equal(output, input);
119+
});
120+
97121
test('rewrites the home screen title for the latest Expo template version', () => {
98122
const input = 'Welcome to&nbsp;Expo&nbsp;57';
99123

scripts/check-expo-preview.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ const EXPO_PREVIEW_BROWNFIELD_CONFIG_PATH = path.join(
4242
EXPO_PREVIEW_APP_DIR,
4343
'brownfield.config.json'
4444
);
45+
const EXPO_PREVIEW_NAVIGATION_SPEC_PATH = path.join(
46+
EXPO_PREVIEW_APP_DIR,
47+
'brownfield.navigation.ts'
48+
);
4549
const EXPO_NPM_REGISTRY_URL = 'https://registry.npmjs.org/expo';
4650

4751
function parseArgs(argv: string[]): CliOptions {
@@ -176,6 +180,29 @@ export function replaceHomeScreenTitle(
176180
.replaceAll(`Expo&nbsp;${version}`, 'Expo&nbsp;Preview');
177181
}
178182

183+
const CONSUMER_ROAD_TEST_NAVIGATION_METHODS = `
184+
/**
185+
* Ask the native host to confirm an action. Resolves with the user's choice.
186+
*/
187+
requestNativeConfirmation(title: string): Promise<boolean>;
188+
189+
/**
190+
* Show a native banner. The native host calls onDismiss when the banner is dismissed.
191+
*/
192+
showNativeBanner(message: string, onDismiss: () => void): void;
193+
`;
194+
195+
export function ensureConsumerNavigationSpec(contents: string): string {
196+
if (contents.includes('requestNativeConfirmation')) {
197+
return contents;
198+
}
199+
200+
return contents.replace(
201+
' navigateToReferrals(userId: string): void;\n}',
202+
` navigateToReferrals(userId: string): void;${CONSUMER_ROAD_TEST_NAVIGATION_METHODS}\n}`
203+
);
204+
}
205+
179206
function generateExpoPreviewApp(): void {
180207
const templateApp = getExpoTemplateApp();
181208
const replaceReferences = (contents: string) =>
@@ -197,6 +224,10 @@ function generateExpoPreviewApp(): void {
197224
updateFileContents(EXPO_PREVIEW_BROWNFIELD_CONFIG_PATH, replaceReferences);
198225
}
199226

227+
if (existsSync(EXPO_PREVIEW_NAVIGATION_SPEC_PATH)) {
228+
updateFileContents(EXPO_PREVIEW_NAVIGATION_SPEC_PATH, ensureConsumerNavigationSpec);
229+
}
230+
200231
const testPath = path.join(
201232
EXPO_PREVIEW_APP_DIR,
202233
'__tests__',

0 commit comments

Comments
 (0)