1
1
import * as ImageSource from 'tns-core-modules/image-source' ;
2
2
import { FloatingActionButtonBase , iconProperty } from './fab-common' ;
3
3
4
- declare var MNFloatingActionButton : any ;
5
-
6
4
export class Fab extends FloatingActionButtonBase {
7
5
public nativeView : UIView ;
8
6
9
7
constructor ( ) {
10
8
super ( ) ;
11
- const btn = MNFloatingActionButton . alloc ( ) . init ( ) ;
9
+ const btn = MNFloatingActionButton . alloc ( ) . init ( ) as MNFloatingActionButton ;
12
10
btn . animationScale = 0.95 ;
13
11
this . nativeView = btn ;
14
12
}
@@ -21,24 +19,28 @@ export class Fab extends FloatingActionButtonBase {
21
19
22
20
// Set the new one
23
21
if ( iconDrawable !== null ) {
24
- newImageView = UIImageView . alloc ( ) . initWithImage ( iconDrawable . ios ) ;
22
+ newImageView = UIImageView . alloc ( ) . initWithImage (
23
+ iconDrawable . ios
24
+ ) as UIImageView ;
25
25
}
26
26
} else {
27
27
// Default image
28
28
const defaultImage = ImageSource . fromBase64 (
29
29
'iVBORw0KGgoAAAANSUhEUgAAAJAAAACQAQAAAADPPd8VAAAAAnRSTlMAAHaTzTgAAAAqSURBVHgBY6AMjIJRYP9n0AuNCo0KMf+HgwPDTmgoRMeo0KgQRWAUjAIABsnZRR7bYyUAAAAASUVORK5CYII='
30
- ) ;
30
+ ) as ImageSource . ImageSource ;
31
31
32
- newImageView = UIImageView . alloc ( ) . initWithImage ( defaultImage . ios ) ;
32
+ newImageView = UIImageView . alloc ( ) . initWithImage (
33
+ defaultImage . ios
34
+ ) as UIImageView ;
33
35
}
34
36
35
37
if ( newImageView !== null ) {
36
38
// Kill the old Image, cocoapod doesn't support changing it yet
37
- const button = this . nativeView . subviews [ 0 ] ;
38
- const oldBadImageView = button . subviews [ 0 ] ;
39
+ const button = this . nativeView . subviews [ 0 ] as MNFloatingActionButton ;
40
+ const oldBadImageView = button . subviews [ 0 ] ; // this should be the image view inside the MNFloatingActionButton
39
41
oldBadImageView . removeFromSuperview ( ) ;
40
42
41
- // Add the new guy
43
+ // Add the new image to the button
42
44
button . addSubview ( newImageView ) ;
43
45
}
44
46
}
@@ -50,16 +52,16 @@ export class Fab extends FloatingActionButtonBase {
50
52
bottom : number
51
53
) : void {
52
54
super . onLayout ( left , top , right , bottom ) ;
53
- this . centerIcon ( ) ;
55
+ this . _centerIcon ( ) ;
54
56
}
55
57
56
- centerIcon ( ) {
57
- const frame = this . nativeView . frame ;
58
- const width = frame . size . width ;
59
- const height = frame . size . height ;
58
+ private _centerIcon ( ) {
59
+ const frame = this . nativeView . frame as CGRect ;
60
+ const width = frame . size . width as number ;
61
+ const height = frame . size . height as number ;
60
62
61
- const button = this . nativeView . subviews [ 0 ] ;
62
- const imageView = < UIImageView > button . subviews [ 0 ] ;
63
+ const button = this . nativeView . subviews [ 0 ] as MNFloatingActionButton ;
64
+ const imageView = < UIImageView > button . subviews [ 0 ] ; // should be the image view inside the MNFloatingActionButton
63
65
64
66
imageView . contentMode = UIViewContentMode . ScaleAspectFit ;
65
67
imageView . frame = CGRectMake ( 0 , 0 , width / 2 , height / 2 ) ;
0 commit comments