Commit 4d044da
authored
feat(iOS): add pageSheet presentation for native-stack (#2793)
## Description
Adds new presentation for Native Stack - `pageSheet`
(`UIModalPresentationPageSheet` modal style on iOS, `modal` on Android).
Since the release of iOS 18, screens with `stackPresentation: 'modal'`
changed size on devices with a bigger screen, such as an iPad - they
became much smaller, which impacted applications of the library's users
(see issue
#2549).
This happens because `UIModalPresentationAutomatic`, which is used by
`react-native-screens` for `modal` on iOS, has been changed with the
release of iOS 18. `UIModalPresentationAutomatic` is now mapped to
`UIModalPresentationFormSheet` for iOS >=18 and
`UIModalPresentationPageSheet` for earlier versions (this was the
default before).
~~Apple added SwiftUI API
[(link)](https://developer.apple.com/documentation/swiftui/presentationsizing)
to allow to choose the behavior of the modal (`form`, `page`, `fitted`
or a custom one) but I wasn't able to find an equivalent functionality
in UIKit.~~ It turns out there is a new property in
`UISheetPresentationController`, see
[here](#2793 (review))
We considered 3 possible solutions to this problem:
- changing modal presentation style on iOS from
`UIModalPresentationAutomatic` to `UIModalPresentationPageSheet` for
`stackPresentation: 'modal'` to bring back old behavior for all modals:
- some users might've already designed their apps with the smaller sheet
in mind so changing the style might break their apps,
- adding a feature flag that would allow users to choose whether screens
with `stackPresentation: 'modal'` should use
`UIModalPresentationAutomatic` or `UIModalPresentationPageSheet`
- this solution would provide the easiest fix for the users impacted by
the change,
- even though 2 different sheet sizes would be available, users would
need to choose only one of them for their application,
- adding a new `stackPresentation` that would use
`UIModalPresentationPageSheet` on iOS and a regular `modal` on Android:
- users can choose whether they want to use `Automatic` or `PageSheet`
behavior per-screen basis,
- hopefully, fixing old applications with some find-and-replace magic
won't be difficult.
We decided on the third option.
tvOS does not allow `UIModalPresentationPageSheet` so it fallbacks to
`UIModalPresentationFullScreen` (the same behavior as
`UIModalPresentationAutomatic`).
This change will require changes to `react-navigation/native-stack` as
well.
Resolves
#2549.
## Changes
- add support for the new presentation in native and JS code
- add `pageSheet` examples in `Stack Presentation` and `Modals` example
screens
## Screenshots / GIFs
### `modal`

### `pageSheet`

## Test code and steps to reproduce
Open `Stack Presentation`, `Modals` example screens and open `pageSheet`
(at the moment, you might need to manually add `pageSheet` in
react-navigation files `packages/native-stack/src`,
`packages/native-stack/src/utils/getModalRoutesKeys.ts`,
`packages/native-stack/src/views`).
## Checklist
- [x] Included code example that can be used to test this change
- [x] Updated TS types
- [x] Updated documentation: <!-- For adding new props to native-stack
-->
- [x]
https://github.com/software-mansion/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md
- [x]
https://github.com/software-mansion/react-native-screens/blob/main/native-stack/README.md
- [x]
https://github.com/software-mansion/react-native-screens/blob/main/src/types.tsx
- [x]
https://github.com/software-mansion/react-native-screens/blob/main/src/native-stack/types.tsx
- [ ] Ensured that CI passes1 parent cc73b18 commit 4d044da
13 files changed
Lines changed: 70 additions & 6 deletions
File tree
- android/src/main/java/com/swmansion/rnscreens
- apps/src/screens
- guides
- ios
- native-stack
- src
- fabric
- native-stack
- utils
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
33 | 38 | | |
34 | 39 | | |
35 | 40 | | |
| |||
50 | 55 | | |
51 | 56 | | |
52 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
53 | 62 | | |
54 | 63 | | |
55 | 64 | | |
| |||
81 | 90 | | |
82 | 91 | | |
83 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
84 | 98 | | |
85 | 99 | | |
86 | 100 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
65 | 71 | | |
66 | 72 | | |
67 | 73 | | |
| |||
123 | 129 | | |
124 | 130 | | |
125 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
126 | 148 | | |
127 | 149 | | |
128 | 150 | | |
| |||
204 | 226 | | |
205 | 227 | | |
206 | 228 | | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
207 | 234 | | |
208 | 235 | | |
209 | 236 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
| 245 | + | |
245 | 246 | | |
246 | 247 | | |
247 | 248 | | |
| |||
253 | 254 | | |
254 | 255 | | |
255 | 256 | | |
| 257 | + | |
256 | 258 | | |
257 | 259 | | |
258 | 260 | | |
259 | 261 | | |
260 | 262 | | |
261 | 263 | | |
262 | | - | |
| 264 | + | |
263 | 265 | | |
264 | 266 | | |
265 | 267 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
| 53 | + | |
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
263 | 272 | | |
264 | 273 | | |
265 | 274 | | |
| |||
2036 | 2045 | | |
2037 | 2046 | | |
2038 | 2047 | | |
| 2048 | + | |
2039 | 2049 | | |
2040 | 2050 | | |
2041 | 2051 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
350 | 350 | | |
351 | 351 | | |
352 | 352 | | |
| 353 | + | |
353 | 354 | | |
354 | 355 | | |
355 | 356 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
0 commit comments