|
1 | | -/************************************************************************************** |
| 1 | +/************************************************************************************** |
2 | 2 | * Made for the {N} community by Brad Martin @BradWayneMartin |
3 | | - * Thanks to Lazaro Danillo for his contributions - https://github.com/lazaromenezes |
4 | | - * Thanks to Steve McNiven-Scott for his contributions - https://github.com/sitefinitysteve |
5 | | - * https://twitter.com/BradWayneMartin |
6 | | - * https://github.com/bradmartin |
7 | | - * Pull requests are welcome. Enjoy! |
8 | | - *************************************************************************************/ |
9 | | - |
10 | | -var common = require("./fab-common"); |
11 | | -var style = require("ui/styling/style"); |
12 | | -var utils = require("utils/utils"); |
13 | | -var color = require("color"); |
14 | | -var ImageSource = require("image-source"); |
15 | | - |
16 | | - require("utils/module-merge").merge(common, module.exports); |
17 | | - |
18 | | - var FloatingActionButton = (function (_super) { |
19 | | - |
20 | | - global.__extends(FloatingActionButton, _super); |
21 | | - |
22 | | - function FloatingActionButton() { |
23 | | - _super.apply(this, arguments); |
24 | | - } |
25 | | - |
26 | | - FloatingActionButton.prototype._createUI = function () { |
27 | | - |
28 | | - this._android = new android.support.design.widget.FloatingActionButton(this._context); |
29 | | - |
30 | | - var that = new WeakRef(this); |
31 | | - |
32 | | - this._android.setOnClickListener(new android.view.View.OnClickListener({ |
33 | | - get owner() { |
34 | | - return that.get(); |
35 | | - }, |
36 | | - |
37 | | - onClick: function (v) { |
38 | | - if (this.owner) { |
39 | | - this.owner._emit("tap"); |
40 | | - } |
41 | | - } |
42 | | - })); |
43 | | - }; |
44 | | - |
45 | | - Object.defineProperty(FloatingActionButton.prototype, "android", { |
46 | | - get: function () { |
47 | | - return this._android; |
48 | | - } |
49 | | - }); |
50 | | - |
51 | | - return FloatingActionButton; |
52 | | - |
53 | | - })(common.Fab); |
54 | | - |
55 | | - exports.Fab = FloatingActionButton; |
56 | | - |
57 | | - |
58 | | -/* SETUP CSS */ |
59 | | -var FloatingActionButtonStyler = (function () { |
60 | | - function FloatingActionButtonStyler() { |
61 | | - } |
62 | | - // BACKGROUND COLOR |
63 | | - FloatingActionButtonStyler.setBackgroundColorProperty = function (view, newValue) { |
64 | | - var fab = view.android; |
65 | | - fab.setBackgroundTintList(android.content.res.ColorStateList.valueOf(newValue)); |
66 | | - }; |
67 | | - FloatingActionButtonStyler.resetBackgroundColorProperty = function (view, nativeValue) { |
68 | | - var fab = view.android; |
69 | | - fab.setBackgroundTintList(android.content.res.ColorStateList.valueOf(nativeValue)); |
70 | | - }; |
71 | | - FloatingActionButtonStyler.getNativeBackgroundColorValue = function (view) { |
72 | | - var fab = view.android; |
73 | | - return fab.getBackgroundTintList(); |
74 | | - }; |
75 | | - |
76 | | - FloatingActionButtonStyler.registerHandlers = function () { |
77 | | - style.registerHandler(style.backgroundColorProperty, new style.StylePropertyChangedHandler(FloatingActionButtonStyler.setBackgroundColorProperty, FloatingActionButtonStyler.resetBackgroundColorProperty, FloatingActionButtonStyler.getNativeBackgroundColorValue), "FloatingActionButton"); |
78 | | - style.registerHandler(style.backgroundInternalProperty, style.ignorePropertyHandler, "FloatingActionButton"); |
79 | | - }; |
80 | | - return FloatingActionButtonStyler; |
81 | | -})(); |
82 | | -exports.FloatingActionButtonStyler = FloatingActionButtonStyler; |
83 | | -FloatingActionButtonStyler.registerHandlers(); |
84 | | - |
85 | | - /* SETUP PROPERTIES */ |
86 | | -//Background Color |
87 | | -function onBackColorPropertyChanged(data) { |
88 | | - if(color.Color.isValid(data.newValue)){ |
89 | | - var fab = data.object; |
90 | | - var droidColor = new color.Color(data.newValue).android; |
91 | | - fab.android.setBackgroundTintList(android.content.res.ColorStateList.valueOf(droidColor)); |
92 | | - } |
93 | | -} |
94 | | -common.Fab.backColorProperty.metadata.onSetNativeValue = onBackColorPropertyChanged; |
95 | | - |
96 | | -//Icon |
97 | | -function onIconPropertyChanged(data) { |
98 | | - var fab = data.object; |
99 | | - var icon = data.newValue; |
100 | | - var iconDrawable = null; |
101 | | - |
102 | | - if(ImageSource.isFileOrResourcePath(icon)){ |
103 | | - iconDrawable = ImageSource.fromFileOrResource(icon); |
| 3 | + * Thanks to Lazaro Danillo for his contributions - https://github.com/lazaromenezes |
| 4 | + * Thanks to Steve McNiven-Scott for his contributions - https://github.com/sitefinitysteve |
| 5 | + * https://twitter.com/BradWayneMartin |
| 6 | + * https://github.com/bradmartin |
| 7 | + * Pull requests are welcome. Enjoy! |
| 8 | + *************************************************************************************/ |
| 9 | + |
| 10 | +var common = require("./fab-common"); |
| 11 | +var style = require("ui/styling/style"); |
| 12 | +var utils = require("utils/utils"); |
| 13 | +var color = require("color"); |
| 14 | +var ImageSource = require("image-source"); |
| 15 | + |
| 16 | + require("utils/module-merge").merge(common, module.exports); |
| 17 | + |
| 18 | + var FloatingActionButton = (function (_super) { |
| 19 | + |
| 20 | + global.__extends(FloatingActionButton, _super); |
| 21 | + |
| 22 | + function FloatingActionButton() { |
| 23 | + _super.apply(this, arguments); |
| 24 | + } |
| 25 | + |
| 26 | + FloatingActionButton.prototype._createUI = function () { |
| 27 | + |
| 28 | + this._android = new android.support.design.widget.FloatingActionButton(this._context); |
| 29 | + |
| 30 | + var that = new WeakRef(this); |
| 31 | + |
| 32 | + this._android.setOnClickListener(new android.view.View.OnClickListener({ |
| 33 | + get owner() { |
| 34 | + return that.get(); |
| 35 | + }, |
| 36 | + |
| 37 | + onClick: function (v) { |
| 38 | + if (this.owner) { |
| 39 | + this.owner._emit("tap"); |
| 40 | + } |
| 41 | + } |
| 42 | + })); |
| 43 | + }; |
| 44 | + |
| 45 | + Object.defineProperty(FloatingActionButton.prototype, "android", { |
| 46 | + get: function () { |
| 47 | + return this._android; |
| 48 | + } |
| 49 | + }); |
| 50 | + |
| 51 | + return FloatingActionButton; |
| 52 | + |
| 53 | + })(common.Fab); |
| 54 | + |
| 55 | + exports.Fab = FloatingActionButton; |
| 56 | + |
| 57 | + |
| 58 | +/* SETUP CSS */ |
| 59 | +var FloatingActionButtonStyler = (function () { |
| 60 | + function FloatingActionButtonStyler() { |
| 61 | + } |
| 62 | + // BACKGROUND COLOR |
| 63 | + FloatingActionButtonStyler.setBackgroundColorProperty = function (view, newValue) { |
| 64 | + var fab = view.android; |
| 65 | + fab.setBackgroundTintList(android.content.res.ColorStateList.valueOf(newValue)); |
| 66 | + }; |
| 67 | + FloatingActionButtonStyler.resetBackgroundColorProperty = function (view, nativeValue) { |
| 68 | + var fab = view.android; |
| 69 | + fab.setBackgroundTintList(android.content.res.ColorStateList.valueOf(nativeValue)); |
| 70 | + }; |
| 71 | + FloatingActionButtonStyler.getNativeBackgroundColorValue = function (view) { |
| 72 | + var fab = view.android; |
| 73 | + return fab.getBackgroundTintList(); |
| 74 | + }; |
| 75 | + |
| 76 | + FloatingActionButtonStyler.registerHandlers = function () { |
| 77 | + style.registerHandler(style.backgroundColorProperty, new style.StylePropertyChangedHandler(FloatingActionButtonStyler.setBackgroundColorProperty, FloatingActionButtonStyler.resetBackgroundColorProperty, FloatingActionButtonStyler.getNativeBackgroundColorValue), "FloatingActionButton"); |
| 78 | + style.registerHandler(style.backgroundInternalProperty, style.ignorePropertyHandler, "FloatingActionButton"); |
| 79 | + }; |
| 80 | + return FloatingActionButtonStyler; |
| 81 | +})(); |
| 82 | +exports.FloatingActionButtonStyler = FloatingActionButtonStyler; |
| 83 | +FloatingActionButtonStyler.registerHandlers(); |
| 84 | + |
| 85 | + /* SETUP PROPERTIES */ |
| 86 | +//Background Color |
| 87 | +function onBackColorPropertyChanged(data) { |
| 88 | + if(color.Color.isValid(data.newValue)){ |
| 89 | + var fab = data.object; |
| 90 | + var droidColor = new color.Color(data.newValue).android; |
| 91 | + fab.android.setBackgroundTintList(android.content.res.ColorStateList.valueOf(droidColor)); |
| 92 | + } |
| 93 | +} |
| 94 | +common.Fab.backColorProperty.metadata.onSetNativeValue = onBackColorPropertyChanged; |
| 95 | + |
| 96 | +//Icon |
| 97 | +function onIconPropertyChanged(data) { |
| 98 | + var fab = data.object; |
| 99 | + var icon = data.newValue; |
| 100 | + var iconDrawable = null; |
| 101 | + |
| 102 | + if(ImageSource.isFileOrResourcePath(icon)){ |
| 103 | + iconDrawable = ImageSource.fromFileOrResource(icon); |
104 | 104 | if (iconDrawable) { |
105 | 105 | fab.android.setImageBitmap(iconDrawable.android); |
106 | 106 | } else { |
107 | 107 | console.log("The icon: " + icon + " was not found. Check your XML icon property."); |
108 | | - } |
| 108 | + } |
109 | 109 | } else { |
110 | | - var drawableId = android.content.res.Resources.getSystem().getIdentifier(icon, "drawable", "android"); |
| 110 | + var drawableId = android.content.res.Resources.getSystem().getIdentifier(icon, "drawable", "android"); |
111 | 111 | iconDrawable = android.content.res.Resources.getSystem().getDrawable(drawableId); |
112 | 112 | if (iconDrawable) { |
113 | 113 | fab.android.setImageDrawable(iconDrawable); |
114 | 114 | } else { |
115 | 115 | console.log("The icon: " + icon + " was not found. Check your XML icon property."); |
116 | 116 | } |
117 | 117 | } |
118 | | -} |
119 | | -common.Fab.iconProperty.metadata.onSetNativeValue = onIconPropertyChanged; |
120 | | - |
121 | | -//Ripple Color |
122 | | -function onRippleColorPropertyChanged(data) { |
123 | | - if(color.Color.isValid(data.newValue)){ |
124 | | - var fab = data.object; |
125 | | - var droidColor = new color.Color(data.newValue).android; |
126 | | - fab.android.setRippleColor(droidColor); |
| 118 | +} |
| 119 | +common.Fab.iconProperty.metadata.onSetNativeValue = onIconPropertyChanged; |
| 120 | + |
| 121 | +//Ripple Color |
| 122 | +function onRippleColorPropertyChanged(data) { |
| 123 | + if(color.Color.isValid(data.newValue)){ |
| 124 | + var fab = data.object; |
| 125 | + var droidColor = new color.Color(data.newValue).android; |
| 126 | + fab.android.setRippleColor(droidColor); |
127 | 127 | } else { |
128 | 128 | console.log("The ripple color: " + data.newValue + " is invalid."); |
129 | | - } |
130 | | -} |
131 | | -common.Fab.rippleColorProperty.metadata.onSetNativeValue = onRippleColorPropertyChanged; |
| 129 | + } |
| 130 | +} |
| 131 | +common.Fab.rippleColorProperty.metadata.onSetNativeValue = onRippleColorPropertyChanged; |
0 commit comments