Skip to content

Commit 080d954

Browse files
committed
use typings
1 parent c62985c commit 080d954

File tree

2 files changed

+53
-16
lines changed

2 files changed

+53
-16
lines changed

src/fab.ios.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import * as ImageSource from 'tns-core-modules/image-source';
22
import { FloatingActionButtonBase, iconProperty } from './fab-common';
33

4-
declare var MNFloatingActionButton: any;
5-
64
export 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);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
declare class MNFloatingActionButton extends UIControl {
3+
4+
static alloc(): MNFloatingActionButton; // inherited from NSObject
5+
6+
static appearance(): MNFloatingActionButton; // inherited from UIAppearance
7+
8+
static appearanceForTraitCollection(trait: UITraitCollection): MNFloatingActionButton; // inherited from UIAppearance
9+
10+
static appearanceForTraitCollectionWhenContainedIn(trait: UITraitCollection, ContainerClass: typeof NSObject): MNFloatingActionButton; // inherited from UIAppearance
11+
12+
static appearanceForTraitCollectionWhenContainedInInstancesOfClasses(trait: UITraitCollection, containerTypes: NSArray<typeof NSObject> | typeof NSObject[]): MNFloatingActionButton; // inherited from UIAppearance
13+
14+
static appearanceWhenContainedIn(ContainerClass: typeof NSObject): MNFloatingActionButton; // inherited from UIAppearance
15+
16+
static appearanceWhenContainedInInstancesOfClasses(containerTypes: NSArray<typeof NSObject> | typeof NSObject[]): MNFloatingActionButton; // inherited from UIAppearance
17+
18+
static new(): MNFloatingActionButton; // inherited from NSObject
19+
20+
animationDuration: number;
21+
22+
animationScale: number;
23+
24+
centerImage: UIImage;
25+
26+
shadowColor: UIColor;
27+
28+
shadowOpacity: number;
29+
30+
shadowRadius: number;
31+
}
32+
33+
declare var MNFloatingActionButtonVersionNumber: number;
34+
35+
declare var MNFloatingActionButtonVersionString: interop.Reference<number>;

0 commit comments

Comments
 (0)