-
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
Send Modal onDismiss event on iOS (Fabric) and Android #42014
Conversation
This PR is identical to #38336. I closed #38336 and was planning to split it into smaller parts, but I found it's not possible to split. I also hope the new PR will attract more attention since the old one has been stale for a few months. (btw, the old PR fork is deleted) |
Base commit: e2fb88e |
label="onDismiss ⚫️" | ||
disabled={Platform.OS !== 'ios'} | ||
label="onDismiss" | ||
multiSelect={true} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why multiselect must be set to true
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's to enable RNTOption
react-native/packages/rn-tester/js/components/RNTOption.js
Lines 40 to 44 in b507e11
disabled={ | |
props.disabled === false || props.multiSelect === true | |
? false | |
: props.selected | |
} |
I see that onShow
passes multiSelect={true}
instead of disable={false}
, so I follow it.
react-native/packages/rn-tester/js/examples/Modal/ModalPresentation.js
Lines 186 to 190 in b507e11
<RNTOption | |
key="onShow" | |
style={styles.option} | |
label="onShow" | |
multiSelect={true} |
Do you think I should change it to disable={false}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, probably it is more clear and accurate. I think that multiSelect
is the API that allows you to select multiple choices (e.g.: "Which ice cream flavour do you prefer?" you can reply with "Chocolate", "cream" and "vanilla" and leave "strawberry" out) but in our case is is true/false and it does not make sense to select both.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that multiSelect is the API that allows you to select multiple choices
This is what I thought when saw it the first time and I totally agree using disabled
makes more sense. Updated the code.
...-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostManager.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It generally looks good to me. I also love that you removed more code than you added and the overall logic looks simpler to me.
Great job! 👏
/rebase - this comment automatically rebase the PR on top of main. |
fe01468
to
8334aae
Compare
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Quick update on this PR. The changes implemented here are making several internal jobs fail with our CI. This is a change we do want, but it will require a little bit more work on our side to make it happen. How urgent is this for you? Is it blocking your workflow? |
@cipolleschi thanks for the update. It's not an urgent one nor blocking any workflow. |
if (this._eventSubscription) { | ||
this._eventSubscription.remove(); | ||
componentDidUpdate(prevProps: Props) { | ||
if (prevProps.visible !== true && this.props.visible === true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of `isRendering?
isRendering is mapped to value of visible
prop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isRendering
is being used to keep the Modal rendered until the onDismiss
callback is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the parent component unmounts Modal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, onDismiss
won't be called.
@cipolleschi merged this pull request in 314cfa8. |
This pull request has been reverted by a58ec07. |
@cipolleschi hi, I see that the PR has been reverted. May I know why it was reverted and is there anything I can do to help? Thanks! |
Hi there, I was about to write. One of the problems is that the change was quite big (changing both platforms, changing public APIs, ...). This kind of changes are always a little risky as the more code we change the higher the probability of something to go wrong. What we can do to make it easier for these changes to stick would be to split this PR in smaller chunks and to try and not change the public APIs. |
@cipolleschi hi, hope you are doing well. I would like to know if Is there any update on the split plan. From me, I'm thinking that perhaps we can add a new props called The native component itself will fire For the split part,
What do you think? |
@cipolleschi hi, do you have any updates? |
Hi @bernhardoj, sorry for the late reply, but I was quite busy with other high priority stuff and I had little to no time to look into this. For iOS, I think everything is done now:
The problem, as you might expect, comes with Android.
There are 2 stepswe can pursue:
This will unblock both you and the app while the discussion proceeds. How does that sound like? |
Last time I tested, the
But I think we should remove the old EventEmitter otherwise there will be double
We actually use |
What I meant is that, after your diff landed, and got reverted, I split the iOS part and manage to get it landed. So, the iOS side is done and it works as you (almost) did with your diff.
No, because The New Architecture does not use the old event emitter and the Old Architecture don't use the event which is Fabric only.
Yeah, that can work too! Patch-packages is a better temporary solution than forking react-native. |
Ah, I see, thanks for clarifying it. I will discuss this with the team first. Thanks for your help! |
Summary:
Currently, the onDismiss is emitted using a device event as a workaround to the RCTModalHostView unable to receive the component event as it's already unmounted when visible is false.
This PR removes the workaround and keeps RCTModalHostView mounted until the onDismiss event is emitted from the host and sends the onDismiss event on Android.
Changelog:
[ANDROID] [ADDED] - Added support for Modal onDismiss prop
[IOS] [FIXED] - Fix onDismiss is not working on Fabric
Test Plan:
Screen.Recording.2023-12-20.at.23.55.29.mov