mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
fix(bottom-navigation): crash when tab selected with no item (#7527)
This commit is contained in:

committed by
GitHub

parent
59575514ad
commit
46c17ca3a4
@ -216,8 +216,9 @@ public class BottomNavigationBar extends LinearLayout {
|
||||
lp.weight = 1;
|
||||
}
|
||||
|
||||
public void onTap(int position) {
|
||||
public boolean onTap(int position) {
|
||||
// to be overridden in JS
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onSelectedPositionChange(int position, int prevPosition) {
|
||||
@ -269,8 +270,9 @@ public class BottomNavigationBar extends LinearLayout {
|
||||
public void onClick(View v) {
|
||||
for (int i = 0; i < mTabStrip.getChildCount(); i++) {
|
||||
if (v == mTabStrip.getChildAt(i)) {
|
||||
onTap(i);
|
||||
setSelectedPosition(i);
|
||||
if (onTap(i)) {
|
||||
setSelectedPosition(i);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -301,8 +301,9 @@ public class TabLayout extends HorizontalScrollView {
|
||||
}
|
||||
}
|
||||
|
||||
public void onTap(int position) {
|
||||
public boolean onTap(int position) {
|
||||
// to be overridden in JS
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onSelectedPositionChange(int position, int prevPosition) {
|
||||
@ -429,8 +430,9 @@ public class TabLayout extends HorizontalScrollView {
|
||||
public void onClick(View v) {
|
||||
for (int i = 0; i < mTabStrip.getChildCount(); i++) {
|
||||
if (v == mTabStrip.getChildAt(i)) {
|
||||
onTap(i);
|
||||
mViewPager.setCurrentItem(i);
|
||||
if (onTap(i)) {
|
||||
mViewPager.setCurrentItem(i);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -118,10 +118,10 @@ function initializeNativeClasses() {
|
||||
owner.selectedIndex = position;
|
||||
}
|
||||
|
||||
public onTap(position: number): void {
|
||||
public onTap(position: number): boolean {
|
||||
const owner = this.owner;
|
||||
if (!owner) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
const tabStripItems = owner.tabStrip && owner.tabStrip.items;
|
||||
@ -129,6 +129,12 @@ function initializeNativeClasses() {
|
||||
if (position >= 0 && tabStripItems[position]) {
|
||||
tabStripItems[position]._emit(TabStripItem.tapEvent);
|
||||
}
|
||||
|
||||
if (!owner.items[position]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -259,10 +259,10 @@ function initializeNativeClasses() {
|
||||
}
|
||||
}
|
||||
|
||||
public onTap(position: number): void {
|
||||
public onTap(position: number): boolean {
|
||||
const owner = this.owner;
|
||||
if (!owner) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
const tabStripItems = owner.tabStrip && owner.tabStrip.items;
|
||||
@ -270,6 +270,12 @@ function initializeNativeClasses() {
|
||||
if (position >= 0 && tabStripItems[position]) {
|
||||
tabStripItems[position]._emit(TabStripItem.tapEvent);
|
||||
}
|
||||
|
||||
if (!owner.items[position]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -410,7 +410,7 @@
|
||||
setTabTextFontSize(fontSize: number): void;
|
||||
getTabTextFontSize(): number;
|
||||
|
||||
onTap(position: number): void;
|
||||
onTap(position: number): boolean;
|
||||
onSelectedPositionChange(position: number, prevPosition: number): void ;
|
||||
setSelectedPosition(position: number): void;
|
||||
setItems(items: Array<TabItemSpec>): void;
|
||||
|
Reference in New Issue
Block a user