-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnativescript-sqlite.component.ts
More file actions
47 lines (40 loc) · 1.2 KB
/
Copy pathnativescript-sqlite.component.ts
File metadata and controls
47 lines (40 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
42
43
44
45
46
47
import { Component, ElementRef, NgZone, ViewChild, OnInit, OnDestroy } from '@angular/core';
import { DemoSharedNativescriptSqlite } from '@demo/shared';
import {} from '@edusperoni/nativescript-sqlite';
import { StackLayout } from '@nativescript/core';
@Component({
selector: 'demo-nativescript-sqlite',
standalone: false,
templateUrl: 'nativescript-sqlite.component.html',
})
export class NativescriptSqliteComponent implements OnInit, OnDestroy {
demoShared: DemoSharedNativescriptSqlite;
@ViewChild('spinner', { static: false }) spinnerRef: ElementRef;
private _spinning = true;
constructor(private _ngZone: NgZone) {}
ngOnInit() {
this.demoShared = new DemoSharedNativescriptSqlite();
}
ngAfterViewInit() {
this._spin();
}
ngOnDestroy() {
this._spinning = false;
}
private _spin() {
if (!this._spinning) return;
const view: StackLayout = this.spinnerRef?.nativeElement;
if (!view) return;
let last: number | null = null;
const step = (ts: number) => {
if (!this._spinning) return;
if (last !== null) {
const delta = ts - last;
view.rotate = (view.rotate + (delta / 800) * 360) % 360;
}
last = ts;
requestAnimationFrame(step);
};
requestAnimationFrame(step);
}
}