@ng-native/expo 0.0.1 → 0.1.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/LICENSE +21 -0
- package/README.md +413 -1
- package/dist/app-info.d.ts +58 -0
- package/dist/app-info.js +71 -0
- package/dist/app-info.js.map +1 -0
- package/dist/apple-sign-in-button.d.ts +16 -0
- package/dist/apple-sign-in-button.js +55 -0
- package/dist/apple-sign-in-button.js.map +1 -0
- package/dist/apple-sign-in.d.ts +68 -0
- package/dist/apple-sign-in.js +120 -0
- package/dist/apple-sign-in.js.map +1 -0
- package/dist/assets.d.ts +24 -0
- package/dist/assets.js +47 -0
- package/dist/assets.js.map +1 -0
- package/dist/background-task.d.ts +66 -0
- package/dist/background-task.js +82 -0
- package/dist/background-task.js.map +1 -0
- package/dist/battery.d.ts +46 -0
- package/dist/battery.js +76 -0
- package/dist/battery.js.map +1 -0
- package/dist/biometrics.d.ts +45 -0
- package/dist/biometrics.js +53 -0
- package/dist/biometrics.js.map +1 -0
- package/dist/brightness.d.ts +38 -0
- package/dist/brightness.js +81 -0
- package/dist/brightness.js.map +1 -0
- package/dist/browser.d.ts +42 -0
- package/dist/browser.js +42 -0
- package/dist/browser.js.map +1 -0
- package/dist/camera.d.ts +48 -0
- package/dist/camera.js +59 -0
- package/dist/camera.js.map +1 -0
- package/dist/clipboard.d.ts +43 -0
- package/dist/clipboard.js +60 -0
- package/dist/clipboard.js.map +1 -0
- package/dist/community-views.d.ts +14 -0
- package/dist/community-views.js +76 -0
- package/dist/community-views.js.map +1 -0
- package/dist/crypto.d.ts +56 -0
- package/dist/crypto.js +84 -0
- package/dist/crypto.js.map +1 -0
- package/dist/database.d.ts +47 -0
- package/dist/database.js +108 -0
- package/dist/database.js.map +1 -0
- package/dist/document-picker.d.ts +34 -0
- package/dist/document-picker.js +40 -0
- package/dist/document-picker.js.map +1 -0
- package/dist/dom-component.d.ts +87 -0
- package/dist/dom-component.js +139 -0
- package/dist/dom-component.js.map +1 -0
- package/dist/expo-image.d.ts +33 -0
- package/dist/expo-image.js +57 -0
- package/dist/expo-image.js.map +1 -0
- package/dist/expo-ui-components.d.ts +327 -0
- package/dist/expo-ui-components.js +707 -0
- package/dist/expo-ui-components.js.map +1 -0
- package/dist/expo-ui.d.ts +46 -0
- package/dist/expo-ui.js +128 -0
- package/dist/expo-ui.js.map +1 -0
- package/dist/file-system.d.ts +63 -0
- package/dist/file-system.js +67 -0
- package/dist/file-system.js.map +1 -0
- package/dist/fonts.d.ts +90 -0
- package/dist/fonts.js +118 -0
- package/dist/fonts.js.map +1 -0
- package/dist/glass.d.ts +33 -0
- package/dist/glass.js +72 -0
- package/dist/glass.js.map +1 -0
- package/dist/haptics.d.ts +49 -0
- package/dist/haptics.js +64 -0
- package/dist/haptics.js.map +1 -0
- package/dist/image-editor.d.ts +62 -0
- package/dist/image-editor.js +101 -0
- package/dist/image-editor.js.map +1 -0
- package/dist/image-picker.d.ts +49 -0
- package/dist/image-picker.js +58 -0
- package/dist/image-picker.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/keep-awake.d.ts +39 -0
- package/dist/keep-awake.js +80 -0
- package/dist/keep-awake.js.map +1 -0
- package/dist/language-model.d.ts +129 -0
- package/dist/language-model.js +225 -0
- package/dist/language-model.js.map +1 -0
- package/dist/locale.d.ts +51 -0
- package/dist/locale.js +78 -0
- package/dist/locale.js.map +1 -0
- package/dist/location.d.ts +68 -0
- package/dist/location.js +83 -0
- package/dist/location.js.map +1 -0
- package/dist/map-view.d.ts +203 -0
- package/dist/map-view.js +184 -0
- package/dist/map-view.js.map +1 -0
- package/dist/media-library.d.ts +103 -0
- package/dist/media-library.js +160 -0
- package/dist/media-library.js.map +1 -0
- package/dist/native-state.d.ts +22 -0
- package/dist/native-state.js +43 -0
- package/dist/native-state.js.map +1 -0
- package/dist/native.d.ts +42 -0
- package/dist/native.js +73 -0
- package/dist/native.js.map +1 -0
- package/dist/network.d.ts +35 -0
- package/dist/network.js +60 -0
- package/dist/network.js.map +1 -0
- package/dist/notifications.d.ts +175 -0
- package/dist/notifications.js +296 -0
- package/dist/notifications.js.map +1 -0
- package/dist/observed.d.ts +37 -0
- package/dist/observed.js +55 -0
- package/dist/observed.js.map +1 -0
- package/dist/orientation.d.ts +35 -0
- package/dist/orientation.js +78 -0
- package/dist/orientation.js.map +1 -0
- package/dist/permissions.d.ts +54 -0
- package/dist/permissions.js +72 -0
- package/dist/permissions.js.map +1 -0
- package/dist/player.d.ts +92 -0
- package/dist/player.js +141 -0
- package/dist/player.js.map +1 -0
- package/dist/register-expo-view.d.ts +55 -0
- package/dist/register-expo-view.js +110 -0
- package/dist/register-expo-view.js.map +1 -0
- package/dist/screen-capture.d.ts +58 -0
- package/dist/screen-capture.js +78 -0
- package/dist/screen-capture.js.map +1 -0
- package/dist/segmented-control.d.ts +32 -0
- package/dist/segmented-control.js +55 -0
- package/dist/segmented-control.js.map +1 -0
- package/dist/sensors.d.ts +85 -0
- package/dist/sensors.js +115 -0
- package/dist/sensors.js.map +1 -0
- package/dist/splash-screen.d.ts +73 -0
- package/dist/splash-screen.js +115 -0
- package/dist/splash-screen.js.map +1 -0
- package/dist/store-review.d.ts +43 -0
- package/dist/store-review.js +52 -0
- package/dist/store-review.js.map +1 -0
- package/dist/store.d.ts +108 -0
- package/dist/store.js +247 -0
- package/dist/store.js.map +1 -0
- package/dist/symbol.d.ts +36 -0
- package/dist/symbol.js +69 -0
- package/dist/symbol.js.map +1 -0
- package/dist/tracking.d.ts +45 -0
- package/dist/tracking.js +54 -0
- package/dist/tracking.js.map +1 -0
- package/dist/transforms.d.ts +2 -0
- package/dist/transforms.js +13 -0
- package/dist/transforms.js.map +1 -0
- package/dist/updates.d.ts +61 -0
- package/dist/updates.js +97 -0
- package/dist/updates.js.map +1 -0
- package/package.json +397 -3
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `StoreReview`, bound to `expo-store-review`: the platform's "rate this app" prompt.
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* private readonly review = inject(StoreReview);
|
|
6
|
+
*
|
|
7
|
+
* async finishedFifthWorkout(): Promise<void> {
|
|
8
|
+
* if (await this.review.hasAction()) await this.review.request();
|
|
9
|
+
* }
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* The module's own four functions under shorter names. The prompt is the platform's, and so is the
|
|
13
|
+
* decision whether it appears at all: iOS shows it at most three times a year and says nothing
|
|
14
|
+
* when it declines, so a call that resolves is not a prompt that was shown. Without the module
|
|
15
|
+
* installed, every question answers no and `request()` does nothing.
|
|
16
|
+
*/
|
|
17
|
+
import { InjectionToken } from '@angular/core';
|
|
18
|
+
import * as i0 from "@angular/core";
|
|
19
|
+
type Expo = typeof import('expo-store-review');
|
|
20
|
+
/** The module's functions this service calls. The real module is one; a test provides a fake. */
|
|
21
|
+
export type NativeStoreReview = Pick<Expo, 'isAvailableAsync' | 'hasAction' | 'requestReview' | 'storeUrl'>;
|
|
22
|
+
export declare class StoreReview {
|
|
23
|
+
/** Overridden in a test to ask for a review nobody will be shown. */
|
|
24
|
+
static readonly SOURCE: InjectionToken<NativeStoreReview | null>;
|
|
25
|
+
private readonly native;
|
|
26
|
+
/** Whether the platform has an in-app review prompt: iOS, and Android with the Play Store. */
|
|
27
|
+
available(): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Whether `request()` would do anything: show the prompt, or failing that open the store page
|
|
30
|
+
* set as `ios.appStoreUrl` or `android.playStoreUrl` in the app config.
|
|
31
|
+
*/
|
|
32
|
+
hasAction(): Promise<boolean>;
|
|
33
|
+
/**
|
|
34
|
+
* Asks the platform to show the prompt, or opens the store page where there is none. Resolves
|
|
35
|
+
* whether or not the platform chose to show anything.
|
|
36
|
+
*/
|
|
37
|
+
request(): Promise<void>;
|
|
38
|
+
/** The app's store page from the app config, for a "rate us" link. Null when none is set. */
|
|
39
|
+
storeUrl(): string | null;
|
|
40
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<StoreReview, never>;
|
|
41
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `StoreReview`, bound to `expo-store-review`: the platform's "rate this app" prompt.
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* private readonly review = inject(StoreReview);
|
|
6
|
+
*
|
|
7
|
+
* async finishedFifthWorkout(): Promise<void> {
|
|
8
|
+
* if (await this.review.hasAction()) await this.review.request();
|
|
9
|
+
* }
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* The module's own four functions under shorter names. The prompt is the platform's, and so is the
|
|
13
|
+
* decision whether it appears at all: iOS shows it at most three times a year and says nothing
|
|
14
|
+
* when it declines, so a call that resolves is not a prompt that was shown. Without the module
|
|
15
|
+
* installed, every question answers no and `request()` does nothing.
|
|
16
|
+
*/
|
|
17
|
+
import { InjectionToken, Service, inject } from '@angular/core';
|
|
18
|
+
import { expoModule } from "./native.js";
|
|
19
|
+
import * as i0 from "@angular/core";
|
|
20
|
+
export class StoreReview {
|
|
21
|
+
/** Overridden in a test to ask for a review nobody will be shown. */
|
|
22
|
+
static SOURCE = new InjectionToken('angular-native.storeReviewSource', { factory: () => expoModule('expo-store-review', () => require('expo-store-review')) });
|
|
23
|
+
native = inject(StoreReview.SOURCE);
|
|
24
|
+
/** Whether the platform has an in-app review prompt: iOS, and Android with the Play Store. */
|
|
25
|
+
async available() {
|
|
26
|
+
return (await this.native?.isAvailableAsync()) ?? false;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Whether `request()` would do anything: show the prompt, or failing that open the store page
|
|
30
|
+
* set as `ios.appStoreUrl` or `android.playStoreUrl` in the app config.
|
|
31
|
+
*/
|
|
32
|
+
async hasAction() {
|
|
33
|
+
return (await this.native?.hasAction()) ?? false;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Asks the platform to show the prompt, or opens the store page where there is none. Resolves
|
|
37
|
+
* whether or not the platform chose to show anything.
|
|
38
|
+
*/
|
|
39
|
+
async request() {
|
|
40
|
+
await this.native?.requestReview();
|
|
41
|
+
}
|
|
42
|
+
/** The app's store page from the app config, for a "rate us" link. Null when none is set. */
|
|
43
|
+
storeUrl() {
|
|
44
|
+
return this.native?.storeUrl() ?? null;
|
|
45
|
+
}
|
|
46
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: StoreReview, deps: [], target: i0.ɵɵFactoryTarget.Service });
|
|
47
|
+
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: StoreReview });
|
|
48
|
+
}
|
|
49
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: StoreReview, decorators: [{
|
|
50
|
+
type: Service
|
|
51
|
+
}] });
|
|
52
|
+
//# sourceMappingURL=store-review.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-review.js","sourceRoot":"","sources":["../src/store-review.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;;AAWzC,MAAM,OAAO,WAAW;IACtB,qEAAqE;IACrE,MAAM,CAAU,MAAM,GAAG,IAAI,cAAc,CACzC,kCAAkC,EAClC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,mBAAmB,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,mBAAmB,CAAS,CAAC,EAAE,CAC/F,CAAC;IAEe,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAErD,8FAA8F;IAC9F,KAAK,CAAC,SAAS;QACb,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE,gBAAgB,EAAE,CAAC,IAAI,KAAK,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,SAAS;QACb,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,IAAI,KAAK,CAAC;IACnD,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,MAAM,EAAE,aAAa,EAAE,CAAC;IACrC,CAAC;IAED,6FAA6F;IAC7F,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,IAAI,CAAC;IACzC,CAAC;uGAjCU,WAAW;wGAAX,WAAW;;2FAAX,WAAW;kBADvB,OAAO","sourcesContent":["/**\n * `StoreReview`, bound to `expo-store-review`: the platform's \"rate this app\" prompt.\n *\n * ```ts\n * private readonly review = inject(StoreReview);\n *\n * async finishedFifthWorkout(): Promise<void> {\n * if (await this.review.hasAction()) await this.review.request();\n * }\n * ```\n *\n * The module's own four functions under shorter names. The prompt is the platform's, and so is the\n * decision whether it appears at all: iOS shows it at most three times a year and says nothing\n * when it declines, so a call that resolves is not a prompt that was shown. Without the module\n * installed, every question answers no and `request()` does nothing.\n */\nimport { InjectionToken, Service, inject } from '@angular/core';\nimport { expoModule } from './native.ts';\n\ntype Expo = typeof import('expo-store-review');\n\n/** The module's functions this service calls. The real module is one; a test provides a fake. */\nexport type NativeStoreReview = Pick<\n Expo,\n 'isAvailableAsync' | 'hasAction' | 'requestReview' | 'storeUrl'\n>;\n\n@Service()\nexport class StoreReview {\n /** Overridden in a test to ask for a review nobody will be shown. */\n static readonly SOURCE = new InjectionToken<NativeStoreReview | null>(\n 'angular-native.storeReviewSource',\n { factory: () => expoModule('expo-store-review', () => require('expo-store-review') as Expo) },\n );\n\n private readonly native = inject(StoreReview.SOURCE);\n\n /** Whether the platform has an in-app review prompt: iOS, and Android with the Play Store. */\n async available(): Promise<boolean> {\n return (await this.native?.isAvailableAsync()) ?? false;\n }\n\n /**\n * Whether `request()` would do anything: show the prompt, or failing that open the store page\n * set as `ios.appStoreUrl` or `android.playStoreUrl` in the app config.\n */\n async hasAction(): Promise<boolean> {\n return (await this.native?.hasAction()) ?? false;\n }\n\n /**\n * Asks the platform to show the prompt, or opens the store page where there is none. Resolves\n * whether or not the platform chose to show anything.\n */\n async request(): Promise<void> {\n await this.native?.requestReview();\n }\n\n /** The app's store page from the app config, for a \"rate us\" link. Null when none is set. */\n storeUrl(): string | null {\n return this.native?.storeUrl() ?? null;\n }\n}\n"]}
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Storage` and `SecureStorage`, bound to `@react-native-async-storage/async-storage` and
|
|
3
|
+
* `expo-secure-store`.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* private readonly store = inject(Storage);
|
|
7
|
+
* protected readonly theme = this.store.signal<'light' | 'dark'>('theme', 'light');
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* The signal is bound both ways: reading it is reading the preference, setting it persists.
|
|
11
|
+
*
|
|
12
|
+
* The underlying APIs are already plain promises with no React in them, so what is built is not a
|
|
13
|
+
* wrapper but a *binding*: `store.signal('theme', 'light')` reads it back once, writes it through
|
|
14
|
+
* whenever it is set, and is an ordinary signal in between. Everything is JSON, because both
|
|
15
|
+
* stores hold strings and a store that silently held `"[object Object]"` would be worse than one
|
|
16
|
+
* that held nothing.
|
|
17
|
+
*
|
|
18
|
+
* Two services rather than one because the difference matters and should be visible at the
|
|
19
|
+
* injection site. `SecureStorage` is the keychain and the Android keystore: small values, an
|
|
20
|
+
* async write, and a size limit that is not documented but is real. `Storage` is a plain
|
|
21
|
+
* key-value file: bigger, faster, and readable by anyone with the device unlocked. Two tokens
|
|
22
|
+
* over one class, for the same reason the sensors are.
|
|
23
|
+
*/
|
|
24
|
+
import { InjectionToken, type Signal, type WritableSignal } from '@angular/core';
|
|
25
|
+
/** What both `AsyncStorage` and `SecureStore` offer, reduced to the three verbs. */
|
|
26
|
+
export interface NativeStore {
|
|
27
|
+
get(key: string): Promise<string | null>;
|
|
28
|
+
set(key: string, value: string): Promise<void>;
|
|
29
|
+
remove(key: string): Promise<void>;
|
|
30
|
+
/** Where the platform can answer without waiting - `SecureStore` can, `AsyncStorage` cannot. */
|
|
31
|
+
getSync?(key: string): string | null;
|
|
32
|
+
}
|
|
33
|
+
export declare class Store {
|
|
34
|
+
private readonly native;
|
|
35
|
+
private readonly bound;
|
|
36
|
+
/** Keys written by the app before their read came back. The read must not undo a write. */
|
|
37
|
+
private readonly written;
|
|
38
|
+
/**
|
|
39
|
+
* Updates made to a key whose read has not come back, in order. An update changes the stored
|
|
40
|
+
* value rather than replacing it, so these wait for it and are applied to it, not to `initial`.
|
|
41
|
+
*/
|
|
42
|
+
private readonly waiting;
|
|
43
|
+
/** Reads started and not yet back, successful or not. */
|
|
44
|
+
private readonly reading;
|
|
45
|
+
private readonly failure;
|
|
46
|
+
/** Writes sent to the platform and not yet answered. What `flush()` waits for. */
|
|
47
|
+
private readonly writes;
|
|
48
|
+
/** The first write to fail since the last `flush()`, held until a flush reports it. */
|
|
49
|
+
private unreported;
|
|
50
|
+
constructor(native: NativeStore | null);
|
|
51
|
+
/**
|
|
52
|
+
* Whether every key asked for so far has been read back. False while any read is outstanding,
|
|
53
|
+
* so it goes back to false when a new key is asked for, and true again once that read returns.
|
|
54
|
+
*
|
|
55
|
+
* A read that fails still counts as back: the signal keeps its `initial`, and the failure is on
|
|
56
|
+
* `error`. A loading screen held on `ready` should not wait forever for a store that is broken.
|
|
57
|
+
*/
|
|
58
|
+
readonly ready: Signal<boolean>;
|
|
59
|
+
/**
|
|
60
|
+
* The most recent read or write that failed, or null while none has.
|
|
61
|
+
*
|
|
62
|
+
* A write through `set()` has no promise to reject, so this is where a full disk or a locked
|
|
63
|
+
* keychain is reported. `flush()` is the way to wait on the writes themselves.
|
|
64
|
+
*/
|
|
65
|
+
readonly error: Signal<Error | null>;
|
|
66
|
+
/**
|
|
67
|
+
* The stored value at `key`, as a signal that writes through when set.
|
|
68
|
+
*
|
|
69
|
+
* Starts at `initial` and stays there until the read returns, which is one turn away at best -
|
|
70
|
+
* unless the platform can answer synchronously, in which case it never shows `initial` at all.
|
|
71
|
+
* The same key always returns the same signal, so two components binding to it stay in step.
|
|
72
|
+
*/
|
|
73
|
+
signal<T>(key: string, initial: T): WritableSignal<T>;
|
|
74
|
+
/**
|
|
75
|
+
* Forget a key, in the store and in the signal bound to it.
|
|
76
|
+
*
|
|
77
|
+
* The signal goes back to the `initial` it was first asked for with, and stays the one signal
|
|
78
|
+
* for the key. Rejects if the platform could not remove it, which also sets `error`.
|
|
79
|
+
*/
|
|
80
|
+
remove(key: string): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Wait for every write sent so far. Rejects with the first of them that failed since the last
|
|
83
|
+
* `flush()`, whether it failed before this call or while waiting, so a screen that has to know a
|
|
84
|
+
* value reached the disk - before signing out, say - can find out. Each failure is reported by
|
|
85
|
+
* one flush only.
|
|
86
|
+
*/
|
|
87
|
+
flush(): Promise<void>;
|
|
88
|
+
private readSync;
|
|
89
|
+
/**
|
|
90
|
+
* Read the stored value in, unless the app has already set one.
|
|
91
|
+
*
|
|
92
|
+
* The race is real and silent: a screen that writes a preference during startup would otherwise
|
|
93
|
+
* have it overwritten a tick later by whatever was there before.
|
|
94
|
+
*/
|
|
95
|
+
private hydrate;
|
|
96
|
+
/** The read is back: show what was stored, with any updates that waited for it applied. */
|
|
97
|
+
private settle;
|
|
98
|
+
private write;
|
|
99
|
+
/** A platform call, kept until it answers, with its failure reported on `error`. */
|
|
100
|
+
private track;
|
|
101
|
+
private fail;
|
|
102
|
+
}
|
|
103
|
+
/** A plain key-value file. Bigger and faster than the keychain, and not private. */
|
|
104
|
+
export declare const Storage: InjectionToken<Store>;
|
|
105
|
+
export type Storage = Store;
|
|
106
|
+
/** The keychain and the Android keystore. Small values, and worth the size limit. */
|
|
107
|
+
export declare const SecureStorage: InjectionToken<Store>;
|
|
108
|
+
export type SecureStorage = Store;
|
package/dist/store.js
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Storage` and `SecureStorage`, bound to `@react-native-async-storage/async-storage` and
|
|
3
|
+
* `expo-secure-store`.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* private readonly store = inject(Storage);
|
|
7
|
+
* protected readonly theme = this.store.signal<'light' | 'dark'>('theme', 'light');
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* The signal is bound both ways: reading it is reading the preference, setting it persists.
|
|
11
|
+
*
|
|
12
|
+
* The underlying APIs are already plain promises with no React in them, so what is built is not a
|
|
13
|
+
* wrapper but a *binding*: `store.signal('theme', 'light')` reads it back once, writes it through
|
|
14
|
+
* whenever it is set, and is an ordinary signal in between. Everything is JSON, because both
|
|
15
|
+
* stores hold strings and a store that silently held `"[object Object]"` would be worse than one
|
|
16
|
+
* that held nothing.
|
|
17
|
+
*
|
|
18
|
+
* Two services rather than one because the difference matters and should be visible at the
|
|
19
|
+
* injection site. `SecureStorage` is the keychain and the Android keystore: small values, an
|
|
20
|
+
* async write, and a size limit that is not documented but is real. `Storage` is a plain
|
|
21
|
+
* key-value file: bigger, faster, and readable by anyone with the device unlocked. Two tokens
|
|
22
|
+
* over one class, for the same reason the sensors are.
|
|
23
|
+
*/
|
|
24
|
+
import { InjectionToken, computed, signal } from '@angular/core';
|
|
25
|
+
import { expoModule } from "./native.js";
|
|
26
|
+
export class Store {
|
|
27
|
+
native;
|
|
28
|
+
bound = new Map();
|
|
29
|
+
/** Keys written by the app before their read came back. The read must not undo a write. */
|
|
30
|
+
written = new Set();
|
|
31
|
+
/**
|
|
32
|
+
* Updates made to a key whose read has not come back, in order. An update changes the stored
|
|
33
|
+
* value rather than replacing it, so these wait for it and are applied to it, not to `initial`.
|
|
34
|
+
*/
|
|
35
|
+
waiting = new Map();
|
|
36
|
+
/** Reads started and not yet back, successful or not. */
|
|
37
|
+
reading = signal(0, /* @ts-ignore */
|
|
38
|
+
...(ngDevMode ? [{ debugName: "reading" }] : /* istanbul ignore next */ []));
|
|
39
|
+
failure = signal(null, /* @ts-ignore */
|
|
40
|
+
...(ngDevMode ? [{ debugName: "failure" }] : /* istanbul ignore next */ []));
|
|
41
|
+
/** Writes sent to the platform and not yet answered. What `flush()` waits for. */
|
|
42
|
+
writes = new Set();
|
|
43
|
+
/** The first write to fail since the last `flush()`, held until a flush reports it. */
|
|
44
|
+
unreported = null;
|
|
45
|
+
constructor(native) {
|
|
46
|
+
this.native = native;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Whether every key asked for so far has been read back. False while any read is outstanding,
|
|
50
|
+
* so it goes back to false when a new key is asked for, and true again once that read returns.
|
|
51
|
+
*
|
|
52
|
+
* A read that fails still counts as back: the signal keeps its `initial`, and the failure is on
|
|
53
|
+
* `error`. A loading screen held on `ready` should not wait forever for a store that is broken.
|
|
54
|
+
*/
|
|
55
|
+
ready = computed(() => this.reading() === 0, /* @ts-ignore */
|
|
56
|
+
...(ngDevMode ? [{ debugName: "ready" }] : /* istanbul ignore next */ []));
|
|
57
|
+
/**
|
|
58
|
+
* The most recent read or write that failed, or null while none has.
|
|
59
|
+
*
|
|
60
|
+
* A write through `set()` has no promise to reject, so this is where a full disk or a locked
|
|
61
|
+
* keychain is reported. `flush()` is the way to wait on the writes themselves.
|
|
62
|
+
*/
|
|
63
|
+
error = this.failure.asReadonly();
|
|
64
|
+
/**
|
|
65
|
+
* The stored value at `key`, as a signal that writes through when set.
|
|
66
|
+
*
|
|
67
|
+
* Starts at `initial` and stays there until the read returns, which is one turn away at best -
|
|
68
|
+
* unless the platform can answer synchronously, in which case it never shows `initial` at all.
|
|
69
|
+
* The same key always returns the same signal, so two components binding to it stay in step.
|
|
70
|
+
*/
|
|
71
|
+
signal(key, initial) {
|
|
72
|
+
const existing = this.bound.get(key);
|
|
73
|
+
if (existing)
|
|
74
|
+
return existing.value;
|
|
75
|
+
const stored = this.readSync(key);
|
|
76
|
+
const value = signal(stored === ABSENT ? initial : stored, /* @ts-ignore */
|
|
77
|
+
...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
|
|
78
|
+
const set = value.set.bind(value);
|
|
79
|
+
const update = value.update.bind(value);
|
|
80
|
+
value.set = (next) => {
|
|
81
|
+
this.written.add(key);
|
|
82
|
+
this.waiting.delete(key);
|
|
83
|
+
set(next);
|
|
84
|
+
this.write(key, next);
|
|
85
|
+
};
|
|
86
|
+
value.update = (fn) => {
|
|
87
|
+
// Shown at once, on what is known so far, and written once the stored value is known.
|
|
88
|
+
const waiting = this.waiting.get(key);
|
|
89
|
+
update(fn);
|
|
90
|
+
if (waiting) {
|
|
91
|
+
waiting.push(fn);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
this.written.add(key);
|
|
95
|
+
this.write(key, value());
|
|
96
|
+
};
|
|
97
|
+
this.bound.set(key, {
|
|
98
|
+
value: value,
|
|
99
|
+
reset: set,
|
|
100
|
+
initial,
|
|
101
|
+
});
|
|
102
|
+
// A platform that answered synchronously has said what is stored; one that cannot has not.
|
|
103
|
+
if (stored === ABSENT && this.native && !this.native.getSync)
|
|
104
|
+
this.waiting.set(key, []);
|
|
105
|
+
void this.hydrate(key, set, initial);
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Forget a key, in the store and in the signal bound to it.
|
|
110
|
+
*
|
|
111
|
+
* The signal goes back to the `initial` it was first asked for with, and stays the one signal
|
|
112
|
+
* for the key. Rejects if the platform could not remove it, which also sets `error`.
|
|
113
|
+
*/
|
|
114
|
+
async remove(key) {
|
|
115
|
+
this.written.add(key);
|
|
116
|
+
this.waiting.delete(key);
|
|
117
|
+
const binding = this.bound.get(key);
|
|
118
|
+
binding?.reset(binding.initial);
|
|
119
|
+
await this.track(this.native?.remove(key));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Wait for every write sent so far. Rejects with the first of them that failed since the last
|
|
123
|
+
* `flush()`, whether it failed before this call or while waiting, so a screen that has to know a
|
|
124
|
+
* value reached the disk - before signing out, say - can find out. Each failure is reported by
|
|
125
|
+
* one flush only.
|
|
126
|
+
*/
|
|
127
|
+
async flush() {
|
|
128
|
+
await Promise.allSettled([...this.writes]);
|
|
129
|
+
const failed = this.unreported;
|
|
130
|
+
this.unreported = null;
|
|
131
|
+
if (failed)
|
|
132
|
+
throw failed.error;
|
|
133
|
+
}
|
|
134
|
+
readSync(key) {
|
|
135
|
+
const raw = this.native?.getSync?.(key);
|
|
136
|
+
return raw == null ? ABSENT : decode(raw);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Read the stored value in, unless the app has already set one.
|
|
140
|
+
*
|
|
141
|
+
* The race is real and silent: a screen that writes a preference during startup would otherwise
|
|
142
|
+
* have it overwritten a tick later by whatever was there before.
|
|
143
|
+
*/
|
|
144
|
+
async hydrate(key, set, initial) {
|
|
145
|
+
this.reading.update((n) => n + 1);
|
|
146
|
+
let stored = ABSENT;
|
|
147
|
+
try {
|
|
148
|
+
const raw = await this.native?.get(key);
|
|
149
|
+
if (raw != null)
|
|
150
|
+
stored = decode(raw);
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
this.fail(error);
|
|
154
|
+
}
|
|
155
|
+
finally {
|
|
156
|
+
this.settle(key, set, stored === ABSENT ? initial : stored, stored !== ABSENT);
|
|
157
|
+
this.reading.update((n) => n - 1);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/** The read is back: show what was stored, with any updates that waited for it applied. */
|
|
161
|
+
settle(key, set, base, found) {
|
|
162
|
+
const updates = this.waiting.get(key);
|
|
163
|
+
this.waiting.delete(key);
|
|
164
|
+
if (this.written.has(key))
|
|
165
|
+
return;
|
|
166
|
+
if (!updates?.length) {
|
|
167
|
+
if (found)
|
|
168
|
+
set(base);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const value = updates.reduce((current, fn) => fn(current), base);
|
|
172
|
+
this.written.add(key);
|
|
173
|
+
set(value);
|
|
174
|
+
this.write(key, value);
|
|
175
|
+
}
|
|
176
|
+
write(key, value) {
|
|
177
|
+
const sent = value === undefined ? this.native?.remove(key) : this.native?.set(key, JSON.stringify(value));
|
|
178
|
+
// Observed here, so a failure lands on `error` and in `flush()` rather than going unhandled.
|
|
179
|
+
this.track(sent).catch(() => { });
|
|
180
|
+
}
|
|
181
|
+
/** A platform call, kept until it answers, with its failure reported on `error`. */
|
|
182
|
+
track(sent) {
|
|
183
|
+
if (!sent)
|
|
184
|
+
return Promise.resolve();
|
|
185
|
+
const tracked = sent.then(() => undefined, (error) => {
|
|
186
|
+
this.fail(error);
|
|
187
|
+
this.unreported ??= { error };
|
|
188
|
+
throw error;
|
|
189
|
+
});
|
|
190
|
+
this.writes.add(tracked);
|
|
191
|
+
const forget = () => void this.writes.delete(tracked);
|
|
192
|
+
tracked.then(forget, forget);
|
|
193
|
+
return tracked;
|
|
194
|
+
}
|
|
195
|
+
fail(error) {
|
|
196
|
+
this.failure.set(error instanceof Error ? error : new Error(String(error)));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/** What `decode` answers for a string that is not JSON, since `null` is a value JSON can hold. */
|
|
200
|
+
const ABSENT = Symbol('absent');
|
|
201
|
+
/**
|
|
202
|
+
* A stored string as the value it encodes.
|
|
203
|
+
*
|
|
204
|
+
* A value that will not parse is treated as absent rather than thrown: it is a store written by
|
|
205
|
+
* an older version of the app, and the right answer is the default the caller already supplied.
|
|
206
|
+
* A stored `null` is not that: it parses, and a nullable signal gets it back.
|
|
207
|
+
*/
|
|
208
|
+
function decode(raw) {
|
|
209
|
+
try {
|
|
210
|
+
return JSON.parse(raw);
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
return ABSENT;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const plain = () => {
|
|
217
|
+
const module = expoModule('@react-native-async-storage/async-storage', () => require('@react-native-async-storage/async-storage'));
|
|
218
|
+
const store = module?.default;
|
|
219
|
+
if (!store)
|
|
220
|
+
return null;
|
|
221
|
+
return {
|
|
222
|
+
get: (key) => store.getItem(key),
|
|
223
|
+
set: (key, value) => store.setItem(key, value),
|
|
224
|
+
remove: (key) => store.removeItem(key),
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
const secure = () => {
|
|
228
|
+
const expo = expoModule('expo-secure-store', () => require('expo-secure-store'));
|
|
229
|
+
if (!expo)
|
|
230
|
+
return null;
|
|
231
|
+
return {
|
|
232
|
+
get: (key) => expo.getItemAsync(key),
|
|
233
|
+
set: (key, value) => expo.setItemAsync(key, value),
|
|
234
|
+
remove: (key) => expo.deleteItemAsync(key),
|
|
235
|
+
// The keychain can answer without waiting, so a token never flashes its default.
|
|
236
|
+
getSync: (key) => expo.getItem(key),
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
/** A plain key-value file. Bigger and faster than the keychain, and not private. */
|
|
240
|
+
export const Storage = new InjectionToken('angular-native.storage', {
|
|
241
|
+
factory: () => new Store(plain()),
|
|
242
|
+
});
|
|
243
|
+
/** The keychain and the Android keystore. Small values, and worth the size limit. */
|
|
244
|
+
export const SecureStorage = new InjectionToken('angular-native.secureStorage', {
|
|
245
|
+
factory: () => new Store(secure()),
|
|
246
|
+
});
|
|
247
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAoC,MAAM,eAAe,CAAC;AACnG,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC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O,CAAC,GAAG,CAAC;KACpC,CAAC;AACJ,CAAC,CAAC;AAEF,oFAAoF;AACpF,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,cAAc,CAAQ,wBAAwB,EAAE;IACzE,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;CAClC,CAAC,CAAC;AAGH,qFAAqF;AACrF,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,cAAc,CAAQ,8BAA8B,EAAE;IACrF,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;CACnC,CAAC,CAAC","sourcesContent":["/**\n * `Storage` and `SecureStorage`, bound to `@react-native-async-storage/async-storage` and\n * `expo-secure-store`.\n *\n * ```ts\n * private readonly store = inject(Storage);\n * protected readonly theme = this.store.signal<'light' | 'dark'>('theme', 'light');\n * ```\n *\n * The signal is bound both ways: reading it is reading the preference, setting it persists.\n *\n * The underlying APIs are already plain promises with no React in them, so what is built is not a\n * wrapper but a *binding*: `store.signal('theme', 'light')` reads it back once, writes it through\n * whenever it is set, and is an ordinary signal in between. Everything is JSON, because both\n * stores hold strings and a store that silently held `\"[object Object]\"` would be worse than one\n * that held nothing.\n *\n * Two services rather than one because the difference matters and should be visible at the\n * injection site. `SecureStorage` is the keychain and the Android keystore: small values, an\n * async write, and a size limit that is not documented but is real. `Storage` is a plain\n * key-value file: bigger, faster, and readable by anyone with the device unlocked. Two tokens\n * over one class, for the same reason the sensors are.\n */\nimport { InjectionToken, computed, signal, type Signal, type WritableSignal } from '@angular/core';\nimport { expoModule } from './native.ts';\n\n/** What both `AsyncStorage` and `SecureStore` offer, reduced to the three verbs. */\nexport interface NativeStore {\n get(key: string): Promise<string | null>;\n set(key: string, value: string): Promise<void>;\n remove(key: string): Promise<void>;\n /** Where the platform can answer without waiting - `SecureStore` can, `AsyncStorage` cannot. */\n getSync?(key: string): string | null;\n}\n\n/** A key's signal, with what `remove()` needs to put it back. */\ninterface Binding {\n readonly value: WritableSignal<unknown>;\n /** The signal's own `set`, which does not write through. */\n readonly reset: (value: unknown) => void;\n readonly initial: unknown;\n}\n\nexport class Store {\n private readonly native: NativeStore | null;\n private readonly bound = new Map<string, Binding>();\n /** Keys written by the app before their read came back. The read must not undo a write. */\n private readonly written = new Set<string>();\n /**\n * Updates made to a key whose read has not come back, in order. An update changes the stored\n * value rather than replacing it, so these wait for it and are applied to it, not to `initial`.\n */\n private readonly waiting = new Map<string, ((current: unknown) => unknown)[]>();\n /** Reads started and not yet back, successful or not. */\n private readonly reading = signal(0);\n private readonly failure = signal<Error | null>(null);\n /** Writes sent to the platform and not yet answered. What `flush()` waits for. */\n private readonly writes = new Set<Promise<void>>();\n /** The first write to fail since the last `flush()`, held until a flush reports it. */\n private unreported: { readonly error: unknown } | null = null;\n\n constructor(native: NativeStore | null) {\n this.native = native;\n }\n\n /**\n * Whether every key asked for so far has been read back. False while any read is outstanding,\n * so it goes back to false when a new key is asked for, and true again once that read returns.\n *\n * A read that fails still counts as back: the signal keeps its `initial`, and the failure is on\n * `error`. A loading screen held on `ready` should not wait forever for a store that is broken.\n */\n readonly ready: Signal<boolean> = computed(() => this.reading() === 0);\n\n /**\n * The most recent read or write that failed, or null while none has.\n *\n * A write through `set()` has no promise to reject, so this is where a full disk or a locked\n * keychain is reported. `flush()` is the way to wait on the writes themselves.\n */\n readonly error: Signal<Error | null> = this.failure.asReadonly();\n\n /**\n * The stored value at `key`, as a signal that writes through when set.\n *\n * Starts at `initial` and stays there until the read returns, which is one turn away at best -\n * unless the platform can answer synchronously, in which case it never shows `initial` at all.\n * The same key always returns the same signal, so two components binding to it stay in step.\n */\n signal<T>(key: string, initial: T): WritableSignal<T> {\n const existing = this.bound.get(key);\n if (existing) return existing.value as WritableSignal<T>;\n\n const stored = this.readSync(key);\n const value = signal<T>(stored === ABSENT ? initial : (stored as T));\n\n const set = value.set.bind(value);\n const update = value.update.bind(value);\n value.set = (next: T) => {\n this.written.add(key);\n this.waiting.delete(key);\n set(next);\n this.write(key, next);\n };\n value.update = (fn: (current: T) => T) => {\n // Shown at once, on what is known so far, and written once the stored value is known.\n const waiting = this.waiting.get(key);\n update(fn);\n if (waiting) {\n waiting.push(fn as (current: unknown) => unknown);\n return;\n }\n this.written.add(key);\n this.write(key, value());\n };\n this.bound.set(key, {\n value: value as WritableSignal<unknown>,\n reset: set as (value: unknown) => void,\n initial,\n });\n\n // A platform that answered synchronously has said what is stored; one that cannot has not.\n if (stored === ABSENT && this.native && !this.native.getSync) this.waiting.set(key, []);\n void this.hydrate(key, set, initial);\n return value;\n }\n\n /**\n * Forget a key, in the store and in the signal bound to it.\n *\n * The signal goes back to the `initial` it was first asked for with, and stays the one signal\n * for the key. Rejects if the platform could not remove it, which also sets `error`.\n */\n async remove(key: string): Promise<void> {\n this.written.add(key);\n this.waiting.delete(key);\n const binding = this.bound.get(key);\n binding?.reset(binding.initial);\n await this.track(this.native?.remove(key));\n }\n\n /**\n * Wait for every write sent so far. Rejects with the first of them that failed since the last\n * `flush()`, whether it failed before this call or while waiting, so a screen that has to know a\n * value reached the disk - before signing out, say - can find out. Each failure is reported by\n * one flush only.\n */\n async flush(): Promise<void> {\n await Promise.allSettled([...this.writes]);\n const failed = this.unreported;\n this.unreported = null;\n if (failed) throw failed.error;\n }\n\n private readSync(key: string): unknown {\n const raw = this.native?.getSync?.(key);\n return raw == null ? ABSENT : decode(raw);\n }\n\n /**\n * Read the stored value in, unless the app has already set one.\n *\n * The race is real and silent: a screen that writes a preference during startup would otherwise\n * have it overwritten a tick later by whatever was there before.\n */\n private async hydrate<T>(key: string, set: (value: T) => void, initial: T): Promise<void> {\n this.reading.update((n) => n + 1);\n let stored: unknown = ABSENT;\n try {\n const raw = await this.native?.get(key);\n if (raw != null) stored = decode(raw);\n } catch (error) {\n this.fail(error);\n } finally {\n this.settle(key, set, stored === ABSENT ? initial : stored, stored !== ABSENT);\n this.reading.update((n) => n - 1);\n }\n }\n\n /** The read is back: show what was stored, with any updates that waited for it applied. */\n private settle<T>(key: string, set: (value: T) => void, base: unknown, found: boolean): void {\n const updates = this.waiting.get(key);\n this.waiting.delete(key);\n if (this.written.has(key)) return;\n if (!updates?.length) {\n if (found) set(base as T);\n return;\n }\n const value = updates.reduce((current, fn) => fn(current), base);\n this.written.add(key);\n set(value as T);\n this.write(key, value);\n }\n\n private write(key: string, value: unknown): void {\n const sent =\n value === undefined ? this.native?.remove(key) : this.native?.set(key, JSON.stringify(value));\n // Observed here, so a failure lands on `error` and in `flush()` rather than going unhandled.\n this.track(sent).catch(() => {});\n }\n\n /** A platform call, kept until it answers, with its failure reported on `error`. */\n private track(sent: Promise<void> | undefined): Promise<void> {\n if (!sent) return Promise.resolve();\n const tracked = sent.then(\n () => undefined,\n (error: unknown) => {\n this.fail(error);\n this.unreported ??= { error };\n throw error;\n },\n );\n this.writes.add(tracked);\n const forget = () => void this.writes.delete(tracked);\n tracked.then(forget, forget);\n return tracked;\n }\n\n private fail(error: unknown): void {\n this.failure.set(error instanceof Error ? error : new Error(String(error)));\n }\n}\n\n/** What `decode` answers for a string that is not JSON, since `null` is a value JSON can hold. */\nconst ABSENT: unique symbol = Symbol('absent');\n\n/**\n * A stored string as the value it encodes.\n *\n * A value that will not parse is treated as absent rather than thrown: it is a store written by\n * an older version of the app, and the right answer is the default the caller already supplied.\n * A stored `null` is not that: it parses, and a nullable signal gets it back.\n */\nfunction decode(raw: string): unknown {\n try {\n return JSON.parse(raw) as unknown;\n } catch {\n return ABSENT;\n }\n}\n\nconst plain = (): NativeStore | null => {\n const module = expoModule(\n '@react-native-async-storage/async-storage',\n () =>\n require('@react-native-async-storage/async-storage') as {\n default: typeof import('@react-native-async-storage/async-storage').default;\n },\n );\n const store = module?.default;\n if (!store) return null;\n return {\n get: (key) => store.getItem(key),\n set: (key, value) => store.setItem(key, value),\n remove: (key) => store.removeItem(key),\n };\n};\n\nconst secure = (): NativeStore | null => {\n const expo = expoModule(\n 'expo-secure-store',\n () => require('expo-secure-store') as typeof import('expo-secure-store'),\n );\n if (!expo) return null;\n return {\n get: (key) => expo.getItemAsync(key),\n set: (key, value) => expo.setItemAsync(key, value),\n remove: (key) => expo.deleteItemAsync(key),\n // The keychain can answer without waiting, so a token never flashes its default.\n getSync: (key) => expo.getItem(key),\n };\n};\n\n/** A plain key-value file. Bigger and faster than the keychain, and not private. */\nexport const Storage = new InjectionToken<Store>('angular-native.storage', {\n factory: () => new Store(plain()),\n});\nexport type Storage = Store;\n\n/** The keychain and the Android keystore. Small values, and worth the size limit. */\nexport const SecureStorage = new InjectionToken<Store>('angular-native.secureStorage', {\n factory: () => new Store(secure()),\n});\nexport type SecureStorage = Store;\n"]}
|
package/dist/symbol.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
export type SymbolType = 'monochrome' | 'hierarchical' | 'palette' | 'multicolor';
|
|
3
|
+
export type SymbolScale = 'default' | 'unspecified' | 'small' | 'medium' | 'large';
|
|
4
|
+
export type SymbolWeight = 'unspecified' | 'ultraLight' | 'thin' | 'light' | 'regular' | 'medium' | 'semibold' | 'bold' | 'heavy' | 'black';
|
|
5
|
+
export type SymbolResizeMode = 'scaleToFill' | 'scaleAspectFit' | 'scaleAspectFill' | 'redraw' | 'center' | 'top' | 'bottom' | 'left' | 'right' | 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight';
|
|
6
|
+
/** How a symbol animates, as `expo-symbols` describes it. */
|
|
7
|
+
export interface SymbolAnimationSpec {
|
|
8
|
+
readonly effect?: {
|
|
9
|
+
readonly type: 'bounce' | 'pulse' | 'scale';
|
|
10
|
+
readonly wholeSymbol?: boolean;
|
|
11
|
+
readonly direction?: 'up' | 'down';
|
|
12
|
+
};
|
|
13
|
+
readonly repeating?: boolean;
|
|
14
|
+
readonly repeatCount?: number;
|
|
15
|
+
readonly speed?: number;
|
|
16
|
+
readonly variableAnimationSpec?: Readonly<Record<string, boolean>>;
|
|
17
|
+
}
|
|
18
|
+
export declare class ExpoSymbol {
|
|
19
|
+
/** The symbol's name, as SF Symbols lists it: `heart.fill`, `cloud.sun.rain`. */
|
|
20
|
+
readonly name: import("@angular/core").InputSignal<string>;
|
|
21
|
+
readonly type: import("@angular/core").InputSignal<SymbolType>;
|
|
22
|
+
readonly scale: import("@angular/core").InputSignal<SymbolScale | undefined>;
|
|
23
|
+
readonly weight: import("@angular/core").InputSignal<SymbolWeight | undefined>;
|
|
24
|
+
/** The colour of a `monochrome` or `hierarchical` symbol. */
|
|
25
|
+
readonly tintColor: import("@angular/core").InputSignal<string | undefined>;
|
|
26
|
+
/** The layers' colours, for `palette`. */
|
|
27
|
+
readonly colors: import("@angular/core").InputSignal<string | readonly string[] | undefined>;
|
|
28
|
+
readonly resizeMode: import("@angular/core").InputSignal<SymbolResizeMode | undefined>;
|
|
29
|
+
readonly animationSpec: import("@angular/core").InputSignal<SymbolAnimationSpec | undefined>;
|
|
30
|
+
/** Points, both ways. */
|
|
31
|
+
readonly size: import("@angular/core").InputSignalWithTransform<number, unknown>;
|
|
32
|
+
protected readonly colourList: import("@angular/core").Signal<readonly string[] | undefined>;
|
|
33
|
+
protected readonly animated: import("@angular/core").Signal<boolean>;
|
|
34
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ExpoSymbol, never>;
|
|
35
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<ExpoSymbol, "expo-symbol", never, { "name": { "alias": "name"; "required": true; "isSignal": true; }; "type": { "alias": "type"; "required": false; "isSignal": true; }; "scale": { "alias": "scale"; "required": false; "isSignal": true; }; "weight": { "alias": "weight"; "required": false; "isSignal": true; }; "tintColor": { "alias": "tintColor"; "required": false; "isSignal": true; }; "colors": { "alias": "colors"; "required": false; "isSignal": true; }; "resizeMode": { "alias": "resizeMode"; "required": false; "isSignal": true; }; "animationSpec": { "alias": "animationSpec"; "required": false; "isSignal": true; }; "size": { "alias": "size"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
36
|
+
}
|
package/dist/symbol.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<expo-symbol>`: an SF Symbol, from `expo-symbols`, typed so a template is checked against the
|
|
3
|
+
* props. iOS only. Registered with `registerExpoViews('expo-symbol')`.
|
|
4
|
+
*
|
|
5
|
+
* It does what the module's React component does before native sees the props: the view is `size`
|
|
6
|
+
* points square (24 unless set), `type` is `monochrome` unless set, one colour or several become
|
|
7
|
+
* the list native takes, and an `animationSpec` is what turns animation on.
|
|
8
|
+
*
|
|
9
|
+
* ```html
|
|
10
|
+
* <expo-symbol name="heart.fill" [size]="28" tintColor="#ff2d55" weight="semibold" />
|
|
11
|
+
* <expo-symbol name="cloud.sun.fill" type="palette" [colors]="['#fff', '#ffcc00']" />
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
import { Component, computed, input } from '@angular/core';
|
|
15
|
+
import { optionalNumber } from "./transforms.js";
|
|
16
|
+
import * as i0 from "@angular/core";
|
|
17
|
+
export class ExpoSymbol {
|
|
18
|
+
/** The symbol's name, as SF Symbols lists it: `heart.fill`, `cloud.sun.rain`. */
|
|
19
|
+
name = input.required(/* @ts-ignore */
|
|
20
|
+
...(ngDevMode ? [{ debugName: "name" }] : /* istanbul ignore next */ []));
|
|
21
|
+
type = input('monochrome', /* @ts-ignore */
|
|
22
|
+
...(ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []));
|
|
23
|
+
scale = input(/* @ts-ignore */
|
|
24
|
+
...(ngDevMode ? [undefined, { debugName: "scale" }] : /* istanbul ignore next */ []));
|
|
25
|
+
weight = input(/* @ts-ignore */
|
|
26
|
+
...(ngDevMode ? [undefined, { debugName: "weight" }] : /* istanbul ignore next */ []));
|
|
27
|
+
/** The colour of a `monochrome` or `hierarchical` symbol. */
|
|
28
|
+
tintColor = input(/* @ts-ignore */
|
|
29
|
+
...(ngDevMode ? [undefined, { debugName: "tintColor" }] : /* istanbul ignore next */ []));
|
|
30
|
+
/** The layers' colours, for `palette`. */
|
|
31
|
+
colors = input(/* @ts-ignore */
|
|
32
|
+
...(ngDevMode ? [undefined, { debugName: "colors" }] : /* istanbul ignore next */ []));
|
|
33
|
+
resizeMode = input(/* @ts-ignore */
|
|
34
|
+
...(ngDevMode ? [undefined, { debugName: "resizeMode" }] : /* istanbul ignore next */ []));
|
|
35
|
+
animationSpec = input(/* @ts-ignore */
|
|
36
|
+
...(ngDevMode ? [undefined, { debugName: "animationSpec" }] : /* istanbul ignore next */ []));
|
|
37
|
+
/** Points, both ways. */
|
|
38
|
+
size = input(24, { ...(ngDevMode ? { debugName: "size" } : /* istanbul ignore next */ {}), transform: (value) => optionalNumber(value) ?? 24 });
|
|
39
|
+
colourList = computed(() => {
|
|
40
|
+
const colours = this.colors();
|
|
41
|
+
return colours === undefined ? undefined : typeof colours === 'string' ? [colours] : colours;
|
|
42
|
+
}, /* @ts-ignore */
|
|
43
|
+
...(ngDevMode ? [{ debugName: "colourList" }] : /* istanbul ignore next */ []));
|
|
44
|
+
animated = computed(() => this.animationSpec() !== undefined, /* @ts-ignore */
|
|
45
|
+
...(ngDevMode ? [{ debugName: "animated" }] : /* istanbul ignore next */ []));
|
|
46
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ExpoSymbol, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
47
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.2.0", type: ExpoSymbol, isStandalone: true, selector: "expo-symbol", inputs: { name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: true, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, scale: { classPropertyName: "scale", publicName: "scale", isSignal: true, isRequired: false, transformFunction: null }, weight: { classPropertyName: "weight", publicName: "weight", isSignal: true, isRequired: false, transformFunction: null }, tintColor: { classPropertyName: "tintColor", publicName: "tintColor", isSignal: true, isRequired: false, transformFunction: null }, colors: { classPropertyName: "colors", publicName: "colors", isSignal: true, isRequired: false, transformFunction: null }, resizeMode: { classPropertyName: "resizeMode", publicName: "resizeMode", isSignal: true, isRequired: false, transformFunction: null }, animationSpec: { classPropertyName: "animationSpec", publicName: "animationSpec", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "name": "name()", "type": "type()", "scale": "scale()", "weight": "weight()", "tintColor": "tintColor()", "colors": "colourList()", "resizeMode": "resizeMode()", "animationSpec": "animationSpec()", "animated": "animated()", "style.width": "size()", "style.height": "size()" } }, ngImport: i0, template: '', isInline: true });
|
|
48
|
+
}
|
|
49
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ExpoSymbol, decorators: [{
|
|
50
|
+
type: Component,
|
|
51
|
+
args: [{
|
|
52
|
+
selector: 'expo-symbol',
|
|
53
|
+
template: '',
|
|
54
|
+
host: {
|
|
55
|
+
'[name]': 'name()',
|
|
56
|
+
'[type]': 'type()',
|
|
57
|
+
'[scale]': 'scale()',
|
|
58
|
+
'[weight]': 'weight()',
|
|
59
|
+
'[tintColor]': 'tintColor()',
|
|
60
|
+
'[colors]': 'colourList()',
|
|
61
|
+
'[resizeMode]': 'resizeMode()',
|
|
62
|
+
'[animationSpec]': 'animationSpec()',
|
|
63
|
+
'[animated]': 'animated()',
|
|
64
|
+
'[style.width]': 'size()',
|
|
65
|
+
'[style.height]': 'size()',
|
|
66
|
+
},
|
|
67
|
+
}]
|
|
68
|
+
}], propDecorators: { name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: true }] }], type: [{ type: i0.Input, args: [{ isSignal: true, alias: "type", required: false }] }], scale: [{ type: i0.Input, args: [{ isSignal: true, alias: "scale", required: false }] }], weight: [{ type: i0.Input, args: [{ isSignal: true, alias: "weight", required: false }] }], tintColor: [{ type: i0.Input, args: [{ isSignal: true, alias: "tintColor", required: false }] }], colors: [{ type: i0.Input, args: [{ isSignal: true, alias: "colors", required: false }] }], resizeMode: [{ type: i0.Input, args: [{ isSignal: true, alias: "resizeMode", required: false }] }], animationSpec: [{ type: i0.Input, args: [{ isSignal: true, alias: "animationSpec", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }] } });
|
|
69
|
+
//# sourceMappingURL=symbol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"symbol.js","sourceRoot":"","sources":["../src/symbol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;;AA4DjD,MAAM,OAAO,UAAU;IACrB,iFAAiF;IACxE,IAAI,GAAG,KAAK,CAAC,QAAQ;6EAAU,CAAC;IAChC,IAAI,GAAG,KAAK,CAAa,YAAY;6EAAC,CAAC;IACvC,KAAK,GAAG,KAAK;yFAAe,CAAC;IAC7B,MAAM,GAAG,KAAK;0FAAgB,CAAC;IACxC,6DAA6D;IACpD,SAAS,GAAG,KAAK;6FAAU,CAAC;IACrC,0CAA0C;IACjC,MAAM,GAAG,KAAK;0FAA8B,CAAC;IAC7C,UAAU,GAAG,KAAK;8FAAoB,CAAC;IACvC,aAAa,GAAG,KAAK;iGAAuB,CAAC;IACtD,yBAAyB;IAChB,IAAI,GAAG,KAAK,CAAC,EAAE,4EAAI,SAAS,EAAE,CAAC,KAAc,EAAE,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC;IAEvE,UAAU,GAAG,QAAQ,CAAC,GAAG,EAAE;QAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC9B,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC/F,CAAC;mFAAC,CAAC;IACgB,QAAQ,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,aAAa,EAAE,KAAK,SAAS;iFAAC,CAAC;uGAnBtE,UAAU;2FAAV,UAAU,u+CAfX,EAAE;;2FAeD,UAAU;kBAjBtB,SAAS;mBAAC;oBACT,QAAQ,EAAE,aAAa;oBACvB,QAAQ,EAAE,EAAE;oBACZ,IAAI,EAAE;wBACJ,QAAQ,EAAE,QAAQ;wBAClB,QAAQ,EAAE,QAAQ;wBAClB,SAAS,EAAE,SAAS;wBACpB,UAAU,EAAE,UAAU;wBACtB,aAAa,EAAE,aAAa;wBAC5B,UAAU,EAAE,cAAc;wBAC1B,cAAc,EAAE,cAAc;wBAC9B,iBAAiB,EAAE,iBAAiB;wBACpC,YAAY,EAAE,YAAY;wBAC1B,eAAe,EAAE,QAAQ;wBACzB,gBAAgB,EAAE,QAAQ;qBAC3B;iBACF","sourcesContent":["/**\n * `<expo-symbol>`: an SF Symbol, from `expo-symbols`, typed so a template is checked against the\n * props. iOS only. Registered with `registerExpoViews('expo-symbol')`.\n *\n * It does what the module's React component does before native sees the props: the view is `size`\n * points square (24 unless set), `type` is `monochrome` unless set, one colour or several become\n * the list native takes, and an `animationSpec` is what turns animation on.\n *\n * ```html\n * <expo-symbol name=\"heart.fill\" [size]=\"28\" tintColor=\"#ff2d55\" weight=\"semibold\" />\n * <expo-symbol name=\"cloud.sun.fill\" type=\"palette\" [colors]=\"['#fff', '#ffcc00']\" />\n * ```\n */\nimport { Component, computed, input } from '@angular/core';\nimport { optionalNumber } from './transforms.ts';\n\nexport type SymbolType = 'monochrome' | 'hierarchical' | 'palette' | 'multicolor';\nexport type SymbolScale = 'default' | 'unspecified' | 'small' | 'medium' | 'large';\nexport type SymbolWeight =\n | 'unspecified'\n | 'ultraLight'\n | 'thin'\n | 'light'\n | 'regular'\n | 'medium'\n | 'semibold'\n | 'bold'\n | 'heavy'\n | 'black';\nexport type SymbolResizeMode =\n | 'scaleToFill'\n | 'scaleAspectFit'\n | 'scaleAspectFill'\n | 'redraw'\n | 'center'\n | 'top'\n | 'bottom'\n | 'left'\n | 'right'\n | 'topLeft'\n | 'topRight'\n | 'bottomLeft'\n | 'bottomRight';\n\n/** How a symbol animates, as `expo-symbols` describes it. */\nexport interface SymbolAnimationSpec {\n readonly effect?: {\n readonly type: 'bounce' | 'pulse' | 'scale';\n readonly wholeSymbol?: boolean;\n readonly direction?: 'up' | 'down';\n };\n readonly repeating?: boolean;\n readonly repeatCount?: number;\n readonly speed?: number;\n readonly variableAnimationSpec?: Readonly<Record<string, boolean>>;\n}\n\n@Component({\n selector: 'expo-symbol',\n template: '',\n host: {\n '[name]': 'name()',\n '[type]': 'type()',\n '[scale]': 'scale()',\n '[weight]': 'weight()',\n '[tintColor]': 'tintColor()',\n '[colors]': 'colourList()',\n '[resizeMode]': 'resizeMode()',\n '[animationSpec]': 'animationSpec()',\n '[animated]': 'animated()',\n '[style.width]': 'size()',\n '[style.height]': 'size()',\n },\n})\nexport class ExpoSymbol {\n /** The symbol's name, as SF Symbols lists it: `heart.fill`, `cloud.sun.rain`. */\n readonly name = input.required<string>();\n readonly type = input<SymbolType>('monochrome');\n readonly scale = input<SymbolScale>();\n readonly weight = input<SymbolWeight>();\n /** The colour of a `monochrome` or `hierarchical` symbol. */\n readonly tintColor = input<string>();\n /** The layers' colours, for `palette`. */\n readonly colors = input<string | readonly string[]>();\n readonly resizeMode = input<SymbolResizeMode>();\n readonly animationSpec = input<SymbolAnimationSpec>();\n /** Points, both ways. */\n readonly size = input(24, { transform: (value: unknown) => optionalNumber(value) ?? 24 });\n\n protected readonly colourList = computed(() => {\n const colours = this.colors();\n return colours === undefined ? undefined : typeof colours === 'string' ? [colours] : colours;\n });\n protected readonly animated = computed(() => this.animationSpec() !== undefined);\n}\n"]}
|