-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfab.android.js
165 lines (149 loc) · 5.53 KB
/
fab.android.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*******************************************************
** NativeScript Floating Action Button ui/plugin
** Author : Tony Ooi
** File : fab.android.js
*******************************************************/
var common = require("./fab-common");
var Color = require("color").Color;
var ImageSource = require("image-source");
var Gestures = require("ui/gestures");
var view = require("ui/core/view");
require("utils/module-merge").merge(common, module.exports);
var FloatingActionButton = (function(_super){
global.__extends(FloatingActionButton,_super);
function FloatingActionButton(){
_super.apply(this,arguments);
}
FloatingActionButton.prototype._createUI = function(){
this._android = new android.support.design.widget.FloatingActionButton(this._context);
this._android.setUseCompatPadding(true);
var that = new WeakRef(this);
var onFloatingActionButtonClickListener = new android.view.View.OnClickListener({
onClick : function(fab){
var instance = that.get();
if(instance){
instance._emit("tap");
}
}
});
this._android.setOnClickListener(onFloatingActionButtonClickListener);
};
FloatingActionButton.prototype.onLoaded = function(){
_super.prototype.onLoaded.call(this);
console.log(this._parent);
console.log(this.anchorId);
var fab = this._android; // set here or else not resolvable, undefined
var fabParent = this._parent;
var anchorView = view.getViewById(this._parent,this.anchorId);
console.log("anchorview is ", anchorView)
if ( anchorView ) {
// console.log(args.state);
anchorView.on(Gestures.GestureTypes.pan, function(args){
switch( args.state ) {
// cancelled = 0 , began = 1 , changed = 2 , ended = 3
case 1 : fab.hide();
// fab.animate({ scale : { x : 0 , y: 0 } , duration : 280}) ; // in use case where fab = this
break ;
// end = 3
case 3 : fab.show();
// fab.animate({ scale : { x : 1 , y: 1 } , duration : 280}) ; // in use case where fab = this
break ;
}
})
} else {
console.log("Anchored view id "+this.anchorId+" could not be found/located");
// Use parent as fallback
fabParent.on(Gestures.GestureTypes.pan, function(args){
// console.log(args.state);
switch( args.state ) {
// cancelled = 0 , began = 1 , changed = 2 , ended = 3
case 1 : fab.hide();
// fab.animate({ scale : { x : 0 , y: 0 } , duration : 280}) ; // in use case where fab = this
break ;
// end = 3
case 3 : fab.show();
// fab.animate({ scale : { x : 1 , y: 1 } , duration : 280}) ; // in use case where fab = this
break ;
}
})
}
};
Object.defineProperty(FloatingActionButton.prototype,"android",{
get : function(){ return this._android ; }
});
return FloatingActionButton;
})(common.Fab);
exports.Fab = FloatingActionButton;
function onSizePropertyChanges(data){
var fab = data.object;
if ( !fab.android) {
return false;
}
fab.android.setSize(data.newValue);
}
common.Fab.sizeProperty.metadata.onSetNativeValue = onSizePropertyChanges;
function onRippleColorPropertyChanges(data){
var fab = data.object;
if ( !fab.android) {
return false;
}
if ( Color.isValid(data.newValue) ) {
rippleColor = new Color(data.newValue); //color is valid color
fab.android.setRippleColor(rippleColor.android); // convert to int when .android
} else {
console.log("Ripple color "+data.newValue+" is not a valid color. eg #fff or blue"); // automatically set to white during rippleColor initialization
}
}
common.Fab.rippleColorProperty.metadata.onSetNativeValue = onRippleColorPropertyChanges;
function onElevationPropertyChanges(data){
var fab = data.object;
if ( !fab.android) {
return false;
}
fab.android.setCompatElevation(data.newValue);
}
common.Fab.elevationProperty.metadata.onSetNativeValue = onElevationPropertyChanges;
function onImageResourcePropertyChanges(data){
var fab = data.object;
if ( !fab.android) {
return false;
}
var img = data.newValue;
var drawableImg = ImageSource.fromFileOrResource(img);
if( drawableImg ) {
fab.android.setImageBitmap(drawableImg.android);
} else {
console.log("Floating action image "+img+" is not found/available");
}
}
common.Fab.imageResourceProperty.metadata.onSetNativeValue = onImageResourcePropertyChanges;
function onIconResourcePropertyChanges(data){
var fab = data.object;
if ( !fab.android) {
return false;
}
var icon = data.newValue;
var drawableIcon = null ;
drawableId = android.content.res.Resources.getSystem().getIdentifier(icon,"drawable","android");
drawableIcon = android.content.res.Resources.getSystem().getDrawable(drawableId);
if( drawableIcon ) {
fab.android.setImageDrawable(drawableIcon);
} else {
console.log("Floating Action Button icon "+icon+" is not found/available");
}
// fab.android.setImageResource(data.newValue); // this icon is an int value referring to eg android.R.drawable.ic_menu_add
}
common.Fab.iconResourceProperty.metadata.onSetNativeValue = onIconResourcePropertyChanges;
function onTintPropertyChanges(data){
var fab = data.object;
if ( !fab.android) {
return false;
}
if( Color.isValid(data.newValue) ) {
var tintColor = new Color(data.newValue).android;
fab.android.setBackgroundTintList(android.content.res.ColorStateList.valueOf(tintColor));
} else {
console.log("Tint color is "+data.newValue+" not a valid color. eg #fff or blue");
}
}
common.Fab.tintProperty.metadata.onSetNativeValue = onTintPropertyChanges;