Skip to content

Absolutely filled Svg does not correctly cover parent component #2689

Open
@itsramiel

Description

@itsramiel

Description

I am trying to create an svg that would span the entire space of its parent view. For that I would apply a style of Stylesheet.absoluteFill, but when I apply such a style the svg does not correctly cover the parent's space. However it does work with a normal view.

Example Code
import { StyleSheet, Text, View } from "react-native";
import { Svg } from "react-native-svg";

export default function Index() {
  return (
    <View
      style={{
        flex: 1,
        justifyContent: "center",
        alignItems: "center",
      }}
    >
      <View
        style={{
          padding: 12,
          backgroundColor: "blue",
        }}
      >
        <Svg
          style={{
            ...StyleSheet.absoluteFillObject,
            backgroundColor: "red",
          }}
        />
        <Text
          style={{
            color: "white",
          }}
        >
          Edit app/index.tsx to edit this screen.
        </Text>
      </View>
      <View
        style={{
          padding: 12,
          backgroundColor: "blue",
        }}
      >
        <View
          style={{
            ...StyleSheet.absoluteFillObject,
            backgroundColor: "red",
          }}
        />
        <Text
          style={{
            color: "white",
          }}
        >
          Edit app/index.tsx to edit this screen.
        </Text>
      </View>
    </View>
  );
}

Example Screenshots

Here I have two views on top of each other, with blue backgrounds. One has an Svg element and the other has a View, both that are absolutely filled with a red background. Notice that the svg extend all the way to the right and does not cover the entire height.

iOS Android
Image Image

My Expectation

I expect Svg to cover the entire View's space similar to a regular View

Steps to reproduce

  1. copy the code provided in the section above
  2. run the code
  3. examine the described issue

Snack or a link to a repository

https://github.com/itsramiel/svg-absolute-fill

SVG version

15.12.0

React Native version

0.79.2

Platforms

iOS, Android

JavaScript runtime

Hermes

Workflow

Expo Dev Client

Architecture

Fabric (New Architecture)

Build type

Debug app & dev bundle

Device

Android emulator

Device model

No response

Acknowledgements

Yes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions