-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: multiple modal on iOS #31498
fix: multiple modal on iOS #31498
Conversation
Base commit: 118489f |
Base commit: 606e145 |
@intergalacticspacehighway why this merge is blocked? |
@lfoliveir4 only collaborators can merge PR. |
@lucianomlima When you can review and dive into this PR, can you please let us know? |
Why this PR doesn't be merged? |
Hello @intergalacticspacehighway , i updated my app to your branch because i'm with the same issue, and your solution works, in some cases... When i already has a modal open and another modal will be opened, for example:
works fine, but if a have a flow of modals, not, when should open the second modal, the first modal close and second modal will not be visible for example:
I don't know if there is something about the way of your solution, because in the same time of Modal1 will be visible=false, Modal2 will be visible=true, i will keep investigating, but my knowledge in ObjetiveC is not good haha. Someone have any idea? |
@carloslibardo Thanks for testing this out. I tried to analyse the issue and I get this log on running your second example
I think it tries to open the second modal before the first one is completely dismissed and there's where it breaks. Changing the above code to something like below works.
I'll try to find a solution! |
@intergalacticspacehighway thanks for reply and keep trying to solve this problem =) I tried to use your second sample to solve my problem, using modal as children of modal, but doesn't works correctly, both modals being not visible =/ |
@intergalacticspacehighway some updates? |
any update on this? |
hi all , any update ? |
Sorry for the delay everyone, I just got a chance to analyse the issue. Here are some findings.
// Modal1's controller will be presented by reactViewController
<Modal1 />
// Modal2's controller will be presented by Modal1's controller
<Modal2 /> This is where it gets tricky, what if the This can be also a bit deceptive when looked at the code as it looks like they are independent but in reality, the last opened Modal is presenting the next Modal. (Need more thoughts). Also, I think multiple Modals most of the time are nested, and in that case, the existing or the above solution would work just fine. I think what we may need is not multiple modal controllers but something like mounting views in UIWindow. Something like this or RN's createPortal support which works on android and iOS. Let me know If I am missing something! :) |
@intergalacticspacehighway What problem are we facing for this PR to be merged? Many UI's use flows with multiple modals... This PR would make life easier for many engineers... Any updates on it? @shergin @mdvacca @JoshuaGross Could any of you contributors help us move this PR forward? If not, what's the best way to proceed with this PR? |
+`1 |
Unfortunately this PR can't be fix below case const positionStyle = [
{ top: 200, left: 200 },
{ top: 200, right: 200 },
{ bottom: 200, left: 200 },
{ bottom: 200, right: 200 },
]
const colors = ['red', 'purple', 'gray', 'orange']
const modals = [0, 1, 2, 3]
const App = () => {
const [visible, setVisible] = useState(0)
return (
<>
<View
style={{ height: '100%', width: '100%', justifyContent: 'center', alignItems: 'center' }}
>
<TouchableOpacity onPress={() => setVisible(v => (v + 1) % 5)}>
<Text>Press me</Text>
</TouchableOpacity>
</View>
{modals.map((_v, i) => (
<Modal isVisible={i + 1 === visible} key={i}>
<View
style={{
position: 'absolute',
justifyContent: 'center',
alignItems: 'center',
...positionStyle[i],
backgroundColor: colors[i],
}}
>
<TouchableOpacity onPress={() => setVisible(v => (v + 1) % 5)}>
<Text>Press me</Text>
</TouchableOpacity>
</View>
</Modal>
))}
</>
)
} The code above expects the old modal to disappear when the new one appears, |
Hi, guys, any progress? |
The patch below should work fine as long as you don't use animationType or transparent prop (like react-native-modal)
I think it's an unavoidable limitation of ReactNative that we can't display multiple Modal(ViewControllers) at once because iOS doesn't support it. Therefore, this patch may cause unintended dismiss behavior if you have a modal open and try to clear the first visible modal, and that modal uses an animationType prop of "slide", "fade", or leaves "transparent" set to true. I tested 4 cases
|
@carloslibardo i pushed a few changes to the PR. Can you try your usecase again? |
This is the most upvoted open PR on the repo, would be amazing to get multiple modals working. A bit crippling for app developoers trying to go all in on RN. |
Why this PR is yet to be merged ? |
This PR is included in the react-native-improved library: react-native-improved
Set-upIn package.json "scripts": {
+ "postinstall": "yarn run react-native-patch"
} Then npmnpm install react-native-improved --save-dev yarn v1yarn add react-native-improved --dev |
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
Still the most upvoted PR on the repo. |
pour one out |
This PR aims to resolve.
https://react-native.canny.io/feature-requests/p/multiple-modal-components
#3445
Summary
In order to open multiple modals at once, they need to be nested within a modal on iOS. To fix this issue, we mount each modal into a new UIWindow.
pageSheet
andformSheet
modal presentation styles are exceptions, they animate the behind view so it cannot be presented in a new window so we use the last presented controller for them to match native behavior.Changelog:
[iOS] [Fixed] - Multiple modals
Test Plan
Verified the existing and added functionality in the RN Tester app.