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

parallax mode, loss of precision during arethmatic conversion #741

Closed
icarus-00 opened this issue Dec 9, 2024 · 2 comments
Closed

parallax mode, loss of precision during arethmatic conversion #741

icarus-00 opened this issue Dec 9, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@icarus-00
Copy link

Describe the bug
currently i am using expo sdk52 after bumping up my project from 51 to 52 and using the new architecture the error "Loss of precision during arithmetic conversion" kept occurring i traced the issue to a component using the carousel with parallax mode

import React, { useState, useEffect } from "react";
import { View, Image, StyleSheet, Dimensions } from "react-native";
import Animated, { useSharedValue } from "react-native-reanimated";
import Carousel from "react-native-reanimated-carousel";

const { width, height } = Dimensions.get("window");

const AdCarousel = () => {
  const images = [
    require("@/assets/defaulBannerAd/banner 45 ad 1.png"),
    require("@/assets/defaulBannerAd/banner 45 ad 2.png"),
    require("@/assets/defaulBannerAd/banner 45 ad 3.png"),
  ];

  const [activeIndex, setActiveIndex] = useState(0);
  const progress = useSharedValue(0);

  const carouselWidth = width;
  const carouselHeight = width / 2;

  return (
    <View style={styles.container}>
      <Carousel
        mode="parallax"
        loop
        width={carouselWidth}
        height={carouselHeight}
        autoPlay={true}
        data={images}
        scrollAnimationDuration={1000}
        onProgressChange={(_, absoluteProgress) => {
          progress.value = absoluteProgress;
        }}
        autoPlayInterval={5000}
        renderItem={({ item }) => (
          <View style={styles.imageContainer}>
            <Image
              source={item}
              style={[
                styles.image,
                {
                  width: carouselWidth,
                  height: carouselHeight,
                },
              ]}
              resizeMode="cover"
            />
          </View>
        )}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    width: "100%",
    alignItems: "center",
    justifyContent: "center",
  },
  imageContainer: {
    width: "100%",
    alignItems: "center",
    justifyContent: "center",
  },
  image: {
    borderRadius: 10,
  },
});

export default AdCarousel;

//excuse my horrible looking code

To Reproduce

  1. initialize new expo project with the latest sdk and new arch enabled
  2. install react-native-carousel using npx expo install react-native-carousel
  3. make two components, one with parallax mode and one without

Expected behavior
using the carousel component in normal mode doesn't cause any issue, and in expo51 using any mode didn't cause any issues
i didn't test turning off the new arch, but i'll try that and comment on the issue

Screenshots
image
that's the only screenshot i can provide, the other one is of my app with the carousel having no parallax effect

Versions (please complete the following information):

  • "react": "18.3.1"
  • "react-native": "0.76.3"
  • "react-native-gesture-handler": "~2.20.2"
  • "react-native-reanimated": "~3.16.1"
  • "react-native-reanimated-carousel": "^3.5.1"

Smartphone (please complete the following information):

  • Device: using xiaomi redmi note 10 and iphone 11 pro
  • OS: android 13 and iOS 18

Additional context
Add any other context about the problem here.

@icarus-00 icarus-00 added the bug Something isn't working label Dec 9, 2024
Copy link

dosubot bot commented Dec 9, 2024

Hey there, @icarus-00! I'm here to help you out with any bugs, questions, or contributions you might have. Let's tackle this together!

There is a similar issue that was reported and resolved regarding the "Loss of precision during arithmetic conversion" error when using the parallax mode in the react-native-reanimated-carousel component. The issue was closed by a pull request that addressed the problem with the parallax layout when the new architecture was enabled. You can find more details about the issue and the solution in this closed issue and the corresponding pull request.

To resolve the error, you can ensure that any arithmetic operations involving floating-point numbers are correctly handled before casting to a long. In JavaScript, using Math.round can help avoid precision loss. Additionally, make sure your babel.config.js includes the react-native-reanimated/plugin to ensure proper configuration with Expo [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@icarus-00
Copy link
Author

using v4.0.0-canary.22 that had the did indeed fix the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants