mirror of
https://github.com/zhigang1992/react-native-paper.git
synced 2026-06-13 09:34:40 +08:00
fix: ref set to null on updates (#410)
The ref function is called twice on updates (see https://reactjs.org/docs/refs-and-the-dom.html#caveats-with-callback-refs). This behaviour causes the variable `this._manager` sometimes to be null during rendering and in that case actions are pushed to the queue again. Since the queue is only processed once (during componentDidMount), somes changes will never be visible. The simple solution is to bind the ref-function as mentioned in the link above. Dynamically change `visible` parameter of Modal. The Modal won't be visible on the second time.
This commit is contained in:
committed by
Satyajit Sahoo
parent
81a5e411e7
commit
db09ad4aeb
@@ -89,6 +89,10 @@ export default class PortalHost extends React.Component<Props> {
|
||||
}
|
||||
};
|
||||
|
||||
_setManager = (manager: ?Object) => {
|
||||
this._manager = manager;
|
||||
};
|
||||
|
||||
_nextKey = 0;
|
||||
_queue: Operation[] = [];
|
||||
_manager: ?PortalManager;
|
||||
@@ -103,11 +107,7 @@ export default class PortalHost extends React.Component<Props> {
|
||||
}}
|
||||
>
|
||||
{this.props.children}
|
||||
<PortalManager
|
||||
ref={c => {
|
||||
this._manager = c;
|
||||
}}
|
||||
/>
|
||||
<PortalManager ref={this._setManager} />
|
||||
</PortalContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user