@@ -6,37 +6,45 @@ import { getRippleColor, themer } from 'nativescript-material-core/core';
6
6
7
7
import { activeColorCssProperty , BottomNavigationBarBase , BottomNavigationTabBase , inactiveColorCssProperty , tabsProperty , titleVisibilityProperty } from './bottomnavigationbar-common' ;
8
8
9
- // Delegate
10
- class BottomNavigationBarDelegate extends NSObject {
11
- static ObjCProtocols = [ MDCBottomNavigationBarDelegate ] ;
12
- private _owner : BottomNavigationBar ;
13
-
14
- static initWithOwner ( owner : WeakRef < BottomNavigationBar > ) : BottomNavigationBarDelegate {
15
- const delegate = < BottomNavigationBarDelegate > BottomNavigationBarDelegate . new ( ) ;
16
- delegate . _owner = owner . get ( ) ;
17
-
18
- return delegate ;
19
- }
20
-
21
- bottomNavigationBarDidSelectItem ( navigationBar : MDCBottomNavigationBar , item : UITabBarItem ) {
22
- if ( this . _owner . selectedTabIndex === item . tag ) {
23
- this . _owner . _emitTabReselected ( item . tag ) ;
24
- return ;
25
- }
26
-
27
- this . _owner . _emitTabSelected ( item . tag ) ;
28
- }
29
-
30
- bottomNavigationBarShouldSelectItem ( bottomNavigationBar : MDCBottomNavigationBar , item : UITabBarItem ) : boolean {
31
- const bottomNavigationTab = this . _owner . items [ item . tag ] ;
32
- if ( ! bottomNavigationTab . isSelectable ) {
33
- this . _owner . _emitTabPressed ( item . tag ) ;
34
- }
35
-
36
- return bottomNavigationTab . isSelectable ;
37
- }
9
+ declare class IBottomNavigationBarDelegate extends NSObject implements MDCBottomNavigationBarDelegate {
10
+ static new ( ) : IBottomNavigationBarDelegate ;
11
+ _owner : WeakRef < BottomNavigationBar > ;
38
12
}
39
13
14
+ const BottomNavigationBarDelegate = ( NSObject as any ) . extend (
15
+ {
16
+
17
+ bottomNavigationBarDidSelectItem ( navigationBar : MDCBottomNavigationBar , item : UITabBarItem ) {
18
+ const owner = this . _owner . get ( ) ;
19
+ if ( ! owner ) {
20
+ return ;
21
+ }
22
+ if ( owner . selectedTabIndex === item . tag ) {
23
+ owner . _emitTabReselected ( item . tag ) ;
24
+ return ;
25
+ }
26
+
27
+ owner . _emitTabSelected ( item . tag ) ;
28
+ } ,
29
+
30
+ bottomNavigationBarShouldSelectItem ( bottomNavigationBar : MDCBottomNavigationBar , item : UITabBarItem ) : boolean {
31
+ const owner = this . _owner . get ( ) ;
32
+ if ( ! owner ) {
33
+ return true ;
34
+ }
35
+ const bottomNavigationTab = owner . items [ item . tag ] ;
36
+ if ( ! bottomNavigationTab . isSelectable ) {
37
+ owner . _emitTabPressed ( item . tag ) ;
38
+ }
39
+
40
+ return bottomNavigationTab . isSelectable ;
41
+ } ,
42
+ } ,
43
+ {
44
+ protocols : [ MDCBottomNavigationBarDelegate ] ,
45
+ }
46
+ ) as typeof IBottomNavigationBarDelegate ;
47
+
40
48
export class BottomNavigationBar extends BottomNavigationBarBase {
41
49
nativeViewProtected : MDCBottomNavigationBar ;
42
50
_items : BottomNavigationTab [ ] ;
@@ -45,7 +53,7 @@ export class BottomNavigationBar extends BottomNavigationBarBase {
45
53
super ( ) ;
46
54
}
47
55
48
- private _delegate : BottomNavigationBarDelegate ;
56
+ private _delegate : IBottomNavigationBarDelegate ;
49
57
50
58
createNativeView ( ) : Object {
51
59
const view = MDCBottomNavigationBar . new ( ) ;
@@ -58,7 +66,8 @@ export class BottomNavigationBar extends BottomNavigationBarBase {
58
66
59
67
initNativeView ( ) : void {
60
68
super . initNativeView ( ) ;
61
- this . _delegate = BottomNavigationBarDelegate . initWithOwner ( new WeakRef ( this ) ) ;
69
+ this . _delegate = BottomNavigationBarDelegate . new ( ) ;
70
+ this . _delegate . _owner = new WeakRef ( this ) ;
62
71
this . nativeViewProtected . delegate = this . _delegate ;
63
72
// Create the tabs before setting the default values for each tab
64
73
// We call this method here to create the tabs defined in the xml
@@ -68,7 +77,7 @@ export class BottomNavigationBar extends BottomNavigationBarBase {
68
77
disposeNativeView ( ) {
69
78
this . nativeViewProtected . delegate = null ;
70
79
this . _delegate = null ;
71
- this . _items . forEach ( item => this . _removeView ( item ) ) ;
80
+ this . _items . forEach ( ( item ) => this . _removeView ( item ) ) ;
72
81
super . disposeNativeView ( ) ;
73
82
}
74
83
0 commit comments