@ng-native/template 0.0.1 → 0.1.1
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 +75 -0
- package/CLAUDE.md +1 -0
- package/LICENSE +21 -0
- package/README.md +23 -2
- package/app.json +29 -0
- package/assets/android-icon-background.png +0 -0
- package/assets/android-icon-foreground.png +0 -0
- package/assets/android-icon-monochrome.png +0 -0
- package/assets/icon.png +0 -0
- package/assets/splash-icon.png +0 -0
- package/gitignore +43 -0
- package/metro.config.js +7 -0
- package/package.json +35 -2
- package/src/app/app.test.ts +11 -0
- package/src/app/app.ts +62 -0
- package/src/main.ts +27 -0
- package/tsconfig.json +12 -0
- package/vitest.config.mts +8 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
This is an Angular app rendering real native iOS and Android views with
|
|
4
|
+
[Angular Native](https://ng-native.com): Angular components on React Native's Fabric renderer,
|
|
5
|
+
inside an Expo app. It is not a web app and not React: there is no DOM and no JSX.
|
|
6
|
+
|
|
7
|
+
The whole documentation, for reading before a change: https://ng-native.com/llms-full.txt. An
|
|
8
|
+
outline with a line per page: https://ng-native.com/llms.txt.
|
|
9
|
+
|
|
10
|
+
Angular's own rules apply as well: https://angular.dev/assets/context/best-practices.md. Its
|
|
11
|
+
browser-only parts do not: there is no `NgOptimizedImage` (use `<image>`), and no AXE or ARIA
|
|
12
|
+
(accessibility is the props below). Where the two disagree, this file wins.
|
|
13
|
+
|
|
14
|
+
## Commands
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
npm start # Metro; press i or a for a simulator, or scan the QR code with Expo Go
|
|
18
|
+
npm run ios # the iOS simulator
|
|
19
|
+
npm run android # the Android emulator
|
|
20
|
+
npm test # Vitest, in Node against a fake native layer: no simulator needed
|
|
21
|
+
npm run typecheck
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
`src/main.ts` mounts the root component, `src/app/app.ts`. Run `npm test` and `npm run typecheck` after a
|
|
25
|
+
change; both are fast.
|
|
26
|
+
|
|
27
|
+
## Rules that are easy to get wrong
|
|
28
|
+
|
|
29
|
+
- **Element names are lowercase:** `<view>`, `<text>`, `<pressable>`, `<scroll-view>`,
|
|
30
|
+
`<text-input>`, `<image>`, `<switch>`, `<safe-area-view>`, `<virtual-list>`, `<modal>`. Each is
|
|
31
|
+
imported from `@ng-native/components` into the component's `imports`, like any Angular
|
|
32
|
+
component: `imports: [View, Text]`. `<View>` compiles to an empty template, and an element used
|
|
33
|
+
without its import renders as a plain view.
|
|
34
|
+
- **There is no DOM.** No `document`, no `window`, no `<div>`, `<span>`, `<button>` or `<input>`,
|
|
35
|
+
no `@angular/platform-browser`, and no `@angular/animations`. Use the native elements above.
|
|
36
|
+
- **Text only renders inside `<text>`.** `<view>Hello</view>` compiles and shows nothing.
|
|
37
|
+
- **Events are native:** `(press)` on `<pressable>`, not `(click)`; `[(value)]` or `(changeText)` on
|
|
38
|
+
`<text-input>`; `(scroll)`, `(layout)`. A pressable text is `<text pressable (press)="...">`.
|
|
39
|
+
- **Signals, zoneless, AOT.** State is signals and `computed()`; there is no zone.js, so nothing
|
|
40
|
+
updates from a plain field changing outside a signal or an event.
|
|
41
|
+
- **No backticks inside an inline template**, even in an HTML comment: they end the template string
|
|
42
|
+
and the build fails with a misleading parse error.
|
|
43
|
+
- **Accessibility is props:** `accessibilityRole="button"`, `accessibilityLabel`,
|
|
44
|
+
`[accessibilityState]`. Screen readers and the testing library's `getByRole` both read them.
|
|
45
|
+
|
|
46
|
+
## Styling
|
|
47
|
+
|
|
48
|
+
- `[style]` takes a React Native style object: camelCase keys, numbers in points
|
|
49
|
+
(`{ padding: 16, backgroundColor: '#fff' }`).
|
|
50
|
+
- A component's `styles` is real CSS, compiled at build time: type, class, id and attribute
|
|
51
|
+
selectors, combinators, `:host`, `@media`, custom properties, transitions and `@keyframes`.
|
|
52
|
+
Grid, float, `::before`/`::after`, `:hover` and `:focus-visible` are dropped with a build
|
|
53
|
+
warning naming the file, line and reason - lay out with flexbox, and drive a hover or focus look
|
|
54
|
+
from a bound attribute. Everything is `display: flex`
|
|
55
|
+
with `flex-direction: column` by default, as in React Native.
|
|
56
|
+
- Tailwind v4 works through `@ng-native/tailwind`, with `ios:`, `android:` and `dark:` variants.
|
|
57
|
+
|
|
58
|
+
## Lists, navigation, forms
|
|
59
|
+
|
|
60
|
+
- A long list is `<virtual-list>`: `@for (row of list.window(); track row.slot)` recycles rows as
|
|
61
|
+
they scroll. `<scroll-view>` renders everything, so keep it for short content.
|
|
62
|
+
- Navigation is `@angular/router` on native stacks and tabs: `provideNativeRouter(routes)` from
|
|
63
|
+
`@ng-native/router` in `mount`'s `providers`, and `<native-stack-outlet />` in a template. Add
|
|
64
|
+
`withComponentInputBinding()` from `@angular/router` for route params to arrive as inputs, in
|
|
65
|
+
tests too.
|
|
66
|
+
- Forms are Signal Forms (`@angular/forms/signals`), with `[formField]` on `<text-input>` and
|
|
67
|
+
`<switch>`.
|
|
68
|
+
- HTTP needs `provideNativeHttpClient()` from `@ng-native/platform/http`, not `provideHttpClient()`.
|
|
69
|
+
|
|
70
|
+
## Tests
|
|
71
|
+
|
|
72
|
+
`app.test.ts` shows the shape: `render(Component)`, then query with `screen.getByRole`,
|
|
73
|
+
`getByText` or `getByTestId` (which matches `nativeID` and `testID`), and act with
|
|
74
|
+
`userEvent.setup().press(...)` or `.type(...)`, all from `@ng-native/testing`. Tests run in Node
|
|
75
|
+
with no simulator, so write one alongside a change.
|
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
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
-
#
|
|
1
|
+
# My Angular Native app
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An Angular app rendering real native views, created from `@ng-native/template`.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm start # Metro; scan the QR code with Expo Go, or press i / a for a simulator
|
|
7
|
+
npm run ios # straight to the iOS simulator
|
|
8
|
+
npm run android # straight to the Android emulator
|
|
9
|
+
npm test # the example test in src/app/app.test.ts, in Node with no simulator
|
|
10
|
+
npm run typecheck
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`src/app/app.ts` is the root component and `src/main.ts` mounts it. Expo Go is enough for development; a
|
|
14
|
+
release build or a native module Expo Go does not include needs a development build
|
|
15
|
+
(`npx expo run:ios`).
|
|
16
|
+
|
|
17
|
+
The app targets iOS and Android, so there is no `npm run web`, whatever `create-expo-app` suggests
|
|
18
|
+
as it finishes. Angular Native components can also render in a browser, set up as
|
|
19
|
+
https://ng-native.com/guide/native-and-web describes.
|
|
20
|
+
|
|
21
|
+
`AGENTS.md` tells a coding agent how this framework differs from the web Angular it knows
|
|
22
|
+
(Claude Code reads it through `CLAUDE.md`). Add your own conventions to it as the app grows.
|
|
23
|
+
|
|
24
|
+
Docs: https://ng-native.com
|
package/app.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"expo": {
|
|
3
|
+
"name": "my-app",
|
|
4
|
+
"slug": "my-app",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"platforms": ["ios", "android"],
|
|
7
|
+
"orientation": "portrait",
|
|
8
|
+
"icon": "./assets/icon.png",
|
|
9
|
+
"userInterfaceStyle": "dark",
|
|
10
|
+
"ios": {
|
|
11
|
+
"supportsTablet": true
|
|
12
|
+
},
|
|
13
|
+
"android": {
|
|
14
|
+
"adaptiveIcon": {
|
|
15
|
+
"backgroundColor": "#E6F4FE",
|
|
16
|
+
"foregroundImage": "./assets/android-icon-foreground.png",
|
|
17
|
+
"backgroundImage": "./assets/android-icon-background.png",
|
|
18
|
+
"monochromeImage": "./assets/android-icon-monochrome.png"
|
|
19
|
+
},
|
|
20
|
+
"predictiveBackGestureEnabled": false
|
|
21
|
+
},
|
|
22
|
+
"scheme": "myapp",
|
|
23
|
+
"extra": {
|
|
24
|
+
"router": {
|
|
25
|
+
"root": "src/app"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/assets/icon.png
ADDED
|
Binary file
|
|
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,7 @@
|
|
|
1
|
+
const { getDefaultConfig } = require('expo/metro-config');
|
|
2
|
+
const { withAngularNative } = require('@ng-native/metro/config.cjs');
|
|
3
|
+
|
|
4
|
+
// Registers the transformer that compiles Angular ahead of time, compiles each component's CSS
|
|
5
|
+
// into the sheet the engine reads, and adds the polyfills Angular needs before `@angular/core`
|
|
6
|
+
// is first evaluated. No options: the framework packages are ordinary dependencies here.
|
|
7
|
+
module.exports = withAngularNative(getDefaultConfig(__dirname));
|
package/package.json
CHANGED
|
@@ -1,11 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ng-native/template",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "An Angular app rendering real native views. Use with create-expo-app --template.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"main": "src/main.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@angular/common": "^22.0.0",
|
|
9
|
+
"@angular/core": "^22.0.0",
|
|
10
|
+
"expo": "~57.0.20",
|
|
11
|
+
"expo-status-bar": "~57.0.1",
|
|
12
|
+
"react": "19.2.3",
|
|
13
|
+
"react-native": "0.86.3",
|
|
14
|
+
"react-native-safe-area-context": "~5.7.0",
|
|
15
|
+
"@ng-native/components": "0.1.1",
|
|
16
|
+
"@ng-native/metro": "0.1.1",
|
|
17
|
+
"@ng-native/fabric": "0.1.1",
|
|
18
|
+
"@ng-native/platform": "0.1.1",
|
|
19
|
+
"@ng-native/device": "0.1.1"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@angular/compiler-cli": "^22.0.0",
|
|
23
|
+
"@babel/core": "^7.29.7",
|
|
24
|
+
"@types/react": "~19.2.2",
|
|
25
|
+
"typescript": "~6.0.3",
|
|
26
|
+
"vitest": "^5.0.0",
|
|
27
|
+
"@ng-native/testing": "0.1.1"
|
|
28
|
+
},
|
|
6
29
|
"repository": {
|
|
7
30
|
"type": "git",
|
|
8
31
|
"url": "git+https://github.com/ng-native/ng-native.git",
|
|
9
32
|
"directory": "template"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"start": "expo start",
|
|
39
|
+
"android": "expo start --android",
|
|
40
|
+
"ios": "expo start --ios",
|
|
41
|
+
"typecheck": "ngc -p tsconfig.json --noEmit",
|
|
42
|
+
"test": "vitest run"
|
|
10
43
|
}
|
|
11
44
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { render, screen, userEvent } from '@ng-native/testing';
|
|
2
|
+
import { expect, test } from 'vitest';
|
|
3
|
+
import { App } from './app.ts';
|
|
4
|
+
|
|
5
|
+
test('counts taps', async () => {
|
|
6
|
+
await render(App);
|
|
7
|
+
|
|
8
|
+
await userEvent.setup().press(screen.getByRole('button', { name: 'Tapped 0 times' }));
|
|
9
|
+
|
|
10
|
+
expect(screen.getByText('Tapped 1 times')).toBeTruthy();
|
|
11
|
+
});
|
package/src/app/app.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Component, signal } from '@angular/core';
|
|
2
|
+
import { Pressable, SafeAreaView, Text, View } from '@ng-native/components';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Element names are lowercase, and that is load-bearing rather than style: an uppercase name is
|
|
6
|
+
* read as an unknown Angular component and commits as a plain view with nothing in it.
|
|
7
|
+
*/
|
|
8
|
+
@Component({
|
|
9
|
+
imports: [Pressable, SafeAreaView, Text, View],
|
|
10
|
+
selector: 'app-root',
|
|
11
|
+
template: `
|
|
12
|
+
<safe-area-view class="screen">
|
|
13
|
+
<view class="body">
|
|
14
|
+
<text class="title">Angular, natively</text>
|
|
15
|
+
<text class="hint">Real native views. React is never in the render path.</text>
|
|
16
|
+
|
|
17
|
+
<pressable accessibilityRole="button" class="button" (press)="count.set(count() + 1)">
|
|
18
|
+
<text class="label">Tapped {{ count() }} times</text>
|
|
19
|
+
</pressable>
|
|
20
|
+
</view>
|
|
21
|
+
</safe-area-view>
|
|
22
|
+
`,
|
|
23
|
+
styles: `
|
|
24
|
+
:host {
|
|
25
|
+
flex: 1;
|
|
26
|
+
}
|
|
27
|
+
.screen {
|
|
28
|
+
flex: 1;
|
|
29
|
+
background-color: #101014;
|
|
30
|
+
}
|
|
31
|
+
.body {
|
|
32
|
+
flex: 1;
|
|
33
|
+
justify-content: center;
|
|
34
|
+
gap: 12px;
|
|
35
|
+
padding: 24px;
|
|
36
|
+
}
|
|
37
|
+
.title {
|
|
38
|
+
color: #ffffff;
|
|
39
|
+
font-size: 28px;
|
|
40
|
+
font-weight: 700;
|
|
41
|
+
}
|
|
42
|
+
.hint {
|
|
43
|
+
color: #8b8b96;
|
|
44
|
+
font-size: 15px;
|
|
45
|
+
}
|
|
46
|
+
.button {
|
|
47
|
+
align-items: center;
|
|
48
|
+
margin-top: 8px;
|
|
49
|
+
padding: 14px;
|
|
50
|
+
border-radius: 10px;
|
|
51
|
+
background-color: #3b6ef5;
|
|
52
|
+
}
|
|
53
|
+
.label {
|
|
54
|
+
color: #ffffff;
|
|
55
|
+
font-size: 16px;
|
|
56
|
+
font-weight: 600;
|
|
57
|
+
}
|
|
58
|
+
`,
|
|
59
|
+
})
|
|
60
|
+
export class App {
|
|
61
|
+
protected readonly count = signal(0);
|
|
62
|
+
}
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AppRegistry, Image, Platform, processColor } from 'react-native';
|
|
2
|
+
import { mount } from '@ng-native/platform';
|
|
3
|
+
import { currentConditions, deviceTokens, watchConditions } from '@ng-native/device';
|
|
4
|
+
import { getFabricUIManager, registerPlatformComponents } from '@ng-native/fabric';
|
|
5
|
+
import { App } from './app/app.ts';
|
|
6
|
+
|
|
7
|
+
registerPlatformComponents(Platform.OS);
|
|
8
|
+
|
|
9
|
+
AppRegistry.registerRunnable('main', ({ rootTag }: { rootTag: number | string }) => {
|
|
10
|
+
const app = mount(Number(rootTag), App, getFabricUIManager(), {
|
|
11
|
+
// Colours, as the integers the platform wants.
|
|
12
|
+
processColor,
|
|
13
|
+
// What `@media` resolves against. Without it every media query is false and a responsive
|
|
14
|
+
// layout renders as its smallest case.
|
|
15
|
+
conditions: currentConditions(),
|
|
16
|
+
// Values only the device knows - the hairline width, which is a third of a point on a 3x
|
|
17
|
+
// screen. Without it `1px` is what you get, and that is a visibly fat divider.
|
|
18
|
+
tokens: deviceTokens(),
|
|
19
|
+
// Turns a `require('./x.png')` into something native can load. Without it images are blank.
|
|
20
|
+
resolveAssetSource: (value) => Image.resolveAssetSource(value as never),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Re-resolves the conditions when the device rotates or the theme changes. A rotation dirties
|
|
24
|
+
// no component and no binding, so without this nothing re-renders and `dark:` stops following
|
|
25
|
+
// the system switch.
|
|
26
|
+
watchConditions(app.engine);
|
|
27
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ngNative } from '@ng-native/testing/vitest';
|
|
2
|
+
import { defineConfig } from 'vitest/config';
|
|
3
|
+
|
|
4
|
+
// Compiles Angular for the tests the way Metro compiles it for the app. Tests run in Node against
|
|
5
|
+
// a fake of the native side: no simulator, no device.
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
plugins: [ngNative()],
|
|
8
|
+
});
|