forked from halfnelson/svelte-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
41 lines (33 loc) · 1.2 KB
/
Copy pathindex.ts
File metadata and controls
41 lines (33 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { run, on, launchEvent } from 'tns-core-modules/application'
import { navigate, ViewNode, createElement, initializeDom, FrameElement } from './dom';
declare global {
export class SvelteComponent {
$destroy(): void;
constructor(options: { target?: ViewNode, props?: any, anchor?: ViewNode, intro?: boolean });
$set(props: any): void;
}
}
export function svelteNative(startPage: typeof SvelteComponent, data: any): Promise<SvelteComponent> {
initializeDom();
//setup a frame so we always have somewhere to hang our css
let rootFrame = createElement('frame') as FrameElement;
rootFrame.setAttribute("id", "app-root-frame");
let pageInstance = navigate({
page: startPage,
props: data || {},
frame: rootFrame
})
return new Promise((resolve, reject) => {
//wait for launch
on(launchEvent, () => {
console.log("Application Launched");
resolve(pageInstance);
})
try {
run({ create: () => rootFrame.nativeView });
} catch (e) {
reject(e);
}
});
}
export { navigate, goBack, showModal, closeModal, initializeDom, DomTraceCategory } from "./dom"