@ng-native/template-desktop 0.0.0 → 0.23.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/AGENTS.md +94 -0
- package/CLAUDE.md +1 -0
- package/LICENSE +21 -0
- package/README.md +42 -0
- package/app.json +20 -0
- package/assets/icon.png +0 -0
- package/gitignore +43 -0
- package/metro.config.js +10 -0
- package/package.json +42 -1
- package/src/app/app.device.ts +8 -0
- package/src/app/app.test.ts +42 -0
- package/src/app/app.ts +159 -0
- package/src/main.ts +43 -0
- package/tsconfig.json +12 -0
- package/vitest.config.mts +16 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
This is an Angular app rendering real native macOS views (AppKit) with
|
|
4
|
+
[Angular Native](https://ng-native.com): Angular components on React Native's Fabric renderer, in
|
|
5
|
+
the `@ng-native/desktop` host. Expo is the build tool (CLI, config, autolinking, Metro), not the
|
|
6
|
+
runtime. It is not a web app, not Electron and not React: there is no DOM, no web view and no JSX.
|
|
7
|
+
|
|
8
|
+
The whole documentation, for reading before a change: https://ng-native.com/llms-full.txt. An
|
|
9
|
+
outline with a line per page: https://ng-native.com/llms.txt.
|
|
10
|
+
|
|
11
|
+
Angular's own rules apply as well: https://angular.dev/assets/context/best-practices.md. Its
|
|
12
|
+
browser-only parts do not: there is no `NgOptimizedImage` (use `<image>`), and no AXE
|
|
13
|
+
(accessibility is the props below). Where the two disagree, this file wins.
|
|
14
|
+
|
|
15
|
+
## Commands
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm start # Metro, the dev server the app loads from
|
|
19
|
+
npm run macos # builds the desktop host (the first time) and opens the app from Metro
|
|
20
|
+
npm test # Vitest, in Node against a fake native layer: no app window needed
|
|
21
|
+
npx vitest --project macos # tests in src/**/*.device.ts, inside the running app; needs
|
|
22
|
+
# EXPO_PUBLIC_DEVICE_TESTS=1 npx expo start in another terminal
|
|
23
|
+
npm run typecheck
|
|
24
|
+
npm run package # the .app
|
|
25
|
+
npm run package -- --format dmg # a signed, notarised download; --format mas for the Mac App Store
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`src/main.ts` mounts the root component, `src/app/app.ts`. Run `npm test` and `npm run typecheck` after a
|
|
29
|
+
change; both are fast.
|
|
30
|
+
|
|
31
|
+
## Rules that are easy to get wrong
|
|
32
|
+
|
|
33
|
+
- **Element names are lowercase:** `<view>`, `<text>`, `<pressable>`, `<scroll-view>`,
|
|
34
|
+
`<text-input>`, `<image>`, `<switch>`, `<safe-area-view>`, `<virtual-list>`, `<modal>`. Each is
|
|
35
|
+
imported from `@ng-native/components` into the component's `imports`, like any Angular
|
|
36
|
+
component: `imports: [View, Text]`. `<View>` matches no component and fails the build, and an element used
|
|
37
|
+
without its import renders as a plain view.
|
|
38
|
+
- **There is no DOM.** No `document`, no `window`, no `<button>`, `<a>`, `<input>` or `<img>`, no
|
|
39
|
+
`@angular/platform-browser`, and no `@angular/animations`. Use the native elements above. HTML's
|
|
40
|
+
text elements (`p`, `span`, `h1`, `strong`) draw as text and its layout elements (`div`,
|
|
41
|
+
`section`, `ul`) as plain views, with none of a browser's default styles.
|
|
42
|
+
- **A component's host is a flex item.** `<app-case-list />` commits as a view of its own, with no
|
|
43
|
+
`flex`, so a `flex: 1` scroll view inside it gets a height of zero and shows nothing. A component
|
|
44
|
+
that fills the space it is given sets `host: { style: 'flex: 1' }` (or `:host { flex: 1; }`).
|
|
45
|
+
- **Text is drawn in a text element.** `<text>` is the one with inputs and outputs (`numberOfLines`,
|
|
46
|
+
`(press)`). `p`, `span` and the other HTML text elements are text while they hold only text and
|
|
47
|
+
other text elements; one that holds a view is a view. Text written straight into a view is given
|
|
48
|
+
a paragraph of its own, one per run, and never flows inline with the elements beside it.
|
|
49
|
+
- **Events are native:** `(press)` on `<pressable>`, not `(click)`; `[(value)]` or `(changeText)` on
|
|
50
|
+
`<text-input>`; `(scroll)`, `(layout)`. A pressable text is `<text pressable (press)="...">`.
|
|
51
|
+
- **Signals, zoneless, AOT.** State is signals and `computed()`; there is no zone.js, so nothing
|
|
52
|
+
updates from a plain field changing outside a signal or an event.
|
|
53
|
+
- **No backticks inside an inline template**, even in an HTML comment: they end the template string
|
|
54
|
+
and the build fails with a misleading parse error.
|
|
55
|
+
- **Accessibility is props:** `accessibilityRole="button"`, `accessibilityLabel`,
|
|
56
|
+
`[accessibilityState]`. The web spellings work too, as aliases: `role`, and the `aria-*` names
|
|
57
|
+
React Native maps (`aria-label`, `aria-checked`, `aria-hidden` and so on). Screen readers and
|
|
58
|
+
the testing library's `getByRole` both read them.
|
|
59
|
+
|
|
60
|
+
## Styling
|
|
61
|
+
|
|
62
|
+
- `[style]` takes a React Native style object: camelCase keys, numbers in points
|
|
63
|
+
(`{ padding: 16, backgroundColor: '#fff' }`).
|
|
64
|
+
- A component's `styles` is real CSS, compiled at build time: type, class, id and attribute
|
|
65
|
+
selectors, combinators, `:host`, `@media`, custom properties, transitions and `@keyframes`, and
|
|
66
|
+
`:active`, `:focus`, `:hover`, `:focus-visible` and `:focus-within`. Float and
|
|
67
|
+
`::before`/`::after` are dropped with a build warning naming the file, line and reason - lay out
|
|
68
|
+
with flexbox, grid or a block. Everything is `display: flex` with `flex-direction: column` by
|
|
69
|
+
default, as in React Native.
|
|
70
|
+
- Tailwind v4 works through `@ng-native/tailwind`, with `ios:`, `android:`, `macos:`, `desktop:`
|
|
71
|
+
and `dark:` variants.
|
|
72
|
+
|
|
73
|
+
## Lists, navigation, forms
|
|
74
|
+
|
|
75
|
+
- A long list is `<virtual-list>`: `@for (row of list.window(); track row.slot)` recycles rows as
|
|
76
|
+
they scroll. `<scroll-view>` renders everything, so keep it for short content.
|
|
77
|
+
- Navigation is `@angular/router` on native stacks and tabs: `provideNativeRouter(routes)` from
|
|
78
|
+
`@ng-native/router` in `mount`'s `providers`, and `<native-stack-outlet />` in a template. Add
|
|
79
|
+
`withComponentInputBinding()` from `@angular/router` for route params to arrive as inputs, in
|
|
80
|
+
tests too.
|
|
81
|
+
- Forms are Signal Forms (`@angular/forms/signals`), with `[formField]` on `<text-input>` and
|
|
82
|
+
`<switch>`.
|
|
83
|
+
- HTTP needs `provideNativeHttpClient()` from `@ng-native/platform/http`, not `provideHttpClient()`.
|
|
84
|
+
|
|
85
|
+
## Tests
|
|
86
|
+
|
|
87
|
+
`app.test.ts` shows the shape: `render(Component)`, then query with `screen.getByRole`,
|
|
88
|
+
`getByText` or `getByTestId` (which matches `nativeID` and `testID`), and act with
|
|
89
|
+
`userEvent.setup().press(...)` or `.type(...)`, all from `@ng-native/testing`. Tests run in Node
|
|
90
|
+
with no simulator, so write one alongside a change.
|
|
91
|
+
|
|
92
|
+
A service that depends on the platform injects `OS` and `OS_VERSION` from `@ng-native/device`
|
|
93
|
+
rather than importing `Platform` from `react-native`, which a test cannot load. A test provides
|
|
94
|
+
the values it wants: `{ provide: OS, useValue: 'android' }`.
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@AGENTS.md
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ashley Hunter
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# My Angular Native macOS app
|
|
2
|
+
|
|
3
|
+
A native macOS app in Angular, created from `@ng-native/template-desktop`: real AppKit views, a
|
|
4
|
+
sidebar and a menu bar, and no web view.
|
|
5
|
+
|
|
6
|
+
Expo is your build tool here, not your runtime. Its CLI, config, autolinking and Metro build the
|
|
7
|
+
app, and none of Expo ships in it: the `@ng-native/desktop` host runs it.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm start # Metro, the dev server the app loads from; leave it running
|
|
11
|
+
npm run macos # builds the desktop host and opens the app, with Fast Refresh
|
|
12
|
+
npm test # the example test in src/app/app.test.ts, in Node with no app window
|
|
13
|
+
npm run typecheck
|
|
14
|
+
npm run package # dist/macos/my-app.app
|
|
15
|
+
npm run package -- --format dmg # a signed, notarised .dmg; --format mas for the Mac App Store
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
To run tests inside the app, on real AppKit views, start Metro for them and run the `macos` Vitest
|
|
19
|
+
project, which opens the app itself (`src/app/app.device.ts` is the example):
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
EXPO_PUBLIC_DEVICE_TESTS=1 npx expo start
|
|
23
|
+
npx vitest --project macos
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`npm test` runs the Node project, `node-macos`, alone.
|
|
27
|
+
|
|
28
|
+
`npm run macos` uses the prebuilt debug desktop host, with React Native's debugger, published for
|
|
29
|
+
the app's React Native version when the app links no native code of its own and its host libraries
|
|
30
|
+
are the versions the host was built with. Otherwise the first run builds the host from source,
|
|
31
|
+
which takes a few minutes and needs Xcode's command line tools, CMake and Ninja; later runs reuse
|
|
32
|
+
it. `npm run package` needs full Xcode for the app icon.
|
|
33
|
+
|
|
34
|
+
`src/app/app.ts` is the root component and `src/main.ts` mounts it. The app's settings are Expo's
|
|
35
|
+
keys in `app.json` (`name`, `icon`, `scheme`, `ios.bundleIdentifier` for the bundle identifier),
|
|
36
|
+
and what has no Expo key is the `@ng-native/desktop` plugin's options: see
|
|
37
|
+
https://ng-native.com/packages/desktop.
|
|
38
|
+
|
|
39
|
+
`AGENTS.md` tells a coding agent how this framework differs from the web Angular it knows
|
|
40
|
+
(Claude Code reads it through `CLAUDE.md`). Add your own conventions to it as the app grows.
|
|
41
|
+
|
|
42
|
+
Docs: https://ng-native.com
|
package/app.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"expo": {
|
|
3
|
+
"name": "my-app",
|
|
4
|
+
"slug": "my-app",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"platforms": ["macos"],
|
|
7
|
+
"experiments": {
|
|
8
|
+
"outOfTreePlatforms": true
|
|
9
|
+
},
|
|
10
|
+
"icon": "./assets/icon.png",
|
|
11
|
+
"userInterfaceStyle": "automatic",
|
|
12
|
+
"scheme": "helloworld",
|
|
13
|
+
"extra": {
|
|
14
|
+
"router": {
|
|
15
|
+
"root": "src/app"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"plugins": ["@ng-native/metro", "@ng-native/desktop"]
|
|
19
|
+
}
|
|
20
|
+
}
|
package/assets/icon.png
ADDED
|
Binary file
|
package/gitignore
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files
|
|
2
|
+
|
|
3
|
+
# dependencies
|
|
4
|
+
node_modules/
|
|
5
|
+
|
|
6
|
+
# Expo
|
|
7
|
+
.expo/
|
|
8
|
+
dist/
|
|
9
|
+
expo-env.d.ts
|
|
10
|
+
|
|
11
|
+
# Native
|
|
12
|
+
.kotlin/
|
|
13
|
+
*.orig.*
|
|
14
|
+
*.jks
|
|
15
|
+
*.p8
|
|
16
|
+
*.p12
|
|
17
|
+
*.key
|
|
18
|
+
*.mobileprovision
|
|
19
|
+
|
|
20
|
+
# Metro
|
|
21
|
+
.metro-health-check*
|
|
22
|
+
|
|
23
|
+
# debug
|
|
24
|
+
npm-debug.*
|
|
25
|
+
yarn-debug.*
|
|
26
|
+
yarn-error.*
|
|
27
|
+
|
|
28
|
+
# macOS
|
|
29
|
+
.DS_Store
|
|
30
|
+
*.pem
|
|
31
|
+
|
|
32
|
+
# local env files
|
|
33
|
+
.env*.local
|
|
34
|
+
|
|
35
|
+
# typescript
|
|
36
|
+
*.tsbuildinfo
|
|
37
|
+
|
|
38
|
+
# generated native folders
|
|
39
|
+
/ios
|
|
40
|
+
/android
|
|
41
|
+
|
|
42
|
+
# Generated by @ng-native/tailwind's withTailwind, rebuilt on every Metro start
|
|
43
|
+
.angular-native/
|
package/metro.config.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const { getDefaultConfig } = require('expo/metro-config');
|
|
2
|
+
const { withAngularNative } = require('@ng-native/metro/config.cjs');
|
|
3
|
+
const { withDeviceTests } = require('@ng-native/testing/device/metro');
|
|
4
|
+
|
|
5
|
+
// Registers the transformer that compiles Angular ahead of time, compiles each component's CSS
|
|
6
|
+
// into the sheet the engine reads, and adds the polyfills Angular needs before `@angular/core`
|
|
7
|
+
// is first evaluated. No options: the framework packages are ordinary dependencies here.
|
|
8
|
+
// `withDeviceTests` does nothing until Metro starts with EXPO_PUBLIC_DEVICE_TESTS set, for the
|
|
9
|
+
// tests that run inside the app.
|
|
10
|
+
module.exports = withDeviceTests(withAngularNative(getDefaultConfig(__dirname)));
|
package/package.json
CHANGED
|
@@ -1 +1,42 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "@ng-native/template-desktop",
|
|
3
|
+
"version": "0.23.0",
|
|
4
|
+
"description": "A macOS app in Angular, rendering real AppKit views. Use with create-expo-app --template.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "src/main.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@ng-native/components": "0.23.0",
|
|
9
|
+
"@ng-native/desktop": "0.23.0",
|
|
10
|
+
"@ng-native/device": "0.23.0",
|
|
11
|
+
"@ng-native/expo": "0.23.0",
|
|
12
|
+
"@ng-native/fabric": "0.23.0",
|
|
13
|
+
"@ng-native/metro": "0.23.0",
|
|
14
|
+
"@ng-native/platform": "0.23.0",
|
|
15
|
+
"@angular/common": "^22.0.0",
|
|
16
|
+
"@angular/core": "^22.0.0",
|
|
17
|
+
"expo": "~58.0.16",
|
|
18
|
+
"react": "19.3.0",
|
|
19
|
+
"react-native": "0.88.0",
|
|
20
|
+
"react-native-safe-area-context": "5.10.1"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@angular/compiler-cli": "^22.0.0",
|
|
24
|
+
"@babel/core": "^7.29.7",
|
|
25
|
+
"@ng-native/testing": "0.23.0",
|
|
26
|
+
"@types/react": "~19.3.0",
|
|
27
|
+
"typescript": "~6.0.3",
|
|
28
|
+
"vitest": "^5.0.0"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/ng-native/ng-native.git",
|
|
33
|
+
"directory": "template-desktop"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"start": "expo start",
|
|
37
|
+
"macos": "ng-native-desktop run",
|
|
38
|
+
"package": "ng-native-desktop package",
|
|
39
|
+
"typecheck": "node metro.config.js && ngc -p tsconfig.json --noEmit",
|
|
40
|
+
"test": "vitest run --project node-macos"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import { expect, it } from 'vitest';
|
|
3
|
+
|
|
4
|
+
// Runs inside the app, on real AppKit views: `npx vitest --project macos`. Render a component
|
|
5
|
+
// with `render` and `screen` from `@ng-native/testing/device`.
|
|
6
|
+
it('runs on the Mac', () => {
|
|
7
|
+
expect(Platform.OS).toBe('macos');
|
|
8
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ErrorHandler } from '@angular/core';
|
|
2
|
+
import { Clipboard, type NativeClipboard } from '@ng-native/expo/clipboard';
|
|
3
|
+
import { render, screen, userEvent } from '@ng-native/testing';
|
|
4
|
+
import { expect, test } from 'vitest';
|
|
5
|
+
import { App } from './app.ts';
|
|
6
|
+
|
|
7
|
+
test('goes to a page from the menu bar and copies its title', async () => {
|
|
8
|
+
const copied: string[] = [];
|
|
9
|
+
const clipboard: NativeClipboard = {
|
|
10
|
+
getStringAsync: async () => copied.at(-1) ?? '',
|
|
11
|
+
setStringAsync: async (text) => (copied.push(text), true),
|
|
12
|
+
addClipboardListener: () => ({ remove: () => {} }),
|
|
13
|
+
};
|
|
14
|
+
await render(App, { providers: [{ provide: Clipboard.SOURCE, useValue: clipboard }] });
|
|
15
|
+
const user = userEvent.setup();
|
|
16
|
+
|
|
17
|
+
expect(await userEvent.keyboard('mod+2')).toBe(true);
|
|
18
|
+
expect(screen.getByRole('header', { name: 'Notes' })).toBeTruthy();
|
|
19
|
+
|
|
20
|
+
await user.press(screen.getByRole('button', { name: 'Copy Title' }));
|
|
21
|
+
expect(copied).toEqual(['Notes']);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("hands a copy the clipboard refuses to Angular's ErrorHandler", async () => {
|
|
25
|
+
const refused = new Error('no clipboard');
|
|
26
|
+
const clipboard: NativeClipboard = {
|
|
27
|
+
getStringAsync: async () => '',
|
|
28
|
+
setStringAsync: async () => Promise.reject(refused),
|
|
29
|
+
addClipboardListener: () => ({ remove: () => {} }),
|
|
30
|
+
};
|
|
31
|
+
const handled: unknown[] = [];
|
|
32
|
+
await render(App, {
|
|
33
|
+
providers: [
|
|
34
|
+
{ provide: Clipboard.SOURCE, useValue: clipboard },
|
|
35
|
+
{ provide: ErrorHandler, useValue: { handleError: (error: unknown) => handled.push(error) } },
|
|
36
|
+
],
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
await userEvent.setup().press(screen.getByRole('button', { name: 'Copy Title' }));
|
|
40
|
+
expect(handled).toEqual([refused]);
|
|
41
|
+
expect(screen.queryByText(/^Copied/)).toBeNull();
|
|
42
|
+
});
|
package/src/app/app.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { Component, computed, ErrorHandler, inject, signal } from '@angular/core';
|
|
2
|
+
import {
|
|
3
|
+
MenuBar,
|
|
4
|
+
MenuGroup,
|
|
5
|
+
MenuItem,
|
|
6
|
+
NativeButton,
|
|
7
|
+
SafeAreaProvider,
|
|
8
|
+
SafeAreaView,
|
|
9
|
+
Sidebar,
|
|
10
|
+
SidebarItem,
|
|
11
|
+
SidebarSection,
|
|
12
|
+
SplitView,
|
|
13
|
+
Text,
|
|
14
|
+
} from '@ng-native/components';
|
|
15
|
+
// @ng-native/expo holds the services whose mobile source is Expo; on macOS the desktop host answers.
|
|
16
|
+
import { Clipboard } from '@ng-native/expo/clipboard';
|
|
17
|
+
|
|
18
|
+
interface Page {
|
|
19
|
+
readonly id: string;
|
|
20
|
+
readonly label: string;
|
|
21
|
+
readonly sfSymbol: string;
|
|
22
|
+
readonly hint: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const PAGES: readonly Page[] = [
|
|
26
|
+
{ id: 'home', label: 'Home', sfSymbol: 'house', hint: 'A native macOS app, written in Angular.' },
|
|
27
|
+
{ id: 'notes', label: 'Notes', sfSymbol: 'note.text', hint: 'Real AppKit views, no web view.' },
|
|
28
|
+
{ id: 'settings', label: 'Settings', sfSymbol: 'gearshape', hint: 'One runtime: no IPC.' },
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Element names are lowercase, and that is load-bearing rather than style: an uppercase name such
|
|
33
|
+
* as <View> matches no component's selector, and the Metro transform fails the build on it.
|
|
34
|
+
*
|
|
35
|
+
* Sizes are a phone's by default and a Mac's under :host-context(.platform-macos), so the app is
|
|
36
|
+
* Mac-sized now and still fits a phone if iOS or Android is added later.
|
|
37
|
+
*/
|
|
38
|
+
@Component({
|
|
39
|
+
imports: [
|
|
40
|
+
MenuBar,
|
|
41
|
+
MenuGroup,
|
|
42
|
+
MenuItem,
|
|
43
|
+
NativeButton,
|
|
44
|
+
SafeAreaProvider,
|
|
45
|
+
SafeAreaView,
|
|
46
|
+
Sidebar,
|
|
47
|
+
SidebarItem,
|
|
48
|
+
SidebarSection,
|
|
49
|
+
SplitView,
|
|
50
|
+
Text,
|
|
51
|
+
],
|
|
52
|
+
selector: 'app-root',
|
|
53
|
+
template: `
|
|
54
|
+
<menu-bar>
|
|
55
|
+
<menu-group label="Go" menuRole="view">
|
|
56
|
+
@for (page of pages; track page.id; let i = $index) {
|
|
57
|
+
<menu-item [label]="page.label" [shortcut]="'mod+' + (i + 1)" (select)="show(page.id)" />
|
|
58
|
+
}
|
|
59
|
+
</menu-group>
|
|
60
|
+
<menu-group label="Edit" menuRole="edit">
|
|
61
|
+
<menu-item label="Copy Page Title" shortcut="mod+shift+c" (select)="copyTitle()" />
|
|
62
|
+
</menu-group>
|
|
63
|
+
</menu-bar>
|
|
64
|
+
|
|
65
|
+
<safe-area-provider>
|
|
66
|
+
<split-view>
|
|
67
|
+
<sidebar minWidth="180" autosave="main">
|
|
68
|
+
<sidebar-section title="My App">
|
|
69
|
+
@for (page of pages; track page.id) {
|
|
70
|
+
<sidebar-item
|
|
71
|
+
[label]="page.label"
|
|
72
|
+
[sfSymbol]="page.sfSymbol"
|
|
73
|
+
[selected]="page.id === current().id"
|
|
74
|
+
(select)="show(page.id)"
|
|
75
|
+
/>
|
|
76
|
+
}
|
|
77
|
+
</sidebar-section>
|
|
78
|
+
</sidebar>
|
|
79
|
+
|
|
80
|
+
<safe-area-view class="content">
|
|
81
|
+
<text class="title" accessibilityRole="header">{{ current().label }}</text>
|
|
82
|
+
<text class="hint">{{ current().hint }}</text>
|
|
83
|
+
<native-button (press)="copyTitle()">Copy Title</native-button>
|
|
84
|
+
@if (copied()) {
|
|
85
|
+
<text class="hint">Copied {{ copied() }}.</text>
|
|
86
|
+
}
|
|
87
|
+
</safe-area-view>
|
|
88
|
+
</split-view>
|
|
89
|
+
</safe-area-provider>
|
|
90
|
+
`,
|
|
91
|
+
styles: `
|
|
92
|
+
:host {
|
|
93
|
+
flex: 1;
|
|
94
|
+
}
|
|
95
|
+
.content {
|
|
96
|
+
flex: 1;
|
|
97
|
+
gap: 12px;
|
|
98
|
+
padding: 24px;
|
|
99
|
+
align-items: flex-start;
|
|
100
|
+
background-color: #ffffff;
|
|
101
|
+
}
|
|
102
|
+
.title {
|
|
103
|
+
color: #101014;
|
|
104
|
+
font-size: 28px;
|
|
105
|
+
font-weight: 700;
|
|
106
|
+
}
|
|
107
|
+
.hint {
|
|
108
|
+
color: #5f5f6b;
|
|
109
|
+
font-size: 15px;
|
|
110
|
+
}
|
|
111
|
+
:host-context(.platform-macos) .content {
|
|
112
|
+
gap: 8px;
|
|
113
|
+
padding: 20px;
|
|
114
|
+
}
|
|
115
|
+
:host-context(.platform-macos) .title {
|
|
116
|
+
font-size: 22px;
|
|
117
|
+
}
|
|
118
|
+
:host-context(.platform-macos) .hint {
|
|
119
|
+
font-size: 13px;
|
|
120
|
+
}
|
|
121
|
+
@media (prefers-color-scheme: dark) {
|
|
122
|
+
.content {
|
|
123
|
+
background-color: #1e1e20;
|
|
124
|
+
}
|
|
125
|
+
.title {
|
|
126
|
+
color: #ffffff;
|
|
127
|
+
}
|
|
128
|
+
.hint {
|
|
129
|
+
color: #8b8b96;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
`,
|
|
133
|
+
})
|
|
134
|
+
export class App {
|
|
135
|
+
private readonly clipboard = inject(Clipboard);
|
|
136
|
+
private readonly errors = inject(ErrorHandler);
|
|
137
|
+
|
|
138
|
+
protected readonly pages = PAGES;
|
|
139
|
+
private readonly selected = signal(PAGES[0]!.id);
|
|
140
|
+
protected readonly current = computed(
|
|
141
|
+
() => PAGES.find((page) => page.id === this.selected()) ?? PAGES[0]!,
|
|
142
|
+
);
|
|
143
|
+
protected readonly copied = signal('');
|
|
144
|
+
|
|
145
|
+
protected show(id: string): void {
|
|
146
|
+
this.selected.set(id);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
protected async copyTitle(): Promise<void> {
|
|
150
|
+
const title = this.current().label;
|
|
151
|
+
// A handler's promise goes nowhere, so a refused copy goes to the ErrorHandler.
|
|
152
|
+
try {
|
|
153
|
+
await this.clipboard.write(title);
|
|
154
|
+
this.copied.set(title);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
this.errors.handleError(error);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Expo's runtime: its fetch, whose response streams a body, and URL, TextDecoderStream and
|
|
2
|
+
// structuredClone. Metro runs it before this file only when something imports it, and nothing
|
|
3
|
+
// else does in a release build, which would then get React Native's fetch, with no body.
|
|
4
|
+
import 'expo';
|
|
5
|
+
import { AppRegistry, Image, Platform, processColor } from 'react-native';
|
|
6
|
+
import { mount } from '@ng-native/platform';
|
|
7
|
+
import { currentConditions, deviceTokens, watchConditions } from '@ng-native/device';
|
|
8
|
+
import { getFabricUIManager, registerPlatformComponents } from '@ng-native/fabric';
|
|
9
|
+
import { App } from './app/app.ts';
|
|
10
|
+
|
|
11
|
+
registerPlatformComponents(Platform.OS);
|
|
12
|
+
|
|
13
|
+
/** What `mount` takes, for the app and for the tests that run inside it. */
|
|
14
|
+
const mountOptions = () => ({
|
|
15
|
+
// Colours, as the integers the platform wants.
|
|
16
|
+
processColor,
|
|
17
|
+
// What `@media` resolves against. Without it every media query is false and a responsive
|
|
18
|
+
// layout renders as its smallest case.
|
|
19
|
+
conditions: currentConditions(),
|
|
20
|
+
// Values only the device knows - the hairline width, which is a third of a point on a 3x
|
|
21
|
+
// screen. Without it `1px` is what you get, and that is a visibly fat divider.
|
|
22
|
+
tokens: deviceTokens(),
|
|
23
|
+
// Turns a `require('./x.png')` into something native can load. Without it images are blank.
|
|
24
|
+
resolveAssetSource: (value: unknown) => Image.resolveAssetSource(value as never),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (process.env.EXPO_PUBLIC_DEVICE_TESTS) {
|
|
28
|
+
// Metro was started for `vitest --project macos`: the test host, not the app.
|
|
29
|
+
const { startDeviceTests } =
|
|
30
|
+
require('@ng-native/testing/device/host') as typeof import('@ng-native/testing/device/host');
|
|
31
|
+
startDeviceTests({ mount: mountOptions() });
|
|
32
|
+
} else {
|
|
33
|
+
AppRegistry.registerRunnable('main', ({ rootTag }) => {
|
|
34
|
+
const app = mount(Number(rootTag), App, getFabricUIManager(), mountOptions());
|
|
35
|
+
|
|
36
|
+
// Re-resolves the conditions when the device rotates or the theme changes. A rotation dirties
|
|
37
|
+
// no component and no binding, so without this nothing re-renders and `dark:` stops following
|
|
38
|
+
// the system switch. It stops with the app, which Android destroys when it recreates the
|
|
39
|
+
// activity, so the app mounted in its place is the only one still watching.
|
|
40
|
+
const stopWatching = watchConditions(app.engine);
|
|
41
|
+
app.applicationRef.onDestroy(stopWatching);
|
|
42
|
+
});
|
|
43
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "expo/tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"strict": true,
|
|
5
|
+
"allowImportingTsExtensions": true
|
|
6
|
+
},
|
|
7
|
+
"angularCompilerOptions": {
|
|
8
|
+
"strictTemplates": true,
|
|
9
|
+
"typeCheckHostBindings": false,
|
|
10
|
+
"strictDomEventTypes": false
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ngNative } from '@ng-native/testing/vitest';
|
|
2
|
+
import { deviceTests } from '@ng-native/testing/device/vitest';
|
|
3
|
+
import { defineConfig } from 'vitest/config';
|
|
4
|
+
|
|
5
|
+
// Two projects. `node-macos` compiles Angular for the tests the way Metro compiles it for the app
|
|
6
|
+
// and runs them in Node against a fake of the native side: no app window. `macos` runs the
|
|
7
|
+
// `*.device.ts` files inside the running app on this Mac, which it opens itself; start Metro with
|
|
8
|
+
// EXPO_PUBLIC_DEVICE_TESTS=1 first. `npm test` runs `node-macos` alone.
|
|
9
|
+
export default defineConfig({
|
|
10
|
+
test: {
|
|
11
|
+
projects: [
|
|
12
|
+
{ plugins: [ngNative({ os: 'macos' })], test: { name: 'node-macos' } },
|
|
13
|
+
{ plugins: [deviceTests({ platform: 'macos' })] },
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
});
|