MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / onNavigatedTo

Function onNavigatedTo

apps/ui/src/media-queries/main-page.ts:6–34  ·  view source on GitHub ↗
(args: EventData)

Source from the content-addressed store, hash-verified

4import { Page } from '@nativescript/core/ui/page';
5
6export function onNavigatedTo(args: EventData) {
7 const page = <Page>args.object;
8
9 const orientationButton: Button = page.getViewById('orientation-match-media-btn');
10 if (orientationButton) {
11 const mq = matchMedia('(orientation: portrait)');
12 let mode = mq.matches ? 'portrait' : 'landscape';
13
14 orientationButton.text = `I' m in ${mode} mode!`;
15
16 mq.addEventListener('change', (event: MediaQueryListEvent) => {
17 mode = event.matches ? 'portrait' : 'landscape';
18 orientationButton.text = `I' m in ${mode} mode!`;
19 });
20 }
21
22 const themeModeButton: Button = page.getViewById('theme-match-media-btn');
23 if (themeModeButton) {
24 const mq = matchMedia('(prefers-color-scheme: light)');
25 let mode = mq.matches ? 'light' : 'dark';
26
27 themeModeButton.text = `I' m in ${mode} mode!`;
28
29 mq.addEventListener('change', (event: MediaQueryListEvent) => {
30 mode = event.matches ? 'light' : 'dark';
31 themeModeButton.text = `I' m in ${mode} mode!`;
32 });
33 }
34}

Callers

nothing calls this directly

Calls 2

matchMediaFunction · 0.85
addEventListenerMethod · 0.45

Tested by

no test coverage detected