summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2020-09-23 17:15:29 +0200
committerOskar Nyberg <oskar@mullvad.net>2020-10-13 13:58:56 +0200
commit4d11817ef253b60ebec3107130d449fcc4f4d038 (patch)
tree915094f094fb05db45f48bb4530d9cde08d7b195
parentfe9c120ce85e17fdf9b3a7b2b27d1fd41bc8eb02 (diff)
downloadmullvadvpn-4d11817ef253b60ebec3107130d449fcc4f4d038.tar.xz
mullvadvpn-4d11817ef253b60ebec3107130d449fcc4f4d038.zip
Move CSS property with url-value to inline styles
Due to an ineffeciency in `styled-components` url-values are refetched each time styles are appended causing the icons to flicker.
-rw-r--r--gui/src/renderer/components/ImageView.tsx9
1 files changed, 5 insertions, 4 deletions
diff --git a/gui/src/renderer/components/ImageView.tsx b/gui/src/renderer/components/ImageView.tsx
index fa57985363..368b72cd9e 100644
--- a/gui/src/renderer/components/ImageView.tsx
+++ b/gui/src/renderer/components/ImageView.tsx
@@ -1,14 +1,14 @@
import path from 'path';
-import * as React from 'react';
+import React, { useMemo } from 'react';
import styled from 'styled-components';
export interface IImageViewProps extends IImageMaskProps {
+ source: string;
onClick?: (event: React.MouseEvent) => void;
className?: string;
}
interface IImageMaskProps extends React.HTMLAttributes<HTMLElement> {
- source: string;
width?: number;
height?: number;
disabled?: boolean;
@@ -26,7 +26,6 @@ const ImageMask = styled.div((props: IImageMaskProps) => {
const maskWidth = props.width ? `${props.width}px` : 'auto';
const maskHeight = props.height ? `${props.height}px` : 'auto';
return {
- maskImage: `url('${props.source}')`,
maskRepeat: 'no-repeat',
maskSize: `${maskWidth} ${maskHeight}`,
maskPosition: 'center',
@@ -45,10 +44,12 @@ export default function ImageView(props: IImageViewProps) {
? props.source
: `../../assets/images/${props.source}.svg`;
+ const style = useMemo(() => ({ WebkitMaskImage: `url('${url}')` }), [url]);
+
if (props.tintColor) {
const { source: _source, ...otherProps } = props;
return (
- <ImageMask source={url} {...otherProps}>
+ <ImageMask style={style} {...otherProps}>
<HiddenImage src={url} width={props.width} height={props.height} />
</ImageMask>
);