-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkeyframes.android.ts
52 lines (40 loc) · 1.42 KB
/
keyframes.android.ts
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 { ad } from "utils/utils";
import { Image } from "ui/image";
import * as fs from "file-system";
declare var android, com, java: any;
let appPath = fs.knownFolders.currentApp().path;
export class KeyframesView extends Image {
private _source: string;
private _androidViewId: number;
private _android; // : android.widget.ImageView;
get android(): any {
return this._android;
}
get _nativeView(): any {
return this._android;
}
set source(value: string) {
this._source = value;
}
public _createUI() {
this._android = new android.widget.ImageView(this._context);
if (!this._androidViewId) {
this._androidViewId = android.view.View.generateViewId();
}
this._android.setId(this._androidViewId);
let src = appPath + (this._source.indexOf("/") === 0 ? "" : "/") + this._source;
if (!fs.File.exists(src)) {
console.log("Keyframe source not found at " + src + "; showing an empty image");
return;
}
let fis = new java.io.FileInputStream(src);
let kfImage = com.facebook.keyframes.deserializers.KFImageDeserializer.deserialize(fis);
let kfDrawable = new com.facebook.keyframes.KeyframesDrawableBuilder()
.withImage(kfImage)
// .withMaxFrameRate(60) // default 60
.build();
kfDrawable.startAnimation();
this._android.setLayerType(android.view.View.LAYER_TYPE_SOFTWARE, null);
this._android.setImageDrawable(kfDrawable);
}
}