@@ -37,34 +37,42 @@ function initializeClickListener(): void {
3737 }
3838
3939 ClickListener = ClickListenerImpl ;
40- APILEVEL = android . os . Build . VERSION . SDK_INT ;
41- AndroidButton = android . widget . Button ;
4240}
4341
4442export class Button extends ButtonBase {
4543 nativeViewProtected : android . widget . Button ;
4644
45+ constructor ( ) {
46+ super ( ) ;
47+ if ( ! APILEVEL ) {
48+ APILEVEL = android . os . Build . VERSION . SDK_INT ;
49+ }
50+ }
51+
4752 private _stateListAnimator : any ;
4853 private _highlightedHandler : ( args : TouchGestureEventData ) => void ;
4954
5055 @profile
5156 public createNativeView ( ) {
52- initializeClickListener ( ) ;
53- const button = new AndroidButton ( this . _context ) ;
54- const clickListener = new ClickListener ( this ) ;
55- button . setOnClickListener ( clickListener ) ;
56- ( < any > button ) . clickListener = clickListener ;
57- return button ;
57+ if ( ! AndroidButton ) {
58+ AndroidButton = android . widget . Button ;
59+ }
60+ return new AndroidButton ( this . _context ) ;
5861 }
5962
6063 public initNativeView ( ) : void {
61- const nativeView = this . nativeViewProtected ;
62- ( < any > nativeView ) . clickListener . owner = this ;
6364 super . initNativeView ( ) ;
65+ const nativeView = this . nativeViewProtected ;
66+ initializeClickListener ( ) ;
67+ const clickListener = new ClickListener ( this ) ;
68+ nativeView . setOnClickListener ( clickListener ) ;
69+ ( < any > nativeView ) . clickListener = clickListener ;
6470 }
6571
6672 public disposeNativeView ( ) {
67- ( < any > this . nativeViewProtected ) . clickListener . owner = null ;
73+ if ( this . nativeViewProtected ) {
74+ ( < any > this . nativeViewProtected ) . clickListener . owner = null ;
75+ }
6876 super . disposeNativeView ( ) ;
6977 }
7078
0 commit comments