Skip to content
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

How to fill remaining height with View? #185

Closed
b-graves opened this issue Oct 18, 2023 · 3 comments
Closed

How to fill remaining height with View? #185

b-graves opened this issue Oct 18, 2023 · 3 comments

Comments

@b-graves
Copy link

b-graves commented Oct 18, 2023

Hi, I am struggling to create a simple header/content layout using the View utility.

I would like to have a View that fills the full screen height, then a header that is a fixed height, then the content fill the remaining space.

I thought something like this would work:

export const LayoutTestViews = () => (
  <View height="100vh">
    <ActionBar position="top">
      <Text>Header</Text>
    </ActionBar>
    <View grow backgroundColor="neutral-faded">
      <Text>Content</Text>
    </View>
  </View>
)

as the top View is 100vh then the inner content View will grow to fill the remaining height. However, the content View does not grow:

Screenshot 2023-10-18 at 11 42 38

I have re-written it using divs to create the effect I was expecting, with the same flex properties I thought would be applied by the View like this:

export const LayoutTestDivs = () => (
  <div
    style={{
      display: 'flex',
      flexDirection: 'column',
      height: '100vh',
    }}
  >
    <ActionBar position="top">
      <Text>Header</Text>
    </ActionBar>
    <div
      style={{
        flexGrow: 1,
        backgroundColor: 'var(--rs-color-background-neutral-faded)',
      }}
    >
      <Text>Content</Text>
    </div>
  </div>
)

and it works as expected:

Screenshot 2023-10-18 at 11 44 40

So I am a little unclear on what I am doing wrong when trying to use the View?

Thanks!!

@X86-7
Copy link

X86-7 commented Oct 18, 2023

Hey there, to clarify, you're trying to make the view assume the entirety of the page?

You need to use a property called View.Item grow

Try this with your original code and see if it works.

<View>
    <View.Item grow backgroundColor="neutral-faded">
      <Text>Content</Text>
    </View.Item>
</View>

@blvdmitry
Copy link
Contributor

That's a good point! Right now we're only turning on flexbox behaviour if one of the flex properties are used on View. I'll see how we can improve that, but meanwhile what you can do is apply align to the parent View for example:

https://codesandbox.io/s/goofy-sun-m5mt2y?file=/src/App.tsx

@blvdmitry blvdmitry moved this to 2.5.0 in Reshaped Oct 21, 2023
@blvdmitry
Copy link
Contributor

I've added auto detection for this use case as well. If you have a View that has a child View or View.Item with grow – it will automatically turn to flexbox to ensure the child grows as expected

@github-project-automation github-project-automation bot moved this from 2.5.0 to Waiting for the release in Reshaped Oct 21, 2023
@blvdmitry blvdmitry moved this from Waiting for the release to Recently completed in Reshaped Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Recently completed
Development

No branches or pull requests

3 participants