react-native-reanimated-carousel icon indicating copy to clipboard operation
react-native-reanimated-carousel copied to clipboard

Layout issues in RN 0.74.2

Open udeyrishi opened this issue 1 year ago • 5 comments

Describe the bug

I'm noticing that the Carousel component is reporting its runtime height as 0 when using RN 0.74.2. When running in RN 0.73.6, the runtime height is being correctly computed as the actual height of the items rendered inside. This is causing any siblings rendered below the Carousel to overlap the carousel.

To Reproduce

I've created this barebones Expo Go repo that reproduces the issue: https://github.com/udeyrishi/carousel-bug-repro.

  • Checkout the tag rn-73 and run the app via npm run ios. This is running the sample in RN 0.73.6. See the barebones HomeScreen component entrypoint showing a Text rendered below the Carousel (as expected). Also notice the measured height logged in the console.
  • Now checkout the tag rn-74. It's the same application code, except that Expo version is upgraded to 51 (and with it RN to 0.74.2, and some other expo recommended upgrades). This time, the Text will overlap the Carousel, and measured height is logged as 0.
    • Make sure to re-install the dependencies with npm install and install the recommended Expo Go version when running npm run ios.

Expected behavior

The layout behaviour in RN 74 should be identical to RN 73.

Screenshots

In RN 0.73.6 In RN 0.74.2
image image

Versions (please complete the following information):

  • react: v18.2.0
  • react-native: v0.74.3
  • react-native-reanimated: v3.10.1
  • react-native-reanimated-carousel: v3.5.1
  • react-native-gesture-handler: v2.16.2

Smartphone (please complete the following information):

  • Device: iPhone SE 3 simulator
  • OS: iOS 17.5

udeyrishi avatar Jul 04 '24 20:07 udeyrishi

Hey @udeyrishi! 👋 I'm here to help you with any bugs, questions, or contributions while you wait for a human maintainer. Let's squash those bugs together!

To resolve the layout issue with the Carousel component in React Native 0.74.2, where it reports its runtime height as 0, you can explicitly set the height of the Carousel component using the height prop. This ensures that the component has a defined height and prevents sibling components from overlapping.

Here's an example of how you can modify the Carousel component usage to include the height prop:

import React from "react";
import { SafeAreaView, Text, useColorScheme, Dimensions, View } from "react-native";
import Carousel from "react-native-reanimated-carousel";

import { Colors } from "react-native/Libraries/NewAppScreen";

const { width: PAGE_WIDTH } = Dimensions.get("window");
const App = () => {
  const isDarkMode = useColorScheme() === "dark";

  const backgroundStyle = {
    backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
  };

  return (
    <SafeAreaView style={[backgroundStyle, { alignItems: "center", justifyContent: "center", flex: 1 }]}>
      <Carousel
        loop
        width={PAGE_WIDTH}
        height={PAGE_WIDTH / 2} // Set the desired height here
        data={[...new Array(6).keys()]}
        renderItem={({ index }) => (
          <View key={index} style={{ alignItems: "center", justifyContent: "center", flex: 1 }}>
            <Text>Hello</Text>
          </View>
        )}
      />
    </SafeAreaView>
  );
};

export default App;

By explicitly setting the height prop, you ensure that the Carousel component has a defined height, which should resolve the layout issue [1][2].

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Jul 04 '24 20:07 dosubot[bot]

^ This gen AI seems to be hallucinating. In the linked sample example, I'm setting the Carousel's height explicitly, and I'm still seeing the issue.

udeyrishi avatar Jul 04 '24 20:07 udeyrishi

You can embed a View around the Carousel component and adjust its height, but the height setting in baseOptions appears to have no effect.

liy010 avatar Jul 06 '24 23:07 liy010

Same issue here. @liy010's suggestion worked for me.

jadbarakat avatar Jul 16 '24 10:07 jadbarakat

#646 describes the same issue and workaround, and has an associated PR to fix it.

MedeaMelana avatar Aug 25 '24 17:08 MedeaMelana

Hi, @udeyrishi. I'm Dosu, and I'm helping the react-native-reanimated-carousel team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • The Carousel component in React Native 0.74.2 reports its runtime height as 0, causing layout issues.
  • You confirmed that setting the height explicitly did not resolve the issue.
  • Embedding the Carousel in a View and adjusting its height was suggested and confirmed as a working solution.
  • Issue #646 describes the same problem, and there is a pull request aimed at fixing it.

Next Steps:

  • Please let me know if this issue is still relevant to the latest version of the react-native-reanimated-carousel repository. If so, you can keep the discussion open by commenting on this issue.
  • Otherwise, I will automatically close this issue in 7 days.

Thank you for your understanding and contribution!

dosubot[bot] avatar Feb 20 '25 16:02 dosubot[bot]