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
52 lines (42 loc) · 1.6 KB
/
Copy pathindex.ts
File metadata and controls
52 lines (42 loc) · 1.6 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
42
43
44
45
46
47
48
49
50
51
52
import { registerSvelteElements } from './SvelteElements'
import { registerNativeElements } from './NativescriptElements'
import SvelteNativeDocument from './SvelteNativeDocument'
import NativeElementNode from './NativeElementNode'
export { default as FrameElement } from "./FrameElement"
export { default as SvelteNativeDocument } from './SvelteNativeDocument'
export { default as NativeElementNode } from './NativeElementNode'
export { registerCustomElementNode, createElement, ViewNode } from './basicdom'
export { navigate, goBack, showModal, NavigationOptions, BackNavigationOptions } from './navigation'
function installGlobalShims(): SvelteNativeDocument {
//expose our fake dom as global document for svelte components
let window = global as any;
window.window = global;
window.document = new SvelteNativeDocument();
window.requestAnimationFrame = (action: () => {}) => {
setTimeout(action, 33); //about 30 fps
}
window.getComputedStyle = (node: NativeElementNode) => {
return node.nativeView.style;
}
window.performance = {
now() {
return Date.now();
}
};
window.CustomEvent = class {
detail: any;
eventName: string;
type: string;
constructor(name: string, detail: any = null) {
this.eventName = name; //event name for nativescript
this.type = name; // type for svelte
this.detail = detail;
}
}
return window.document;
}
export function initializeDom() {
registerSvelteElements();
registerNativeElements();
return installGlobalShims();
}