software-mansion / software-mansion/react-native-svg

Pixelated SVG on Android when using SvgXml and applying style scale transform.

Open
#2,179 4 comments 3 reactions 1 assignee View on GitHub

@jakex7 is already working on this.

Since Jun 13, 2024.

bug
Dominant language
TypeScript
Stars
8k
Forks
1.2k
Avg merge
10d 9h
Merged PRs (30d)
2

Description

Bug

SVGs displayed using SvgXML are pixelated on Android when scaled using style transforms.

Conditions to reproduce:

  • Use SvgXML
  • Apply a style transformation on scale different to 1 (does not matter if less or more)
  • Run on Android.

The following component:

import * as React from 'react';
import { SvgXml } from 'react-native-svg';

export const LogoSVG: React.FC = () => {
  const svgXML = `<svg width="20" height="20" viewBox="0 0 40 40" fill="none">
    <circle cx="20" cy="20" r="10" fill="#FF0000"/>
  </svg>`;
  return <SvgXml xml={svgXML} style={{ transform: [{ scale: 2.5 }] }} />;
};

Renders like this:
Screenshot 2023-11-26 at 21 08 10

In contrast, when no scale transformation is applied (scale = 1);

import * as React from 'react';
import { SvgXml } from 'react-native-svg';

export const LogoSVG: React.FC = () => {
  const svgXML = `<svg width="60" height="60" viewBox="0 0 40 40" fill="none">
    <circle cx="20" cy="20" r="10" fill="#FF0000"/>
  </svg>`;
  return <SvgXml xml={svgXML} style={{ transform: [{ scale: 1 }] }} />;
};

It renders a sharp, geometrically precise figure:
Screenshot 2023-11-26 at 21 13 42

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.