Skip to content

Commit 7239619

Browse files
committed
closes #84
1 parent 836db8e commit 7239619

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

src/fab.android.ts

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,31 @@ import {
1010
rippleColorProperty
1111
} from './fab-common';
1212

13-
declare var android: any;
14-
1513
export class Fab extends FloatingActionButtonBase {
1614
private _androidViewId: number;
17-
private _android: any;
15+
private _android: android.support.design.widget.FloatingActionButton;
1816
public static tapEvent = 'tap';
1917

20-
get android(): any {
18+
get android(): android.support.design.widget.FloatingActionButton {
2119
return this.nativeView;
2220
}
2321

2422
public createNativeView() {
2523
this._android = new android.support.design.widget.FloatingActionButton(
2624
this._context
2725
);
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-
4326
return this._android;
4427
}
4528

4629
public initNativeView() {
4730
this._androidViewId = android.view.View.generateViewId();
4831
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);
4938
}
5039

5140
[backgroundColorProperty.getDefault](): android.content.res.ColorStateList {
@@ -112,3 +101,33 @@ export class Fab extends FloatingActionButtonBase {
112101
}
113102
}
114103
}
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

Comments
 (0)