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

ImageBackground sometimes only renders a portion of the image and does not fill the entire space #48803

Open
JohnGoodman opened this issue Jan 20, 2025 · 4 comments
Labels
Component: Image Component: ImageBackground Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Newer Patch Available

Comments

@JohnGoodman
Copy link

Description

There seems to be an issue with the ImageBackground component where it does not always render correctly. 90% of the time, it renders as expected, but that other 10% it won't fill the entire space. Instead, it only shows the image as what appears to be a 150 x 150 block. The issue happens on Android and IOS.

I don't have a reproducer since the issue happens intermittently and looking at a reproducer likely won't actually show you the issue. I've included a screenshot and the code I'm using.

Steps to reproduce

Use ImageBackground and run the app

React Native Version

0.76.2

Affected Platforms

Runtime - Android, Runtime - iOS

Output of npx react-native info

System:
  OS: macOS 13.5
  CPU: (10) arm64 Apple M1 Pro
  Memory: 95.38 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 23.3.0
    path: /opt/homebrew/bin/node
  Yarn:
    version: 3.6.4
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.9.0
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2024.11.18.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /opt/homebrew/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: 2023.2 AI-232.10300.40.2321.11668458
  Xcode:
    version: 15.2/15C500b
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.10
    path: /usr/bin/javac
  Ruby:
    version: 3.1.4
    path: /Users/johngoodman/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.1.2
    wanted: ^15.1.2
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.2
    wanted: 0.76.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Stacktrace or Logs

n/a

Reproducer

...

Screenshots and Videos

Here's the screenshot - see how the image is only showing in the top right corner - in this instance, it's supposed to fill the entire screen. Again, this image issue only happens 10% of the time and the other 90% the ImageBackground renders as expected ( it fills the entire ImageBackground component ). Also note, the screenshot is of the simulator, but this issue happens in production builds on actual phones too.

Image

Here's the sample code:

import React from 'react';
import {
  StyleSheet,
  ImageBackground,
  Image,
  View,
  Text,
  SafeAreaView,
  ScrollView
} from 'react-native';


const gradientDark = require('../../../assets/images/gradient-dark.png');


function Screen() {

  return (
    <ImageBackground
      source={{uri: imageUrl}}
      resizeMode={'cover'}
      style={{height: '100%', resizeMode: 'cover'}}
    >

      <Image
        source={gradientDark}
        resizeMode={'cover'}
        style={styles.imageGradient}
      />

      <SafeAreaView style={[
        isAndroid ? headerPadding : null,
        {position: 'relative', zIndex: 1}]
      }>
        <ScrollView
          showsVerticalScrollIndicator={false}
          bounces={false}
          contentContainerStyle={{flexGrow: 1}}
        >
          <View>
            <Text>Body content goes here</Text>
          </View>
        </ScrollView>
      </SafeAreaView>

      <ImageBackground
        source={gradientDark}
        resizeMode={'cover'}
        style={styles.footer}
      />

    </ImageBackground>
  );
}

export default Screen;


// --

const styles = StyleSheet.create({
  imageGradient: {
    position: 'absolute',
    top: -10,
    zIndex: 0,
    width: '100%',
    height: 260,
    transform: [{rotate: '180deg'}],
    resizeMode: 'cover'
  },
  footer: {
    position: 'absolute',
    bottom: 0,
    zIndex: 0,
    width: '100%',
    height: 200,
    resizeMode: 'cover'
  }
});
@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 20, 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

Warning

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

@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.

@devanshsaini11
Copy link

@JohnGoodman Can u please provide a repro to validate it quickly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Image Component: ImageBackground Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Newer Patch Available
Projects
None yet
Development

No branches or pull requests

3 participants