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

[IMPROVEMENT] Add rounded corners to svg NFTs #4247

Merged
merged 8 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,13 @@ exports[`RemoteImage should render static sources 1`] = `
`;

exports[`RemoteImage should render svg correctly 1`] = `
<ComponentErrorBoundary
componentLabel="RemoteImage-SVG"
>
<View
style={Object {}}
>
<SvgUri
height="100%"
source={
Object {
"uri": "https://raw.githubusercontent.com/MetaMask/contract-metadata/master/images/dai.svg",
}
<View>
<RemoteImage
source={
Object {
"uri": "https://raw.githubusercontent.com/MetaMask/contract-metadata/master/images/dai.svg",
}
uri="https://raw.githubusercontent.com/MetaMask/contract-metadata/master/images/dai.svg"
width="100%"
/>
</View>
</ComponentErrorBoundary>
}
/>
</View>
`;
12 changes: 10 additions & 2 deletions app/components/Base/RemoteImage/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import { Image, ViewPropTypes, View } from 'react-native';
import { Image, ViewPropTypes, View, StyleSheet } from 'react-native';
import FadeIn from 'react-native-fade-in-image';
// eslint-disable-next-line import/default
import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource';
Expand All @@ -10,11 +10,19 @@ import ComponentErrorBoundary from '../../UI/ComponentErrorBoundary';
import useIpfsGateway from '../../hooks/useIpfsGateway';
import { util } from '@metamask/controllers';

const createStyles = () =>
StyleSheet.create({
svgContainer: {
overflow: 'hidden',
},
});

const RemoteImage = (props) => {
// Avoid using this component with animated SVG
const source = resolveAssetSource(props.source);
const isImageUrl = isUrl(props?.source?.uri);
const ipfsGateway = useIpfsGateway();
const styles = createStyles();
const resolvedIpfsUrl = useMemo(() => {
try {
const url = new URL(props.source.uri);
Expand Down Expand Up @@ -53,7 +61,7 @@ const RemoteImage = (props) => {
onError={props.onError}
componentLabel="RemoteImage-SVG"
>
<View style={style}>
<View style={[...style, styles.svgContainer]}>
<SvgUri {...props} uri={uri} width={'100%'} height={'100%'} />
</View>
</ComponentErrorBoundary>
Expand Down
13 changes: 8 additions & 5 deletions app/components/Base/RemoteImage/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { View } from 'react-native';
import { shallow } from 'enzyme';
import RemoteImage from './';

Expand All @@ -12,11 +13,13 @@ jest.mock('react-redux', () => ({
describe('RemoteImage', () => {
it('should render svg correctly', () => {
const wrapper = shallow(
<RemoteImage
source={{
uri: 'https://raw.githubusercontent.com/MetaMask/contract-metadata/master/images/dai.svg',
}}
/>,
<View>
<RemoteImage
source={{
uri: 'https://raw.githubusercontent.com/MetaMask/contract-metadata/master/images/dai.svg',
}}
/>
</View>,
);
expect(wrapper).toMatchSnapshot();
});
Expand Down