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

StackNavigator as formSheet content has size of zero (iOS)

Open arnekolja opened this issue 1 year ago • 19 comments

Description

After upgrading to react-navigation 7 and react-native-screens 4.2.0 my modal's content, a native stack navigator, isn't showing up any more. After some debugging I found out that it has a layout of zero width and zero height. Applying a wrapping <View /> with fixed width and height works, applying flex: 1 does not. However, a fixed height cannot be the solution for my flexible-height content. Using a normal view works fine and grows with its content, but not with the stack navigator.

This does only apply to presentation: 'formSheet' but not presentation: 'modal', despite the fact that at least on iOS (only tested on iOS) the resulting modal looks the same. presentation: 'modal' handles sizing of my stack navigator correctly.

Is presentation: 'formSheet' and presentation: 'modal' really the same UI element here? And how can I fix the layout/height of my content? It is definitely a change from 3.x to 4.x, as it worked on 3.x for a long time.

Steps to reproduce

Place a native stack navigator inside a modal of type 'formSheet'.

Snack or a link to a repository

https://snack.expo.dev/Pqu3Cikm2Pk84jev-qtF9

Screens version

4.2.0

React Native version

0.76.2

Platforms

iOS

JavaScript runtime

Hermes

Workflow

React Native (without Expo)

Architecture

Fabric (New Architecture)

Build type

Debug mode

Device

iOS simulator

Device model

iPhone 15 (iOS 17.2)

Acknowledgements

Yes

arnekolja avatar Nov 19 '24 23:11 arnekolja

Having the same issue.

colinchadwick avatar Nov 20 '24 07:11 colinchadwick

Same here flex: 1 just won't work, I ended up using fixed height, but definitely not happy with that solution.

bojandurmic avatar Nov 21 '24 01:11 bojandurmic

Are you using formSheet for its ability to specify detents or is modal presentation good replacement enough?

The formSheet presentation has changed with 4.0 (see here) and it is a bit impaired (but has other possibilities) at the moment. I'll try to handle this asap

kkafar avatar Nov 21 '24 13:11 kkafar

@kkafar Yes, the formSheet allows for better customization than the modal (for e.g. specifying detents, showing the grabber, corner radius, etc.).

colinchadwick avatar Nov 21 '24 14:11 colinchadwick

Then please make sure to read the release notes

kkafar avatar Nov 21 '24 14:11 kkafar

For my two use cases it is okay to fallback to 'modal'. I'm interested in the solution tho. But I'll keep a view on this ticket and re-read the release notes etc. Thanks for the response 🙌🏾

arnekolja avatar Nov 21 '24 14:11 arnekolja

I can't give promises on timelines but will prioritise fixing this up

kkafar avatar Nov 21 '24 14:11 kkafar

Thank you @kkafar for your effort and communication. We really appreciate it!

bojandurmic avatar Nov 21 '24 18:11 bojandurmic

Any news? I'm using modal as fallback right now, but here the modal strangely "deforms" while sliding up in iOS, messing up all the content, until it's settled. never had that with formSheet.

jgo80 avatar Dec 09 '24 10:12 jgo80

This issue still continues. Btw this is only happens when formSheet is initial screen. There is no problem in layout when you navigate from card screen to formSheet screen if they are in same stack.

Image

snndmnsz avatar Jan 16 '25 02:01 snndmnsz

Are there any updates on this?

hraschan avatar Jan 25 '25 00:01 hraschan

This seems to be working for me on iOS but I am experience the issue with Android simulators.

damiensedgwick avatar Jan 28 '25 10:01 damiensedgwick

Giving height: '100%' to contentStyle in your parent stack screen seems to work. I called my collection stack from the bottom tab stack. It works even if they are not in the same stack, you can call it from another stack, and it will still bring screen as formSheet. I tried giving flex: 1, but it did not work, it was still a blank screen. Just give it height: '100%'.

<Stack.Screen
      name="collection"
      options={{
          presentation: "formSheet",
          contentStyle:{
            height: '100%',
          },
          sheetCornerRadius: 20,
          sheetGrabberVisible: true,
       }}
   />

Image

snndmnsz avatar Feb 05 '25 20:02 snndmnsz

Giving height: '100%' to contentStyle in your parent stack screen seems to work. I called my collection stack from the bottom tab stack. It works even if they are not in the same stack, you can call it from another stack, and it will still bring screen as formSheet. I tried giving flex: 1, but it did not work, it was still a blank screen. Just give it height: '100%'.

<Stack.Screen name="collection" options={{ presentation: "formSheet", contentStyle:{ height: '100%', }, sheetCornerRadius: 20, sheetGrabberVisible: true, }} /> Image

This is a hacky fix at best, if you add a background color the sheet you'll see the animations are very laggy, you can just get away with it if your background doesn't change. If you have content fixed to the bottom it won't look good.

danieljvdm avatar Feb 25 '25 17:02 danieljvdm

Image

App crashing for Android when i add contentStyle:{height:'100%'}


      <Stack.Screen
        name="quickaccess"
        options={{
          headerShown: false,
          presentation: 'formSheet',
          sheetGrabberVisible: true,
          sheetCornerRadius: 20,
          contentStyle: {
            height: '100%',
          },
          sheetAllowedDetents: 'fitToContents',
        }}
      />

EDIT: fixed my issue by updating react-native-screens from 4.4.0 to 4.7.0

Raiden-16F7 avatar May 16 '25 14:05 Raiden-16F7

Giving height: '100%' to contentStyle in your parent stack screen seems to work. I called my collection stack from the bottom tab stack. It works even if they are not in the same stack, you can call it from another stack, and it will still bring screen as formSheet. I tried giving flex: 1, but it did not work, it was still a blank screen. Just give it height: '100%'.

<Stack.Screen name="collection" options={{ presentation: "formSheet", contentStyle:{ height: '100%', }, sheetCornerRadius: 20, sheetGrabberVisible: true, }} /> Image

This fix should be built in

Patrick-web avatar Jun 08 '25 14:06 Patrick-web

Hi, just reporting in that this still seems to be an issue on 4.11.1 and setting a contentStyle height of 100% does not play nicely with fitToContents when trying to implement small, navigatable popover sheets

kylealwyn avatar Jun 17 '25 05:06 kylealwyn

Does anyone have any solution for this I am facing the same issue.

galgord avatar Jun 23 '25 20:06 galgord

@kkafar Do you think it would be possible to take another look at this? I am happt to help reproduce if needed.

galgord avatar Jun 24 '25 01:06 galgord

I'm also facing the same issue!

sumersao avatar Aug 10 '25 03:08 sumersao

I believe I have found the issue....

After a stupid amount of time debugging this issue in our project. I found out if you remove the background colour from the main container view in the form-sheets page. It just works...

@sumersao @galgord

Bowlerr avatar Aug 19 '25 10:08 Bowlerr

I believe I have found the issue....

After a stupid amount of time debugging this issue in our project. I found out if you remove the background colour from the main container view in the form-sheets page. It just works...

@sumersao @galgord

I cannot confirm this. Neither my stacks nor their wrappers have a background color.

jgo80 avatar Aug 19 '25 10:08 jgo80

The page itself that is being loaded?

Bowlerr avatar Aug 19 '25 10:08 Bowlerr

@jgo80

Bowlerr avatar Aug 19 '25 10:08 Bowlerr

Like on that component itself.

Bowlerr avatar Aug 19 '25 10:08 Bowlerr

Setting a parent view with just flex 1 and nothing else solved this. It was odd but it was the background colour causing the issue for me

Bowlerr avatar Aug 19 '25 10:08 Bowlerr

Nope. Ally my parent views of the modal content are <View {...props} style={{flex:1}} />

jgo80 avatar Aug 19 '25 10:08 jgo80

Ah never mind, I hope you find the cause. The only other thing I'm doing is setting the background colour in the contentStyle for the sheet.

Thought I would share in case it solves it for y'all

Bowlerr avatar Aug 19 '25 11:08 Bowlerr

@kkafar this is blocking some nice, contextual experiences. hoping you can take another look. happy to pair. thank you.

kylealwyn avatar Sep 13 '25 16:09 kylealwyn

Any update on this one ? 👍

anckaertv avatar Sep 27 '25 09:09 anckaertv