Commit 2ba25663 authored by Lorenzo Trujillo Rojas's avatar Lorenzo Trujillo Rojas
Browse files

[FIX] Se refactorizó el carrusel para hacer mas sencillo los imports en los...

[FIX] Se refactorizó el carrusel para hacer mas sencillo los imports en los archivos y prevenir dependencias circulares
parent a0100bf2
Loading
Loading
Loading
Loading
+61 −54
Original line number Diff line number Diff line
import { View, Animated, Text, Dimensions, Image, NativeSyntheticEvent, NativeScrollEvent } from "react-native";
import {
  View,
  Animated,
  Text,
  Dimensions,
  Image,
  NativeSyntheticEvent,
  NativeScrollEvent,
} from "react-native";
import { PlaceInfoEntity } from "../../../domain/entities/place_info_entity";
import { useRef } from "react";
import { StateDataSource } from "../../../domain/datasources/state_datasource";
import { CarousselTile } from "./caroussel_tile";
import { router } from "expo-router";
import { BLANK_ITEM_WIDTH, ITEM_WIDTH } from "../../constants/caroussel";

interface CarousselProps {
  data: PlaceInfoEntity[];
@@ -11,9 +20,6 @@ interface CarousselProps {
  onIndexChange?: (index: number) => void;
}

const ITEM_WIDTH = Dimensions.get("window").width * 0.7;
const BLANK_ITEM_WIDTH = Dimensions.get("window").width * 0.15;

export const Caroussel = ({ data, onPress, onIndexChange }: CarousselProps) => {
  const scrollX = useRef(new Animated.Value(0)).current;
  const finalData = [
@@ -43,12 +49,14 @@ export const Caroussel = ({ data, onPress, onIndexChange }: CarousselProps) => {
        showsHorizontalScrollIndicator={false}
        decelerationRate={0}
        initialNumToRender={1}

        bounces={false}
        snapToInterval={ITEM_WIDTH}
      onScroll={Animated.event([{ nativeEvent: { contentOffset: { x: scrollX } } }], {
        onScroll={Animated.event(
          [{ nativeEvent: { contentOffset: { x: scrollX } } }],
          {
            useNativeDriver: true,
      })}
          }
        )}
        renderItem={({ item, index }) => {
          if (item.id === -1 || item.id === -2) {
            return <View style={{ width: BLANK_ITEM_WIDTH }} />;
@@ -82,8 +90,7 @@ export const Caroussel = ({ data, onPress, onIndexChange }: CarousselProps) => {
                if (item.id !== -1 && item.id !== -2) {
                  onPress && onPress(item.id);
                }
            }
            }
              }}
            />
          );
        }}
+1 −4
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ import {
} from "react-native";
import { PlaceInfoEntity } from "../../../domain/entities/place_info_entity";
import { Link } from "expo-router";
import { ITEM_HEIGHT, ITEM_WIDTH } from "../../constants/caroussel";

interface CarousselTileProps {
  onPress?: () => void;
@@ -18,10 +19,6 @@ interface CarousselTileProps {
  opacity: Animated.AnimatedInterpolation<number>;
}

const ITEM_WIDTH = Dimensions.get("window").width * 0.7;
const BLANK_ITEM_WIDTH = Dimensions.get("window").width * 0.15;
const ITEM_HEIGHT = Dimensions.get("window").height * 0.7;

export const CarousselTile = memo(
  ({ translateY, scale, opacity, item, onPress }: CarousselTileProps) => {
    return (
+7 −0
Original line number Diff line number Diff line
import { Dimensions } from "react-native";

export const CARROUSEL_HEIGHT = Dimensions.get("window").height * 0.5;
export const CARROUSEL_WIDTH = Dimensions.get("window").width;
export const ITEM_WIDTH = CARROUSEL_WIDTH * 0.8;
export const BLANK_ITEM_WIDTH = CARROUSEL_WIDTH * 0.1;
export const ITEM_HEIGHT = CARROUSEL_HEIGHT * 0.7;
 No newline at end of file