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

borderTopStartRadius causes unexpected changes in all images rendered using the Image component #48626

Closed
Muntader opened this issue Jan 12, 2025 · 5 comments
Labels
Component: Image Needs: Attention Issues where the author has responded to feedback. Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Newer Patch Available Resolution: Answered When the issue is resolved with a simple answer

Comments

@Muntader
Copy link

Muntader commented Jan 12, 2025

Description

When applying a borderTopStartRadius to the Image component style, it appears to affect the width and height of all images, causing them to stretch or shrink incorrectly. This issue occurs regardless of the specified dimensions or aspect ratio in the styles.

My component:

import React, {useState, memo} from 'react';
import {View, Text, StyleSheet, FlatList, Dimensions, Pressable, Image} from 'react-native';
import FastImage from 'react-native-fast-image';
import imageLoader from '../../utils/ImageLoader.ts';
import {ParamListBase, useNavigation} from '@react-navigation/native';
import {NativeStackNavigationProp} from '@react-navigation/native-stack';

// Get screen width for responsive card sizing
const { width: SCREEN_WIDTH } = Dimensions.get('window');
const CARD_WIDTH = SCREEN_WIDTH * 0.20; // Each card takes up ~28% of the screen width
const NEXT_CARD_OFFSET = SCREEN_WIDTH * 0.05; // 0.2 of the next card

// @ts-ignore
const CastCard = memo(({ image, name, role }) => {
  const [imageUri, setImageUri] = useState(
    image
      ? { uri: imageLoader(image, 240, 75), priority: FastImage.priority.high }
      : require('../../assets/person.png') // Default to local fallback image
  );

  return (
    <View style={[styles.card, { width: CARD_WIDTH }]}>
      <Image
        source={imageUri}
        style={styles.image}
        onError={() => setImageUri(require('../../assets/person.png'))} // Load local fallback image on error
      />
      <View style={styles.info}>
        <Text style={styles.name} numberOfLines={1}>
          {name}
        </Text>
        <Text style={styles.role} numberOfLines={1}>
          {role}
        </Text>
      </View>
    </View>
  );
});

// @ts-ignore
const ContentCastsList = ({ casts }) => {
  const navigation = useNavigation<NativeStackNavigationProp<ParamListBase>>();

  return (
    <FlatList
      data={casts}
      keyExtractor={(item) => item.cast_id.toString()}
      renderItem={({ item }) => (
        <Pressable onPress={() => navigation.navigate('CastScreen', {screenTitle: item.cast_name, cast_id: item.cast_id})}>
          <View style={styles.cardContainer}>
            <CastCard
              image={item.cast_profile_path}
              name={item.cast_name}
              role={item.cast_department}
            />
          </View>
        </Pressable>
      )}
      horizontal
      showsHorizontalScrollIndicator={false}
      snapToInterval={CARD_WIDTH + NEXT_CARD_OFFSET} // Snap to cards
      decelerationRate="fast"
    />
  );
};

const styles = StyleSheet.create({
  cardContainer: {
    marginRight: 10,
  },
  card: {
    backgroundColor: '#333',
    borderRadius: 10,
    overflow: 'hidden',
    alignItems: 'center',
    elevation: 3,
    shadowColor: '#000',
    shadowOpacity: 0.2,
    shadowRadius: 3,
    shadowOffset: { width: 0, height: 2 },
  },
  image: {
    width: '100%',
    height: CARD_WIDTH * 1.1,
    borderRadius: 10,
    borderTopStartRadius: 4, // When remove this, it will fix the issues !!!!!
  },
  info: {
    padding: 2,
    paddingVertical: 6,
    alignItems: 'center',
  },
  name: {
    fontSize: 9,
    color: '#FFF',
    fontWeight: 'bold',
    marginBottom: 5,
    textAlign: 'center',
  },
  role: {
    fontSize: 7,
    color: '#CCC',
  },
});

export default ContentCastsList;

Steps to reproduce

When rendering the first image with borderTopStartRadius in its style and navigating to another screen, all app images encounters unexpected behavior. This issue persist whether using the FastImage library or the standard Image component in React Native.

The problem seem to come from the borderTopStartRadius property, as it applies the same style object to all images in the app. Also, images on next screens inherits the same height and width of the style object that have borderTopStartRadius.

React Native Version

0.76.1

Affected Platforms

Runtime - iOS

Output of npx react-native info

System:
  OS: macOS 13.7.1
  CPU: (8) x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
  Memory: 140.14 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 23.4.0
    path: /usr/local/bin/node
  Yarn:
    version: 1.22.22
    path: /usr/local/bin/yarn
  npm:
    version: 10.9.2
    path: /usr/local/bin/npm
  Watchman:
    version: 2024.12.02.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - visionOS 1.0
      - watchOS 10.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.2 AI-242.23339.11.2421.12700392
  Xcode:
    version: 15.2/15C500b
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 23.0.1
    path: /usr/local/opt/openjdk/bin/javac
  Ruby:
    version: 3.4.1
    path: /usr/local/opt/ruby/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.0
    wanted: 15.0.0
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.1
    wanted: 0.76.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Stacktrace or Logs

None

Reproducer

None

Screenshots and Videos

output.mp4
@react-native-bot react-native-bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Newer Patch Available labels Jan 12, 2025
@react-native-bot
Copy link
Collaborator

Tip

Newer version available: You are on a supported minor version, but it looks like there's a newer patch available - 0.76.6. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@react-native-bot
Copy link
Collaborator

Tip

Newer version available: You are on a supported minor version, but it looks like there's a newer patch available - undefined. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@react-native-bot
Copy link
Collaborator

Warning

Missing reproducer: We could not detect a reproducible example in your issue report. Please provide either:

@cortinico
Copy link
Contributor

Can you create a repro for this?

@Muntader
Copy link
Author

I test it with only 2 screen and list of image is work without any issues, I think the issues is related with another lib and i can't figure it, Anyway i will close the it.

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Jan 13, 2025
@cortinico cortinico added the Resolution: Answered When the issue is resolved with a simple answer label Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Image Needs: Attention Issues where the author has responded to feedback. Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Newer Patch Available Resolution: Answered When the issue is resolved with a simple answer
Projects
None yet
Development

No branches or pull requests

3 participants