Skip to content

Commit 5ba639a

Browse files
committed
Merge pull request #13 from sitefinitysteve/master
Changed Cocoapod
2 parents 6b4bedd + 45310ef commit 5ba639a

File tree

4 files changed

+70
-50
lines changed

4 files changed

+70
-50
lines changed

README.md

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# NativeScript-FloatingActionButton
2-
XML widget to create the Material Design Floating Action Button for NativeScript apps.
2+
XML widget to create the Material Design Floating Action Button for NativeScript apps.
33

44
[Material Design Floating Action Button Spec](https://www.google.com/design/spec/components/buttons-floating-action-button.html)
55

@@ -39,15 +39,14 @@ PLEASE NOTE: The fab is on the same **row number** as the listview
3939
***
4040

4141
#### CSS
42-
Recommended CSS styles.
42+
Recommended CSS styles.
4343
```CSS
4444
.fab-button {
4545
height: 70;
4646
margin: 15;
4747
background-color: #ff4081;
48-
horizontal-align: right; /* Android Only */
49-
vertical-align: bottom; /* Android Only */
50-
color: #fff; /* iOS Only */
48+
horizontal-align: right;
49+
vertical-align: bottom;
5150
}
5251
```
5352

@@ -64,26 +63,24 @@ exports.fabTap = function(args) {
6463
***
6564

6665
## Attributes
67-
66+
6867
| Property | Android | iOS | Description | Note |
69-
|------------|-------------------|------|-------------|------|
70-
| backColor | X | X | Sets the background color of the button | None
71-
| icon | X | | Supports the same image source options that NativeScript images support | Required on android
72-
| rippleColor| X | | Ripple color on lollipop devices, it will fill the FAB on pre-lollipop devices | None
73-
74-
## NativeScript Compatibility
75-
76-
| NativeScript Version | FloatingActionButton Plugin Version |
77-
|----------------------|-------------------------------------|
78-
| 1.6 | 2.+ |
79-
| 1.5 | 1.91 |
68+
|------------|-------------------|------|-------------|------|
69+
| backColor | X | X | Sets the background color of the button | None
70+
| icon | X | X | Supports the same image source options that NativeScript images support | Required on android
71+
| rippleColor| X | | Ripple color on lollipop devices, it will fill the FAB on pre-lollipop devices | None
72+
73+
## NativeScript Compatibility
74+
75+
| NativeScript Version | FloatingActionButton Plugin Version |
76+
|----------------------|-------------------------------------|
77+
| 1.6 | 2.+ |
78+
| 1.5 | 1.91 |
8079

8180
## iOS Notes
82-
- Since iOS doesn't have a native FAB, we're using the amazing [KCFloatingActionButton](https://cocoapods.org/pods/KCFloatingActionButton) by [Lee Sun-Hyoup](https://github.com/kciter)
83-
As of this publish, it does not yet support images, however this is an Issue open.
84-
- Requires XCode CommandLineTools 7.1 to build, [the Cocoapod tanks when using 7.2](https://github.com/NativeScript/nativescript-cli/issues/1521)
81+
- We're using [MNFloatingActionButton](http://cocoapods.org/pods/MNFloatingActionButton) by [Matt Nydam](https://github.com/mattnydam)
8582

8683
### Contributors
8784

88-
- Lázaro Danillo [lazaromenezes](https://github.com/lazaromenezes)
85+
- Lázaro Danillo [lazaromenezes](https://github.com/lazaromenezes)
8986
- Steve McNiven-Scott [sitefinitysteve](https://github.com/sitefinitysteve) - iOS

fab.ios.js

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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

1111
var 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;
4851
var 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();
108100
function 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
}
114106
common.Fab.backColorProperty.metadata.onSetNativeValue = onBackColorPropertyChanged;
115107

116108
//Icon
117109
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);
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+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-floatingactionbutton",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"description": "A NativeScript plugin to provide an XML widget to implement the Material Design Floating Action Button in NativeScript apps.",
55
"main": "fab.js",
66
"nativescript": {

platforms/ios/PodFile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pod 'KCFloatingActionButton'
1+
pod 'MNFloatingActionButton', '~> 0.1'

0 commit comments

Comments
 (0)