question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: Why default to full screen height instead of allowing dynamic height?

See original GitHub issue

Which OS ?

Both

Version

Which versions are you using:

  • react-native-swiper v1.6.0.rc
  • react-native v0.62.2

Problem / Question

In the implementation, it is setting the initial height state to window height if we do not provide a height prop to it.

In order to place the swiper perfectly, I would need to calculate the height and width of the content beforehand which is kind of unnecessary work.

Wouldn’t it be more flexible to not do anything with the initial height and let the container fit dynamically with the content? We can always control the dimension ourselves.

PS. If there’s a way to have dynamic height control already that I missed, please let me know thanks!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:8
  • Comments:5

github_iconTop GitHub Comments

7reactions
cardiohelgecommented, Aug 17, 2020

I build a workaround by using onLayout in the child views: (The largest child defines the height of the Swiper)

const [height, setHeight] = useState(100); // "minHeight" - can be smaller too

const handleSetHeight = (value) => {
  if (value > height) {
    setHeight(value);
  }
};

return (
  <Swiper ... style={{ height }}>
    {children.map((child) => (<View onLayout={(event) =>handleSetHeight(event.nativeEvent.layout.height)}>{child}</View>))}
  </Swiper>
);
2reactions
danielfx90commented, Jul 27, 2020

Anyone to answer this, please? It’s a great package, but setting hardcoded dimensions complicates everything.

Read more comments on GitHub >

github_iconTop Results From Across the Web

html - Make a div fill the height of the remaining screen space
So here, what am doing is, adding up the height of elements and than deducting from 100% using calc() function. Just make sure...
Read more >
HTML vs Body: How to Set Width and Height for Full Page Size
Yes, yes it does. The above style definition creates a problem: Setting min-height to 100% on both elements does not allow the body...
Read more >
How to give a div tag 100% height of the browser window ...
How to give a div tag 100% height of the browser window using CSS ... CSS allows to adjust the height of an...
Read more >
background-size - CSS: Cascading Style Sheets | MDN
The background-size CSS property sets the size of the element's background image. The image can be left to its natural size, stretched, ...
Read more >
Size and Lay Out Your Dashboard - Tableau Help
Fixed size dashboards let you specify the exact location and position of the ... Automatic: The dashboard automatically resizes to fill the window...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found