-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathfab.ios.ts
More file actions
71 lines (60 loc) · 2.43 KB
/
fab.ios.ts
File metadata and controls
71 lines (60 loc) · 2.43 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
59
60
61
62
63
64
65
66
67
68
69
70
71
import { ImageSource, Utils } from '@nativescript/core';
import {
FloatingActionButtonBase,
iconProperty,
textProperty
} from './fab-common';
export class Fab extends FloatingActionButtonBase {
nativeView: UIView;
constructor() {
super();
const btn = MNFloatingActionButton.alloc().init() as MNFloatingActionButton;
btn.animationScale = 0.95;
this.nativeView = btn;
}
private setImage(iconDrawable: ImageSource) {
if (iconDrawable) {
const newImageView = UIImageView.alloc().initWithImage(
iconDrawable.ios
) as UIImageView;
if (newImageView !== null) {
// Kill the old Image, cocoapod doesn't support changing it yet
const button = this.nativeView.subviews.objectAtIndex(0) as MNFloatingActionButton;
const oldBadImageView = button.subviews.objectAtIndex(0); // this should be the image view inside the MNFloatingActionButton
oldBadImageView.removeFromSuperview();
// Add the new image to the button
button.addSubview(newImageView);
}
}
}
[iconProperty.setNative](value: any) {
let iconDrawable = null;
if (Utils.isFileOrResourcePath(value)) {
iconDrawable = ImageSource.fromFileOrResourceSync(value);
} else {
// Default image
iconDrawable = ImageSource.fromBase64Sync(
'iVBORw0KGgoAAAANSUhEUgAAAJAAAACQAQAAAADPPd8VAAAAAnRSTlMAAHaTzTgAAAAqSURBVHgBY6AMjIJRYP9n0AuNCo0KMf+HgwPDTmgoRMeo0KgQRWAUjAIABsnZRR7bYyUAAAAASUVORK5CYII='
) as ImageSource;
}
this.setImage(iconDrawable);
}
[textProperty.setNative](value: string) {
const image = this.getImageFromText(value);
this.setImage(image);
}
onLayout(left: number, top: number, right: number, bottom: number): void {
super.onLayout(left, top, right, bottom);
this._centerIcon();
}
private _centerIcon() {
const frame = this.nativeView.frame as CGRect;
const width = frame.size.width as number;
const height = frame.size.height as number;
const button = this.nativeView.subviews.objectAtIndex(0) as MNFloatingActionButton;
const imageView = <UIImageView>button.subviews.objectAtIndex(0); // should be the image view inside the MNFloatingActionButton
imageView.contentMode = UIViewContentMode.ScaleAspectFit;
imageView.frame = CGRectMake(0, 0, width / 2, height / 2);
imageView.center = CGPointMake(width / 2, height / 2);
}
}