Skip to content

Commit f645d5f

Browse files
committed
fix(ios): esm compatible
1 parent d18d90c commit f645d5f

File tree

9 files changed

+1050
-976
lines changed

9 files changed

+1050
-976
lines changed

src/bottomnavigationbar/bottomnavigationbar.ios.ts

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,45 @@ import { getRippleColor, themer } from 'nativescript-material-core/core';
66

77
import { activeColorCssProperty, BottomNavigationBarBase, BottomNavigationTabBase, inactiveColorCssProperty, tabsProperty, titleVisibilityProperty } from './bottomnavigationbar-common';
88

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>;
3812
}
3913

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+
4048
export class BottomNavigationBar extends BottomNavigationBarBase {
4149
nativeViewProtected: MDCBottomNavigationBar;
4250
_items: BottomNavigationTab[];
@@ -45,7 +53,7 @@ export class BottomNavigationBar extends BottomNavigationBarBase {
4553
super();
4654
}
4755

48-
private _delegate: BottomNavigationBarDelegate;
56+
private _delegate: IBottomNavigationBarDelegate;
4957

5058
createNativeView(): Object {
5159
const view = MDCBottomNavigationBar.new();
@@ -58,7 +66,8 @@ export class BottomNavigationBar extends BottomNavigationBarBase {
5866

5967
initNativeView(): void {
6068
super.initNativeView();
61-
this._delegate = BottomNavigationBarDelegate.initWithOwner(new WeakRef(this));
69+
this._delegate = BottomNavigationBarDelegate.new();
70+
this._delegate._owner = new WeakRef(this);
6271
this.nativeViewProtected.delegate = this._delegate;
6372
// Create the tabs before setting the default values for each tab
6473
// We call this method here to create the tabs defined in the xml
@@ -68,7 +77,7 @@ export class BottomNavigationBar extends BottomNavigationBarBase {
6877
disposeNativeView() {
6978
this.nativeViewProtected.delegate = null;
7079
this._delegate = null;
71-
this._items.forEach(item => this._removeView(item));
80+
this._items.forEach((item) => this._removeView(item));
7281
super.disposeNativeView();
7382
}
7483

0 commit comments

Comments
 (0)