react-native icon indicating copy to clipboard operation
react-native copied to clipboard

feat(iOS): modal detents

Open hurali97 opened this issue 1 year ago • 15 comments

Summary

As proposed in this discussion, this PR introduces feature for iOS 15+ detents with fabric support. Kudos to @barthap for his wonderful gist which introduces the feature for paper. Additional work was done to introduce this feature for fabric.

We have three values for detents and the usage is like below:

<Modal 
  detent="mediumResizable" // medium, large, mediumResizable
  presentationStyle="formSheet" // can also try pageSheet
/>

Down the road when adding support for fabric, it occurred to me that onRequestClose is not implemented, which prevents the dismiss of formSheet or PageSheet when we drag it down. So, added the support for onRequestClose as well. I am not sure why this was left out for fabric, if it was intentional, it might worth a discussion.

Since we don't have detents for android AFAIK, an empty method setDetent implemented in ReactModalHostManager to confirm to the generated interface.

Thanks to @nandorojo for his POC with the above gist and a nice tweet showcasing the demo 🚀

Changelog

[iOS] [Added] - iOS 15 detents to Modal

Test Plan

This feature is tested on rn-tester with both old and new arch, below is the output:

https://user-images.githubusercontent.com/47336142/193402450-c9da9835-9ac4-48aa-a703-6a34d08572f5.mp4

Code for rn-tester is not committed to not bloat the PR. I may address it following the design principles of rn-tester in a couple of days, once this PR is merged.

TODO

  • Update documentation for detent on react-native website
  • Update code to implement detent in rn-tester

hurali97 avatar Oct 01 '22 09:10 hurali97

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,062,509 +426
android hermes armeabi-v7a 6,466,999 +290
android hermes x86 7,376,950 +272
android hermes x86_64 7,345,932 +458
android jsc arm64-v8a 8,919,615 +514
android jsc armeabi-v7a 7,685,963 +377
android jsc x86 8,869,166 +361
android jsc x86_64 9,460,069 +545

Base commit: 745f3ee8c571560406629bc7af3cf4914ef1b211 Branch: main

analysis-bot avatar Oct 01 '22 10:10 analysis-bot

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 745f3ee8c571560406629bc7af3cf4914ef1b211 Branch: main

analysis-bot avatar Oct 01 '22 11:10 analysis-bot

Thoughts on calling the prop detent without the word modal? Seems a bit obvious that the modal is part of it.

nandorojo avatar Oct 01 '22 12:10 nandorojo

Thoughts on calling the prop detent without the word modal? Seems a bit obvious that the modal is part of it.

Hmm. I tend to agree with keeping the prop name to detent, to match the parity with other props such as presentationStyle, animationType, etc. I will try to incorporate these changes asap. Thanks for the comment 🌟

hurali97 avatar Oct 03 '22 07:10 hurali97

Could you also rebase the PR on main? The ios errors should have been fixed now.

cipolleschi avatar Oct 04 '22 15:10 cipolleschi

@cipolleschi Thanks for the reviews, these are now incorporated. Would be great if you could re-review 🚀

I am not sure why CI fails on test_windows.

hurali97 avatar Oct 05 '22 08:10 hurali97

that's just a flaky test, unfortunately

cipolleschi avatar Oct 05 '22 09:10 cipolleschi

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Oct 05 '22 09:10 facebook-github-bot

Awesome seeing this approved so quickly, thanks @hurali97 & @cipolleschi!

nandorojo avatar Oct 06 '22 15:10 nandorojo

@cipolleschi Can you see what caused the Facebook Internal - Linter to fail? 🙂

hurali97 avatar Oct 11 '22 14:10 hurali97

There are some linting errors in the internal CI. The Clang format we use internally is slightly different from the Open Source one (we are working on their alignment but is not as easy as it looks, unfortunately). Don't worry too much about them: as soon as the PR is ok, I'll reimport it, fix the linting problems and land it! ;)

cipolleschi avatar Oct 18 '22 11:10 cipolleschi

There are some linting errors in the internal CI. The Clang format we use internally is slightly different from the Open Source one (we are working on their alignment but is not as easy as it looks, unfortunately). Don't worry too much about them: as soon as the PR is ok, I'll reimport it, fix the linting problems and land it! ;)

Perfect. I have added a few comments regarding your suggestions, would be great if you could discuss them.

hurali97 avatar Oct 18 '22 14:10 hurali97

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Oct 20 '22 17:10 facebook-github-bot

I'm going to run the internal formatter on the diff and then we can land it. Thank you so much for the effort and the PR!

cipolleschi avatar Oct 20 '22 17:10 cipolleschi

PR build artifact for 4ce436c6f571b5b442b599b83836d5096db58f38 is ready. To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

pull-bot avatar Oct 25 '22 18:10 pull-bot