5
5
* https://twitter.com/BradWayneMartin
6
6
* https://github.com/bradmartin
7
7
* 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
9
9
*************************************************************************************/
10
10
11
11
var common = require ( "./fab-common" ) ;
@@ -27,7 +27,10 @@ var FloatingActionButton = (function (_super) {
27
27
var _this = this ;
28
28
_super . call ( this ) ;
29
29
30
- var button = KCFloatingActionButton . alloc ( ) . init ( ) ;
30
+ var button = MNFloatingActionButton . alloc ( ) . init ( ) ;
31
+
32
+ button . animationScale = 0.95 ;
33
+
31
34
this . _ios = button ;
32
35
33
36
}
@@ -48,50 +51,39 @@ exports.Fab = FloatingActionButton;
48
51
var FloatingActionButtonStyler = ( function ( ) {
49
52
function FloatingActionButtonStyler ( ) {
50
53
}
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
- } ;
64
54
65
55
// BACKGROUND COLOR
66
56
FloatingActionButtonStyler . setBackgroundColorProperty = function ( view , newValue ) {
67
57
var fab = view . ios ;
68
- fab . buttonColor = newValue ;
58
+ fab . backgroundColor = newValue ;
69
59
} ;
70
60
FloatingActionButtonStyler . resetBackgroundColorProperty = function ( view , nativeValue ) {
71
61
var fab = view . ios ;
72
- fab . buttonColor = nativeValue ;
62
+ fab . backgroundColor = nativeValue ;
73
63
} ;
74
64
FloatingActionButtonStyler . getNativeBackgroundColorValue = function ( view ) {
75
65
var fab = view . ios ;
76
- return fab . buttonColor ;
66
+ return fab . backgroundColor ;
77
67
} ;
78
68
79
69
// WIDTH\HEIGHT
80
70
FloatingActionButtonStyler . setSizeProperty = function ( view , newValue ) {
81
71
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
83
76
} ;
84
77
FloatingActionButtonStyler . resetSizeProperty = function ( view , nativeValue ) {
85
78
var fab = view . ios ;
86
- fab . size = nativeValue ;
79
+ fab . bounds . size . width = nativeValue ;
87
80
} ;
88
81
FloatingActionButtonStyler . getNativeSizeValue = function ( view ) {
89
82
var fab = view . ios ;
90
- return fab . size ;
83
+ return fab . bounds . size . width ;
91
84
} ;
92
85
93
86
FloatingActionButtonStyler . registerHandlers = function ( ) {
94
- style . registerHandler ( style . colorProperty , new style . StylePropertyChangedHandler ( FloatingActionButtonStyler . setColorProperty , FloatingActionButtonStyler . resetColorProperty , FloatingActionButtonStyler . getNativeColorValue ) , "FloatingActionButton" ) ;
95
87
style . registerHandler ( style . backgroundColorProperty , new style . StylePropertyChangedHandler ( FloatingActionButtonStyler . setBackgroundColorProperty , FloatingActionButtonStyler . resetBackgroundColorProperty , FloatingActionButtonStyler . getNativeBackgroundColorValue ) , "FloatingActionButton" ) ;
96
88
style . registerHandler ( style . backgroundInternalProperty , style . ignorePropertyHandler , "FloatingActionButton" ) ;
97
89
style . registerHandler ( style . widthProperty , new style . StylePropertyChangedHandler ( FloatingActionButtonStyler . setSizeProperty , FloatingActionButtonStyler . resetSizeProperty , FloatingActionButtonStyler . getNativeSizeValue ) , "FloatingActionButton" ) ;
@@ -108,16 +100,47 @@ FloatingActionButtonStyler.registerHandlers();
108
100
function onBackColorPropertyChanged ( data ) {
109
101
if ( color . Color . isValid ( data . newValue ) ) {
110
102
var fab = data . object ;
111
- fab . ios . buttonColor = new color . Color ( data . newValue ) . ios ;
103
+ fab . ios . backgroundColor = new color . Color ( data . newValue ) . ios ;
112
104
}
113
105
}
114
106
common . Fab . backColorProperty . metadata . onSetNativeValue = onBackColorPropertyChanged ;
115
107
116
108
//Icon
117
109
function 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 ) ;
121
136
}
122
137
}
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