Skip to content

Commit

Permalink
Only render the host Modal component if rendered
Browse files Browse the repository at this point in the history
Summary:
Checking for `this.props.visible` is redundant, since the state machine goes as follows:
1. Props are initialized as visible (or not)
2. If initialized as visible, isRendered is initialized to true as well
3. If initialized with visible is false, isRendered is initialized to false.
4. When visible changes from false to true, isRendered is set to true
5. isRendered is only reset to false when the native dismiss operation is complete.

So in all cases, the `isRendered` prop follows the value set by `visible`, and is only reset to false after being dismissed, so only checking the `state.isRendered` value is effectively the same behavior.

## Changelog

[Internal]

Differential Revision: D66772150
  • Loading branch information
rozele authored and facebook-github-bot committed Dec 4, 2024
1 parent 734730d commit be254d7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/react-native/Libraries/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class Modal extends React.Component<Props, State> {
// Helper function to encapsulate platform specific logic to show or not the Modal.
_shouldShowModal(): boolean {
if (Platform.OS === 'ios') {
return this.props.visible === true || this.state.isRendered === true;
return this.state.isRendered === true;
}

return this.props.visible === true;
Expand Down

0 comments on commit be254d7

Please sign in to comment.