Both
Which versions are you using:
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!
Anyone to answer this, please? It's a great package, but setting hardcoded dimensions complicates everything.
Anyone to answer this, please? It's a great package, but setting hardcoded dimensions complicates everything.
Same here 😂
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>
);
@cardiohelge its a good workaround, but for dynamic data inside a slide is a big problem when has a many slides with dynamic data inside.
Most helpful comment
I build a workaround by using onLayout in the child views: (The largest child defines the height of the Swiper)