从react-navigation动态地删除一个抽屉项

时间:2019-04-05 13:08:42

标签: reactjs react-navigation

我正在使用react-navigation(2.18.2),并已指定一个contentComponent来具有自定义抽屉组件。

在此自定义抽屉中,如果某个抽屉项符合特定条件,则需要将其删除(在我的示例中,无论如何我都将其中一个抽屉项移除)。可以正确地(从视觉上)删除抽屉项,但是当我点击一个抽屉项时,它导航到我点击的索引+ 1,就好像菜单项没有在其他位置被删除。

Row

然后Drawer组件看起来像这样。

Cell theCell = null;

//find the row that matches the rowNumber we're after
Row row = wsPart.Worksheet.Descendants<Row>().Where(r => r.RowIndex == rowIndex).FirstOrDefault();

if (row != null)
{
    //now grab the last cell of that row
    theCell = row.Descendants<Cell>().LastOrDefault();
}

// If the cell does not exist, return an empty string.
if (theCell != null)
...

由于我现在已删除了抽屉项目B,因此只有三个显示(A,C和D)。但是-当我现在点击抽屉项目C时,它将打开抽屉项目D。我可以轻按一下drawerItemA,它工作正常,但是对于其余部分,它将始终打开菜单下一个屏幕,而不是我尝试访问的屏幕。

任何有关如何实现此工作的想法将不胜感激。

1 个答案:

答案 0 :(得分:0)

我相信您可能想使用Array.filter来过滤项目数组:

  get drawerItems () {
    const { items } = this.props
    const filteredItems = items.filter(
      item => item.key !== 'drawerItemB'
    )
    return <DrawerItems items={filteredItems} {...rest}>
  }