Skip to content

Commit 6bd2675

Browse files
committed
fix(overlay): remove the NativeScript highlight box on an empty request
An empty highlight request cleared only the border fallback, so the native box stayed until its timer ended after the pointer left a row. The handler now clears the box first, as the Angular Native one already did.
1 parent 72a8372 commit 6bd2675

2 files changed

Lines changed: 61 additions & 1 deletion

File tree

‎packages/devtools/src/__tests__/overlay-nativescript-connection.test.ts‎

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ class AppComponent {}
2424
Object.assign(AppComponent, { ɵcmp: { selectors: [['ns-app']] } });
2525
const app = new AppComponent();
2626

27+
const nativeApp: Record<string, unknown> = { getRootView: () => host };
28+
2729
vi.mock('@nativescript/core', () => ({
28-
Application: { getRootView: () => host },
30+
Application: nativeApp,
2931
isAndroid: true,
32+
Utils: { layout: { getDisplayDensity: () => 1 } },
3033
}));
3134

3235
vi.mock('devframe/client', () => ({
@@ -172,6 +175,62 @@ describe('NativeScript overlay connection', () => {
172175
dispose();
173176
});
174177

178+
it('removes the native box on an empty request, not only the border', async () => {
179+
const decor: unknown[] = [];
180+
const decorView = {
181+
addView: (view: unknown) => decor.push(view),
182+
removeView: (view: unknown) => decor.splice(decor.indexOf(view), 1),
183+
};
184+
class View {
185+
setBackground() {}
186+
setClickable() {}
187+
setFocusable() {}
188+
setLayoutParams() {}
189+
setX() {}
190+
setY() {}
191+
}
192+
const g = globalThis as Record<string, unknown>;
193+
g['android'] = {
194+
view: { View },
195+
widget: { FrameLayout: { LayoutParams: class {} } },
196+
graphics: {
197+
Color: { parseColor: () => 0 },
198+
drawable: {
199+
GradientDrawable: class {
200+
setColor() {}
201+
setStroke() {}
202+
},
203+
},
204+
},
205+
};
206+
nativeApp['android'] = {
207+
foregroundActivity: { getWindow: () => ({ getDecorView: () => decorView }) },
208+
};
209+
Object.assign(host, {
210+
getLocationInWindow: () => ({ x: 0, y: 0 }),
211+
getActualSize: () => ({ width: 100, height: 40 }),
212+
});
213+
try {
214+
const { initNativeScriptOverlay } = await import('../overlay-nativescript.ts');
215+
const dispose = initNativeScriptOverlay({
216+
baseURL: 'http://localhost:9999/',
217+
intervalMs: 100,
218+
});
219+
await flush();
220+
const highlight = clients[0].handlers.get('highlight-in-page')!;
221+
highlight({ pageId: pageIdOf(clients[0]), id: elementId(host) });
222+
expect(decor).toHaveLength(1);
223+
highlight('');
224+
expect(decor).toHaveLength(0);
225+
dispose();
226+
} finally {
227+
delete g['android'];
228+
delete nativeApp['android'];
229+
delete host['getLocationInWindow'];
230+
delete host['getActualSize'];
231+
}
232+
});
233+
175234
it('keeps a highlight for the duration the request names', async () => {
176235
const { initNativeScriptOverlay } = await import('../overlay-nativescript.ts');
177236
const dispose = initNativeScriptOverlay({

‎packages/devtools/src/overlay-nativescript.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ async function startSession(
414414
const wanted = typeof request === 'string' ? { selector: request } : request;
415415
if (wanted?.pageId && wanted.pageId !== pageId) return;
416416
clearFlash();
417+
clearNativeHighlight();
417418
if (!wanted) return;
418419
const host =
419420
typeof wanted.id === 'string'

0 commit comments

Comments
 (0)