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

fix(android): Incorrect mapping of svg files #1042

Merged
merged 1 commit into from
Mar 9, 2020

Conversation

msand
Copy link
Contributor

@msand msand commented Mar 9, 2020

software-mansion/react-native-svg#1306
facebook/react-native#28266
facebook/metro#529

Summary:

Fix mapping of svg files. They're currently bundled to the drawable folder incorrectly.

Test Plan:

LocalSvg.js

import React, {useState, useEffect} from 'react';
import {SvgCss} from 'react-native-svg';
import loadLocalResource from 'react-native-local-resource';

export function LocalSvg({asset, ...rest}) {
  const [xml, setXml] = useState(null);
  useEffect(() => {
    loadLocalResource(asset).then(setXml);
  }, [asset]);
  return <SvgCss xml={xml} {...rest} />;
}

App.js

import React from 'react';
import {LocalSvg} from './LocalSvg';
export default () => <LocalSvg asset={require('./test.svg')} />;

test.svg: any svg content

The develop branch of react-native-svg contains an optimized version of LocalSvg, waiting to be released once this set of pull requests are merged.

@msand
Copy link
Contributor Author

msand commented Mar 9, 2020

Merging and releasing this enables using .svg files with react-native-svg without any further configuration. @grabbou @thymikee @Esemesek everyone ok with me merging this?

I would be very surprised if this would break anything, as the current outcome leads to android not even building, unless one adds

android.disableResourceValidation=true

to gradle.properties, at which point the files aren't fetchable, nor usable in Image components. I suspect this file extension has been added by mistake.

@msand
Copy link
Contributor Author

msand commented Mar 9, 2020

Android drawable do not support svg, and never have, so I'm quite certain this has been an unintentional addition. I'll go ahead and merge this. Could we cut a new release soon? Any schedule?

@msand msand merged commit 4a0c14c into master Mar 9, 2020
@thymikee thymikee deleted the fix-raw-svg-drawable-mapping branch March 9, 2020 07:02
@thymikee
Copy link
Member

thymikee commented Mar 9, 2020

Based on the comment it looks like svg shouldn't be there indeed, but maybe it's some kind of a hack? Maybe it's not necessary now? Hard to tell at the moment. We can include it in 4.x, so it would be available in RN 0.62, and see if it breaks anywhere.

Next time, please don't just merge without approval.

cc @krizzu @dulmandakh

@msand
Copy link
Contributor Author

msand commented Mar 9, 2020

Ah great, sounds good.

Oh sorry if I stepped on anyones toes. Was quite certain it'd be alright to merge, and if not, revert it.

@msand
Copy link
Contributor Author

msand commented Mar 9, 2020

Did this while half asleep at 4am, quite an ass move in retrospect, sorry for any inconvenience.

@thymikee
Copy link
Member

thymikee commented Mar 9, 2020

Cool. I hope we can introduce this change as it seems to make sense. I'd just like more eyes on this :). Also, we've improved merging access to code owners only, so we're safer now 👍

@msand
Copy link
Contributor Author

msand commented Mar 9, 2020

Yeah, I was actually a bit surprised to have merge rights, as I haven't contributed to this package before, in my sleepy state somehow assumed it was normal react-native-community practise.

msand added a commit to software-mansion/react-native-svg that referenced this pull request Mar 9, 2020
depends on react-native-community/cli#1042

```jsx
import React from 'react';
import {LocalSvg} from 'react-native-svg';
import test from './test.svg';
export default () => <LocalSvg asset={test} />;
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants