@@ -10,42 +10,31 @@ import {
10
10
rippleColorProperty
11
11
} from './fab-common' ;
12
12
13
- declare var android : any ;
14
-
15
13
export class Fab extends FloatingActionButtonBase {
16
14
private _androidViewId : number ;
17
- private _android : any ;
15
+ private _android : android . support . design . widget . FloatingActionButton ;
18
16
public static tapEvent = 'tap' ;
19
17
20
- get android ( ) : any {
18
+ get android ( ) : android . support . design . widget . FloatingActionButton {
21
19
return this . nativeView ;
22
20
}
23
21
24
22
public createNativeView ( ) {
25
23
this . _android = new android . support . design . widget . FloatingActionButton (
26
24
this . _context
27
25
) ;
28
- const that = new WeakRef ( this ) ;
29
- this . _android . setOnClickListener (
30
- new android . view . View . OnClickListener ( {
31
- get owner ( ) {
32
- return that . get ( ) ;
33
- } ,
34
-
35
- onClick : function ( v ) {
36
- if ( this . owner ) {
37
- this . owner . _emit ( 'tap' ) ;
38
- }
39
- }
40
- } )
41
- ) ;
42
-
43
26
return this . _android ;
44
27
}
45
28
46
29
public initNativeView ( ) {
47
30
this . _androidViewId = android . view . View . generateViewId ( ) ;
48
31
this . nativeView . setId ( this . _androidViewId ) ;
32
+ initializeClickListener ( ) ;
33
+ const clickListener = new ClickListener ( this ) ;
34
+ this . nativeView . setOnClickListener ( clickListener ) ;
35
+ ( < any > this . nativeView ) . clickListener = clickListener ;
36
+ // setting scale type statically for now - can add configuration options with next release after confirming fixes for other icons sizes
37
+ this . android . setScaleType ( android . widget . ImageView . ScaleType . CENTER ) ;
49
38
}
50
39
51
40
[ backgroundColorProperty . getDefault ] ( ) : android . content . res . ColorStateList {
@@ -112,3 +101,33 @@ export class Fab extends FloatingActionButtonBase {
112
101
}
113
102
}
114
103
}
104
+
105
+ interface ClickListener {
106
+ new ( owner : FloatingActionButtonBase ) : android . view . View . OnClickListener ;
107
+ }
108
+
109
+ let ClickListener : ClickListener ;
110
+
111
+ function initializeClickListener ( ) : void {
112
+ if ( ClickListener ) {
113
+ return ;
114
+ }
115
+
116
+ @Interfaces ( [ android . view . View . OnClickListener ] )
117
+ class ClickListenerImpl extends java . lang . Object
118
+ implements android . view . View . OnClickListener {
119
+ constructor ( public owner : FloatingActionButtonBase ) {
120
+ super ( ) ;
121
+ return global . __native ( this ) ;
122
+ }
123
+
124
+ public onClick ( v : android . view . View ) : void {
125
+ const owner = this . owner ;
126
+ if ( owner ) {
127
+ ( < any > owner ) . _emit ( 'tap' ) ;
128
+ }
129
+ }
130
+ }
131
+
132
+ ClickListener = ClickListenerImpl ;
133
+ }
0 commit comments