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 ) ;
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 ( {
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