@livx.cc/native-kit 0.45.14 → 0.45.16
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/package.json +1 -1
- package/src/core/NativeKit.ts +4 -1
- package/src/index.ts +1 -0
- package/src/modules/webview.ts +66 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livx.cc/native-kit",
|
|
3
|
-
"version": "0.45.
|
|
3
|
+
"version": "0.45.16",
|
|
4
4
|
"description": "Isomorphic native-capabilities kit for PWAs — same API in browser and in an appwrap native shell. Zero dependencies.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Elya Livshitz",
|
package/src/core/NativeKit.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { ShareTargetModule } from '../modules/shareTarget';
|
|
|
9
9
|
import { BackgroundTaskModule } from '../modules/backgroundTask';
|
|
10
10
|
import { BiometricsModule } from '../modules/biometrics';
|
|
11
11
|
import { BrowserModule } from '../modules/browser';
|
|
12
|
+
import { WebViewModule } from '../modules/webview';
|
|
12
13
|
import { CalendarModule } from '../modules/calendar';
|
|
13
14
|
import { ClipboardModule } from '../modules/clipboard';
|
|
14
15
|
import { ContactsModule } from '../modules/contacts';
|
|
@@ -103,6 +104,7 @@ export class NativeKit {
|
|
|
103
104
|
public readonly calendar = new CalendarModule(this);
|
|
104
105
|
public readonly app = new AppModule(this);
|
|
105
106
|
public readonly browser = new BrowserModule(this);
|
|
107
|
+
public readonly webview = new WebViewModule(this);
|
|
106
108
|
public readonly oauth = new OAuthModule(this);
|
|
107
109
|
public readonly updates = new UpdatesModule(this);
|
|
108
110
|
public readonly backgroundTask = new BackgroundTaskModule(this);
|
|
@@ -151,7 +153,7 @@ export class NativeKit {
|
|
|
151
153
|
biometrics: this.biometrics, geo: this.geo, heading: this.heading, photos: this.photos,
|
|
152
154
|
network: this.network, lifecycle: this.lifecycle, reviews: this.reviews, motion: this.motion,
|
|
153
155
|
media: this.media, contacts: this.contacts, scanner: this.scanner,
|
|
154
|
-
speech: this.speech, calendar: this.calendar, app: this.app, browser: this.browser,
|
|
156
|
+
speech: this.speech, calendar: this.calendar, app: this.app, browser: this.browser, webview: this.webview,
|
|
155
157
|
oauth: this.oauth, updates: this.updates,
|
|
156
158
|
backgroundTask: this.backgroundTask, tracking: this.tracking, appleSignIn: this.appleSignIn,
|
|
157
159
|
shareTarget: this.shareTarget,
|
|
@@ -376,6 +378,7 @@ declare module './module-registry' {
|
|
|
376
378
|
calendar: CalendarModule;
|
|
377
379
|
app: AppModule;
|
|
378
380
|
browser: BrowserModule;
|
|
381
|
+
webview: WebViewModule;
|
|
379
382
|
oauth: OAuthModule;
|
|
380
383
|
updates: UpdatesModule;
|
|
381
384
|
backgroundTask: BackgroundTaskModule;
|
package/src/index.ts
CHANGED
|
@@ -43,6 +43,7 @@ export { isScanResult } from './modules/scanner';
|
|
|
43
43
|
export type { SpeechVoice, SpeakOptions, ListenOptions, SpeechPartial } from './modules/speech';
|
|
44
44
|
export type { CalendarEventOptions } from './modules/calendar';
|
|
45
45
|
export type { BrowserOptions } from './modules/browser';
|
|
46
|
+
export type { WebViewState, WebViewOpenOptions, WebViewNavOp } from './modules/webview';
|
|
46
47
|
export type { OAuthAuthorizeParams, OAuthResult } from './modules/oauth';
|
|
47
48
|
export type { TrackingStatus } from './modules/tracking';
|
|
48
49
|
export type {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { NativeKit } from '../core/NativeKit';
|
|
2
|
+
import type { Unsubscribe } from '../core/types';
|
|
3
|
+
|
|
4
|
+
/** Navigation state of the overlay, pushed on every change (`webview.state`). */
|
|
5
|
+
export interface WebViewState {
|
|
6
|
+
url: string;
|
|
7
|
+
title: string;
|
|
8
|
+
canGoBack: boolean;
|
|
9
|
+
canGoForward: boolean;
|
|
10
|
+
loading: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface WebViewOpenOptions {
|
|
14
|
+
/** Offset from the top of the app's WebView (CSS px) — keep your own top bar visible above it. Default 0. */
|
|
15
|
+
top?: number;
|
|
16
|
+
/** Inset from the bottom of the app's WebView (CSS px) — keep a bottom dock tappable below it. Default 0. */
|
|
17
|
+
bottom?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type WebViewNavOp = 'back' | 'forward' | 'reload' | 'go';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* In-app WebView OVERLAY — a chrome-less native WebView layered over the app between `top` and `bottom` px, driven by
|
|
24
|
+
* the page (vs {@link BrowserModule}: modal SFSafariViewController with its own chrome + cookie jar).
|
|
25
|
+
* Shares the persistent cookie store, swipe back/forward, target=_blank stays in the same view.
|
|
26
|
+
* `capability` is 'native' on an iOS or Android shell with the `webview` module, else 'none'.
|
|
27
|
+
*/
|
|
28
|
+
export class WebViewModule {
|
|
29
|
+
constructor(private kit: NativeKit) {}
|
|
30
|
+
|
|
31
|
+
get capability() {
|
|
32
|
+
return this.kit.capability('webview');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Show the overlay at `url` (navigates it if already open; re-applies top/bottom insets). */
|
|
36
|
+
open(url: string, opts: WebViewOpenOptions = {}): Promise<WebViewState> {
|
|
37
|
+
return this.kit.invoke('webview.open', { url, ...opts });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
nav(op: WebViewNavOp, url?: string): Promise<WebViewState> {
|
|
41
|
+
return this.kit.invoke('webview.nav', { op, url });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Hide without losing state (reveals the page beneath). */
|
|
45
|
+
hide(): Promise<{ open: boolean }> {
|
|
46
|
+
return this.kit.invoke('webview.hide', {});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Reveal again; pass top/bottom to re-inset (e.g. the page's dock height changed) without reloading. */
|
|
50
|
+
show(opts: WebViewOpenOptions = {}): Promise<{ open: boolean }> {
|
|
51
|
+
return this.kit.invoke('webview.show', { ...opts });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Tear the overlay down (fires {@link onClosed}). */
|
|
55
|
+
close(): Promise<void> {
|
|
56
|
+
return this.kit.invoke('webview.close', {});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
onState(cb: (s: WebViewState) => void): Unsubscribe {
|
|
60
|
+
return this.kit.on('webview.state', (p) => cb(p as WebViewState));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
onClosed(cb: () => void): Unsubscribe {
|
|
64
|
+
return this.kit.on('webview.closed', () => cb());
|
|
65
|
+
}
|
|
66
|
+
}
|