55 * https://twitter.com/BradWayneMartin
66 * https://github.com/bradmartin
77 * Pull requests are welcome. Enjoy!
8- * Cocoapod via: https ://cocoapods.org/pods/KCFloatingActionButton by Lee Sun-hyoup
8+ * Cocoapod via: http ://cocoapods.org/pods/MNFloatingActionButton by Matt Nydam
99 *************************************************************************************/
1010
1111var common = require ( "./fab-common" ) ;
@@ -27,7 +27,10 @@ var FloatingActionButton = (function (_super) {
2727 var _this = this ;
2828 _super . call ( this ) ;
2929
30- var button = KCFloatingActionButton . alloc ( ) . init ( ) ;
30+ var button = MNFloatingActionButton . alloc ( ) . init ( ) ;
31+
32+ button . animationScale = 0.95 ;
33+
3134 this . _ios = button ;
3235
3336 }
@@ -48,50 +51,39 @@ exports.Fab = FloatingActionButton;
4851var FloatingActionButtonStyler = ( function ( ) {
4952 function FloatingActionButtonStyler ( ) {
5053 }
51- // COLOR
52- FloatingActionButtonStyler . setColorProperty = function ( view , newValue ) {
53- var fab = view . ios ;
54- fab . plusColor = newValue ;
55- } ;
56- FloatingActionButtonStyler . resetColorProperty = function ( view , nativeValue ) {
57- var fab = view . ios ;
58- fab . plusColor = nativeValue ;
59- } ;
60- FloatingActionButtonStyler . getNativeColorValue = function ( view ) {
61- var fab = view . ios ;
62- return fab . plusColor ;
63- } ;
6454
6555 // BACKGROUND COLOR
6656 FloatingActionButtonStyler . setBackgroundColorProperty = function ( view , newValue ) {
6757 var fab = view . ios ;
68- fab . buttonColor = newValue ;
58+ fab . backgroundColor = newValue ;
6959 } ;
7060 FloatingActionButtonStyler . resetBackgroundColorProperty = function ( view , nativeValue ) {
7161 var fab = view . ios ;
72- fab . buttonColor = nativeValue ;
62+ fab . backgroundColor = nativeValue ;
7363 } ;
7464 FloatingActionButtonStyler . getNativeBackgroundColorValue = function ( view ) {
7565 var fab = view . ios ;
76- return fab . buttonColor ;
66+ return fab . backgroundColor ;
7767 } ;
7868
7969 // WIDTH\HEIGHT
8070 FloatingActionButtonStyler . setSizeProperty = function ( view , newValue ) {
8171 var fab = view . ios ;
82- fab . size = newValue ;
72+ fab . bounds . size . width = newValue ;
73+ fab . bounds . size . height = newValue ;
74+
75+ centerIcon ( view , newValue ) ; //move image back to center
8376 } ;
8477 FloatingActionButtonStyler . resetSizeProperty = function ( view , nativeValue ) {
8578 var fab = view . ios ;
86- fab . size = nativeValue ;
79+ fab . bounds . size . width = nativeValue ;
8780 } ;
8881 FloatingActionButtonStyler . getNativeSizeValue = function ( view ) {
8982 var fab = view . ios ;
90- return fab . size ;
83+ return fab . bounds . size . width ;
9184 } ;
9285
9386 FloatingActionButtonStyler . registerHandlers = function ( ) {
94- style . registerHandler ( style . colorProperty , new style . StylePropertyChangedHandler ( FloatingActionButtonStyler . setColorProperty , FloatingActionButtonStyler . resetColorProperty , FloatingActionButtonStyler . getNativeColorValue ) , "FloatingActionButton" ) ;
9587 style . registerHandler ( style . backgroundColorProperty , new style . StylePropertyChangedHandler ( FloatingActionButtonStyler . setBackgroundColorProperty , FloatingActionButtonStyler . resetBackgroundColorProperty , FloatingActionButtonStyler . getNativeBackgroundColorValue ) , "FloatingActionButton" ) ;
9688 style . registerHandler ( style . backgroundInternalProperty , style . ignorePropertyHandler , "FloatingActionButton" ) ;
9789 style . registerHandler ( style . widthProperty , new style . StylePropertyChangedHandler ( FloatingActionButtonStyler . setSizeProperty , FloatingActionButtonStyler . resetSizeProperty , FloatingActionButtonStyler . getNativeSizeValue ) , "FloatingActionButton" ) ;
@@ -108,16 +100,47 @@ FloatingActionButtonStyler.registerHandlers();
108100function onBackColorPropertyChanged ( data ) {
109101 if ( color . Color . isValid ( data . newValue ) ) {
110102 var fab = data . object ;
111- fab . ios . buttonColor = new color . Color ( data . newValue ) . ios ;
103+ fab . ios . backgroundColor = new color . Color ( data . newValue ) . ios ;
112104 }
113105}
114106common . Fab . backColorProperty . metadata . onSetNativeValue = onBackColorPropertyChanged ;
115107
116108//Icon
117109function onIconPropertyChanged ( data ) {
118- if ( ImageSource . isFileOrResourcePath ( data . newValue ) ) {
119- //Cocoapod doesn't support this yet afaik
120- //var newImage = ImageSource.fromFileOrResource(data.newValue);
110+ var fab = data . object ;
111+ var icon = data . newValue ;
112+ var iconDrawable = null ;
113+
114+ if ( ImageSource . isFileOrResourcePath ( icon ) ) {
115+ iconDrawable = ImageSource . fromFileOrResource ( icon ) ;
116+
117+ //Kill the old Image, cocoapod doesn't support changing it yet
118+ var button = fab . ios . subviews [ 0 ] ;
119+ var oldBadImageView = button . subviews [ 0 ] ;
120+ oldBadImageView . removeFromSuperview ( ) ;
121+ oldBadImageView . dealloc ( ) ;
122+
123+ var newImageView = null ;
124+
125+ //Set the new one
126+ if ( iconDrawable ) {
127+ newImageView = UIImageView . alloc ( ) . initWithImage ( iconDrawable . ios ) ;
128+ } else {
129+ //Default image
130+ var defaultImage = ImageSource . fromBase64 ( "iVBORw0KGgoAAAANSUhEUgAAAJAAAACQAQAAAADPPd8VAAAAAnRSTlMAAHaTzTgAAAAqSURBVHgBY6AMjIJRYP9n0AuNCo0KMf+HgwPDTmgoRMeo0KgQRWAUjAIABsnZRR7bYyUAAAAASUVORK5CYII=" ) ;
131+ newImageView = UIImageView . alloc ( ) . initWithImage ( defaultImage . ios ) ;
132+ newImageView . frame = CGRectMake ( 0 , 0 , 40 , 40 ) ; //resize
133+ }
134+
135+ button . addSubview ( newImageView ) ;
121136 }
122137}
123- common . Fab . iconProperty . metadata . onSetNativeValue = onIconPropertyChanged ;
138+ common . Fab . iconProperty . metadata . onSetNativeValue = onIconPropertyChanged ;
139+
140+ function centerIcon ( fab , newValue ) {
141+ var button = fab . ios . subviews [ 0 ] ;
142+ var imageView = button . subviews [ 0 ] ;
143+
144+ imageView . center = CGPointMake ( newValue / 2 ,
145+ newValue / 2 ) ;
146+ }
0 commit comments