7
7
* https://github.com/bradmartin
8
8
* Pull requests are welcome. Enjoy!
9
9
*************************************************************************************/
10
-
11
- var view = require ( "ui/core/view" ) ;
12
- var color = require ( "color" ) ;
13
- var frameModule = require ( "ui/frame" ) ;
14
- var dObservable = require ( "ui/core/dependency-observable" ) ;
15
- var proxy = require ( "ui/core/proxy" ) ;
16
-
17
- var FloatingActionButton = ( function ( _super ) {
18
- global . __extends ( FloatingActionButton , _super ) ;
19
-
20
- function FloatingActionButton ( ) {
21
- _super . call ( this ) ;
22
-
23
- this . swipeEventAttached = false ;
24
-
25
- this . getDurationDefault = function ( animationType ) {
26
- switch ( animationType ) {
27
- case "scale" :
28
- return 100 ;
29
- default :
30
- return 300 ;
31
- }
32
- } ;
10
+ import * as definitions from "./index" ;
11
+ import { View , Property } from "ui/core/view" ;
12
+ import { Color } from "color" ;
13
+ import { PanGestureEventData } from "ui/gestures" ;
14
+
15
+ export class FloatingActionButtonBase extends View implements definitions . Fab {
16
+
17
+ private swipeEventAttached : boolean = false ;
18
+ public hideOnSwipeOfView : string ;
19
+ public swipeAnimation : "slideUp" | "slideDown" | "slideRight" | "slideLeft" | "scale" ;
20
+ public hideAnimationDuration : number ;
21
+
22
+ public rippleColor : Color ;
23
+ public icon : string ;
24
+ public backColor : Color ;
25
+
26
+ getDurationDefault ( animationType : string ) {
27
+ switch ( animationType ) {
28
+ case "scale" :
29
+ return 100 ;
30
+ default :
31
+ return 300 ;
32
+ }
33
33
}
34
34
35
-
36
- FloatingActionButton . prototype . onLoaded = function ( ) {
37
- _super . prototype . onLoaded . call ( this ) ;
35
+ onLoaded ( ) {
36
+ super . onLoaded ( )
38
37
39
38
if ( this . swipeEventAttached === false ) {
40
39
var fab = this ;
41
- var viewToAttachTo = this . hideOnSwipeOfView ;
42
- if ( viewToAttachTo !== undefined ) {
43
- var swipeItem = frameModule . topmost ( ) . getViewById ( viewToAttachTo ) ;
40
+ if ( this . hideOnSwipeOfView !== undefined ) {
41
+ var swipeItem = this . page . getViewById ( this . hideOnSwipeOfView ) ;
44
42
var animationType = ( this . swipeAnimation ) ? this . swipeAnimation : "slideDown"
45
43
46
44
if ( swipeItem !== undefined ) {
47
45
var duration = ( this . hideAnimationDuration ) ? this . hideAnimationDuration : this . getDurationDefault ( animationType ) ;
48
46
49
- swipeItem . on ( "pan" , function ( args ) {
47
+ swipeItem . on ( "pan" , ( args : PanGestureEventData ) => {
50
48
//Swipe up
51
49
if ( args . deltaY < - 10 ) {
52
50
switch ( animationType ) {
@@ -163,40 +161,25 @@ var FloatingActionButton = (function (_super) {
163
161
}
164
162
}
165
163
} ;
164
+ }
166
165
167
- Object . defineProperty ( FloatingActionButton . prototype , "rippleColor" , {
168
- get : function ( ) {
169
- return this . _getValue ( FloatingActionButton . rippleColorProperty ) ;
170
- } ,
171
- set : function ( value ) {
172
- this . _setValue ( FloatingActionButton . rippleColorProperty , value ) ;
173
- }
174
- } ) ;
175
166
176
- Object . defineProperty ( FloatingActionButton . prototype , "backColor" , {
177
- get : function ( ) {
178
- return this . _getValue ( FloatingActionButton . backColorProperty ) ;
179
- } ,
180
- set : function ( value ) {
181
- this . _setValue ( FloatingActionButton . backColorProperty , value ) ;
182
- }
183
- } ) ;
184
-
185
- Object . defineProperty ( FloatingActionButton . prototype , "icon" , {
186
- get : function ( ) {
187
- return this . _getValue ( FloatingActionButton . iconProperty ) ;
188
- } ,
189
- set : function ( value ) {
190
- this . _setValue ( FloatingActionButton . iconProperty , value ) ;
191
- }
192
- } ) ;
193
-
194
- FloatingActionButton . backColorProperty = new dObservable . Property ( "backColor" , "FloatingActionButton" , new proxy . PropertyMetadata ( 0 , dObservable . PropertyMetadataSettings . AffectsLayout ) ) ;
195
- FloatingActionButton . iconProperty = new dObservable . Property ( "icon" , "FloatingActionButton" , new proxy . PropertyMetadata ( 0 , dObservable . PropertyMetadataSettings . AffectsLayout ) ) ;
196
- FloatingActionButton . rippleColorProperty = new dObservable . Property ( "rippleColor" , "FloatingActionButton" , new proxy . PropertyMetadata ( 0 , dObservable . PropertyMetadataSettings . AffectsLayout ) ) ;
197
-
198
-
199
- return FloatingActionButton ;
200
- } ) ( view . View ) ;
201
-
202
- exports . Fab = FloatingActionButton ;
167
+ export const backColorProperty = new Property < FloatingActionButtonBase , Color > ( {
168
+ name : "backColor" ,
169
+ equalityComparer : Color . equals ,
170
+ valueConverter : ( v ) => new Color ( v ) ,
171
+ valueChanged : ( fab , oldValue , newValue ) => {
172
+ fab . style . backgroundColor = newValue
173
+ }
174
+ } ) ;
175
+ backColorProperty . register ( FloatingActionButtonBase ) ;
176
+
177
+ export const iconProperty = new Property < FloatingActionButtonBase , string > ( {
178
+ name : "icon" , affectsLayout : true
179
+ } ) ;
180
+ iconProperty . register ( FloatingActionButtonBase ) ;
181
+
182
+ export const rippleColorProperty = new Property < FloatingActionButtonBase , Color > ( {
183
+ name : "rippleColor" , equalityComparer : Color . equals , valueConverter : ( v ) => new Color ( v )
184
+ } ) ;
185
+ rippleColorProperty . register ( FloatingActionButtonBase ) ;
0 commit comments