-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathfab-common.ts
More file actions
243 lines (229 loc) · 6.79 KB
/
fab-common.ts
File metadata and controls
243 lines (229 loc) · 6.79 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
import {
Color,
Font,
ImageSource,
PanGestureEventData,
Property,
View
} from '@nativescript/core';
import { FontStyle, FontWeight } from '@nativescript/core/ui/styling/font';
import * as definitions from './index';
export class FloatingActionButtonBase extends View implements definitions.Fab {
private swipeEventAttached: boolean = false;
hideOnSwipeOfView: string;
swipeAnimation:
| 'slideUp'
| 'slideDown'
| 'slideRight'
| 'slideLeft'
| 'scale';
hideAnimationDuration: number;
rippleColor: Color;
icon: string;
onLoaded() {
super.onLoaded();
if (this.swipeEventAttached === false) {
const fab = this;
if (this.hideOnSwipeOfView) {
const parent = this.parent || this.parentNode;
const swipeItem = parent.getViewById(this.hideOnSwipeOfView);
// check if we have the UI to attach animation to
if (!swipeItem) {
return;
}
const animationType = this.swipeAnimation
? this.swipeAnimation
: 'slideDown';
if (swipeItem !== undefined) {
const duration = this.hideAnimationDuration
? this.hideAnimationDuration
: this._getDurationDefault(animationType);
swipeItem.on('pan', (args: PanGestureEventData) => {
// Swipe up
if (args.deltaY < -10) {
switch (animationType) {
case 'slideUp':
try {
fab.animate({
target: fab,
translate: {
x: 0,
y: -200,
},
opacity: 0,
duration: 400,
});
} catch (error) {
console.log(error);
}
break;
case 'slideDown':
fab.animate({
target: fab,
translate: {
x: 0,
y: 200,
},
opacity: 0,
duration: duration,
});
break;
case 'slideRight':
fab.animate({
target: fab,
translate: {
x: 200,
y: 0,
},
opacity: 0,
duration: duration,
});
break;
case 'slideLeft':
fab.animate({
target: fab,
translate: {
x: -200,
y: 0,
},
opacity: 0,
duration: duration,
});
break;
case 'scale':
fab.animate({
target: fab,
scale: {
x: 0,
y: 0,
},
duration: duration,
});
break;
}
} else if (args.deltaY > 0) {
// Swipe Down
switch (animationType) {
case 'slideUp':
fab.animate({
target: fab,
translate: {
x: 0,
y: 0,
},
opacity: 1,
duration: duration,
});
break;
case 'slideDown':
fab.animate({
target: fab,
translate: {
x: 0,
y: 0,
},
opacity: 1,
duration: duration,
});
break;
case 'slideRight':
fab.animate({
target: fab,
translate: {
x: 0,
y: 0,
},
opacity: 1,
duration: duration,
});
break;
case 'slideLeft':
fab.animate({
target: fab,
translate: {
x: 0,
y: 0,
},
opacity: 1,
duration: duration,
});
break;
case 'scale':
fab.animate({
target: fab,
scale: {
x: 1,
y: 1,
},
duration: duration,
});
break;
}
}
});
this.swipeEventAttached = true;
}
}
}
}
private _getDurationDefault(animationType: string) {
switch (animationType) {
case 'scale':
return 200;
default:
return 400;
}
}
protected getImageFromText(value: string): ImageSource {
const font = new Font(
this.style.fontFamily || 'normal',
this.style.fontSize || 16,
this.style.fontStyle || FontStyle.NORMAL,
this.style.fontWeight || FontWeight.LIGHT
);
const color = this.style.color || new Color('#FFFFFF');
return ImageSource.fromFontIconCodeSync(value, font, color);
}
}
export const iconProperty = new Property<FloatingActionButtonBase, string>({
name: 'icon',
affectsLayout: true,
});
iconProperty.register(FloatingActionButtonBase);
export const textProperty = new Property<FloatingActionButtonBase, string>({
name: 'text',
affectsLayout: true,
});
textProperty.register(FloatingActionButtonBase);
export const rippleColorProperty = new Property<
FloatingActionButtonBase,
Color
>({
name: 'rippleColor',
equalityComparer: Color.equals,
valueConverter: (v) => new Color(v),
});
rippleColorProperty.register(FloatingActionButtonBase);
export type AndroidScaleType =
| 'center'
| 'centerCrop'
| 'centerInside'
| 'fitCenter'
| 'fitEnd'
| 'fitStart'
| 'fitXY'
| 'matrix';
export const androidScaleTypeProperty = new Property<
FloatingActionButtonBase,
AndroidScaleType
>({
name: 'androidScaleType',
defaultValue: 'center',
affectsLayout: true,
});
androidScaleTypeProperty.register(FloatingActionButtonBase);
export const colorProperty = new Property({
name: 'color',
valueConverter: (v) => new Color(v),
});
colorProperty.register(FloatingActionButtonBase);