Skip to content

Commit 3cd6a73

Browse files
Latest droid code
1 parent 9fa4b3c commit 3cd6a73

File tree

2 files changed

+45
-25
lines changed

2 files changed

+45
-25
lines changed

fab-common.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ var FloatingActionButton = (function (_super) {
1212

1313
Object.defineProperty(FloatingActionButton.prototype, "rippleColor", {
1414
get: function () {
15-
return this.rippleColorProperty;
15+
return this._getValue(FloatingActionButton.rippleColorProperty);
1616
},
17-
set: function(value){
18-
this.rippleColorProperty = new color.Color(value);
17+
set: function (value) {
18+
this._setValue(FloatingActionButton.rippleColorProperty, value);
1919
}
2020
});
2121

@@ -37,9 +37,9 @@ var FloatingActionButton = (function (_super) {
3737
}
3838
});
3939

40-
//Expose for iOS
4140
FloatingActionButton.backColorProperty = new dObservable.Property("backColor", "FloatingActionButton", new proxy.PropertyMetadata(0, dObservable.PropertyMetadataSettings.AffectsLayout));
4241
FloatingActionButton.iconProperty = new dObservable.Property("icon", "FloatingActionButton", new proxy.PropertyMetadata(0, dObservable.PropertyMetadataSettings.AffectsLayout));
42+
FloatingActionButton.rippleColorProperty = new dObservable.Property("rippleColor", "FloatingActionButton", new proxy.PropertyMetadata(0, dObservable.PropertyMetadataSettings.AffectsLayout));
4343

4444
return FloatingActionButton;
4545
})(view.View);

fab.android.js

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/**************************************************************************************
2-
* Made for the {N} community by Brad Martin @BradWayneMartin
2+
* Made for the {N} community by Brad Martin @BradWayneMartin
33
* Thanks to Lazaro Danillo for his contributions - https://github.com/lazaromenezes
44
* https://twitter.com/BradWayneMartin
55
* https://github.com/bradmartin
66
* Pull requests are welcome. Enjoy!
77
*************************************************************************************/
88

99
var common = require("./fab-common");
10+
var color = require("color");
1011
var ImageSource = require("image-source");
1112

1213
require("utils/module-merge").merge(common, module.exports);
@@ -23,26 +24,6 @@
2324

2425
this._android = new android.support.design.widget.FloatingActionButton(this._context);
2526

26-
if(this.rippleColor)
27-
this._android.setRippleColor(this.rippleColor.android);
28-
29-
if (this.backColor)
30-
this._android.setBackgroundTintList(android.content.res.ColorStateList.valueOf(this.backColor.android));
31-
32-
if(this.icon){
33-
var iconDrawable = null;
34-
35-
if(ImageSource.isFileOrResourcePath(this.icon)){
36-
iconDrawable = ImageSource.fromFileOrResource(this.icon);
37-
this._android.setImageBitmap(iconDrawable.android);
38-
}
39-
else{
40-
var drawableId = android.content.res.Resources.getSystem().getIdentifier(this.icon, "drawable", "android");
41-
iconDrawable = android.content.res.Resources.getSystem().getDrawable(drawableId);
42-
this._android.setImageDrawable(iconDrawable);
43-
}
44-
}
45-
4627
var that = new WeakRef(this);
4728

4829
this._android.setOnClickListener(new android.view.View.OnClickListener({
@@ -69,3 +50,42 @@
6950
})(common.Fab);
7051

7152
exports.Fab = FloatingActionButton;
53+
54+
/* SETUP PROPERTIES */
55+
//Background Color
56+
function onBackColorPropertyChanged(data) {
57+
if(color.Color.isValid(data.newValue)){
58+
var fab = data.object;
59+
var droidColor = new color.Color(data.newValue).android;
60+
fab.android.setBackgroundTintList(android.content.res.ColorStateList.valueOf(droidColor));
61+
}
62+
}
63+
common.Fab.backColorProperty.metadata.onSetNativeValue = onBackColorPropertyChanged;
64+
65+
//Icon
66+
function onIconPropertyChanged(data) {
67+
var fab = data.object;
68+
var icon = data.newValue;
69+
var iconDrawable = null;
70+
71+
if(ImageSource.isFileOrResourcePath(icon)){
72+
iconDrawable = ImageSource.fromFileOrResource(icon);
73+
fab.android.setImageBitmap(iconDrawable.android);
74+
}
75+
else{
76+
var drawableId = android.content.res.Resources.getSystem().getIdentifier(icon, "drawable", "android");
77+
iconDrawable = android.content.res.Resources.getSystem().getDrawable(drawableId);
78+
fab.android.setImageDrawable(iconDrawable);
79+
}
80+
}
81+
common.Fab.iconProperty.metadata.onSetNativeValue = onIconPropertyChanged;
82+
83+
//Ripple Color
84+
function onRippleColorPropertyChanged(data) {
85+
if(color.Color.isValid(data.newValue)){
86+
var fab = data.object;
87+
var droidColor = new color.Color(data.newValue).android;
88+
fab.android.setRippleColor(droidColor);
89+
}
90+
}
91+
common.Fab.rippleColorProperty.metadata.onSetNativeValue = onRippleColorPropertyChanged;

0 commit comments

Comments
 (0)