-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.tsx
More file actions
58 lines (51 loc) · 1.83 KB
/
index.tsx
File metadata and controls
58 lines (51 loc) · 1.83 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
53
54
55
56
57
58
import 'zone.js';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
import { BrowserModule } from '@angular/platform-browser'
import { IonicModule, Platform } from '@ionic/angular'
import { NgModule } from '@angular/core'
import { Component } from '@angular/core'
import { File } from '@awesome-cordova-plugins/file'
import { Camera, DestinationType, MediaType, PictureSourceType } from '@awesome-cordova-plugins/camera/ngx'
import { main } from './src/main'
export async function loadAsset(path: string): Promise<string> {
var dir = await File.resolveDirectoryUrl(File.applicationDirectory + "www/assets")
var fileEntry = await File.getFile(dir, path, null)
var result = await new Promise<string>((resolve, _) => {
fileEntry.file(file => {
var reader = new FileReader()
reader.onloadend = (_) => resolve(reader.result as string)
reader.readAsDataURL(file)
})
})
return result
}
export async function pickImage(): Promise<string | null> {
return await cameraInstance.getPicture({
destinationType: DestinationType.DATA_URL,
mediaType: MediaType.PICTURE,
sourceType: PictureSourceType.PHOTOLIBRARY
})
}
var cameraInstance: Camera
@Component({
selector: 'app-root',
templateUrl: 'src/main.html',
styleUrl: 'src/main.css'
})
class Main {
constructor(platform: Platform, camera: Camera) {
(async () => {
cameraInstance = camera
await platform.ready()
await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)))
main()
})()
}
}
@NgModule({
bootstrap: [Main],
providers: [Platform, Camera],
imports: [BrowserModule, IonicModule.forRoot()]
})
class MainModule { }
platformBrowserDynamic().bootstrapModule(MainModule)