callstack / callstack/react-native-paper
Menu component closes and fails to open again on re-render
- 主要语言
- TypeScript
- 星标
- 14.5k
- 派生
- 2.2k
- 平均合并
- 5 天 23 小时
- 30 天内合并 PR
- 12
描述
### Current behaviour
- Open the Menu component
- The parent component re-renders
- Menu component closes and can't be opened again
### Expected behaviour
- Open the Menu component
- The parent component re-renders
- Menu component stays open
### How to reproduce?
```TSX
import React, {useState} from 'react';
import {View} from 'react-native';
import {Button, Menu, PaperProvider} from 'react-native-paper';
const MyComponent = () => {
const [randomVarialbeToForceRerender, setRandomVarialbeToForceRerender] =
useState(0);
const [visible, setVisible] = useState(false);
const openMenu = () => {
console.debug('Opening menu');
setVisible(true);
/**
* We update a state variable to force a re-render of the component.
* A real-world example could be a network request or some other
* asynchronous operation that updates the state.
*/
setTimeout(() => setRandomVarialbeToForceRerender(Math.random()), 1000);
};
const closeMenu = () => {
setVisible(false);
console.debug('Closing menu');
};
console.debug('visible', visible);
return (
Show menu}>
{}}
title={`Random ${randomVarialbeToForceRerender}`}
/>
);
};
export default MyComponent;
```
### Preview
https://github.com/user-attachments/assets/3d995026-ab4e-4fd3-bbf3-5544164a63ec
### What have you tried so far?
Memoization to avoid re-rendering the menu. However, this approach is limited and breaks
when the menu items are non-static (c.f. example)
### Your Environment
| software | version
| --------------------- | -------
| ios | 18.5
| android | x
| react-native | 0.77.2
| react-native-paper | 5.13.1
| node | 18.20.8
| npm or yarn | 3.8.7
| expo sdk | x.x.x
贡献指南
调研方向
从 Menu 组件开始,使用 TypeScript 示例重现该问题:打开菜单,触发父组件重新渲染,然后尝试再次打开它。跟踪该重新渲染期间组件的状态和锚点行为;完成的标准是菜单保持打开,并且更新后仍然可以再次打开。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- react-native, typescript
- 领域
- mobile
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100