11import * as ImageSource from 'tns-core-modules/image-source' ;
22import { FloatingActionButtonBase , iconProperty } from './fab-common' ;
33
4- declare var MNFloatingActionButton : any ;
5-
64export class Fab extends FloatingActionButtonBase {
75 public nativeView : UIView ;
86
97 constructor ( ) {
108 super ( ) ;
11- const btn = MNFloatingActionButton . alloc ( ) . init ( ) ;
9+ const btn = MNFloatingActionButton . alloc ( ) . init ( ) as MNFloatingActionButton ;
1210 btn . animationScale = 0.95 ;
1311 this . nativeView = btn ;
1412 }
@@ -21,24 +19,28 @@ export class Fab extends FloatingActionButtonBase {
2119
2220 // Set the new one
2321 if ( iconDrawable !== null ) {
24- newImageView = UIImageView . alloc ( ) . initWithImage ( iconDrawable . ios ) ;
22+ newImageView = UIImageView . alloc ( ) . initWithImage (
23+ iconDrawable . ios
24+ ) as UIImageView ;
2525 }
2626 } else {
2727 // Default image
2828 const defaultImage = ImageSource . fromBase64 (
2929 'iVBORw0KGgoAAAANSUhEUgAAAJAAAACQAQAAAADPPd8VAAAAAnRSTlMAAHaTzTgAAAAqSURBVHgBY6AMjIJRYP9n0AuNCo0KMf+HgwPDTmgoRMeo0KgQRWAUjAIABsnZRR7bYyUAAAAASUVORK5CYII='
30- ) ;
30+ ) as ImageSource . ImageSource ;
3131
32- newImageView = UIImageView . alloc ( ) . initWithImage ( defaultImage . ios ) ;
32+ newImageView = UIImageView . alloc ( ) . initWithImage (
33+ defaultImage . ios
34+ ) as UIImageView ;
3335 }
3436
3537 if ( newImageView !== null ) {
3638 // 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
3941 oldBadImageView . removeFromSuperview ( ) ;
4042
41- // Add the new guy
43+ // Add the new image to the button
4244 button . addSubview ( newImageView ) ;
4345 }
4446 }
@@ -50,16 +52,16 @@ export class Fab extends FloatingActionButtonBase {
5052 bottom : number
5153 ) : void {
5254 super . onLayout ( left , top , right , bottom ) ;
53- this . centerIcon ( ) ;
55+ this . _centerIcon ( ) ;
5456 }
5557
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 ;
6062
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
6365
6466 imageView . contentMode = UIViewContentMode . ScaleAspectFit ;
6567 imageView . frame = CGRectMake ( 0 , 0 , width / 2 , height / 2 ) ;
0 commit comments