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: calculate height of images before they are loaded in intro screens #257

Merged
merged 1 commit into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions src/components/WelcomeStepsModal/FullWidthFixedAspectImage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";

export const FullWidthFixedAspectImage: React.FC<{ aspect: number; src: string; alt: string }> = (props) => {
// the aspect value should be calculated as 100 * h / w
return (
<div style={{ position: "relative", width: "100%", height: "auto", padding: `${props.aspect}% 0 0 0` }}>
<img
src={props.src}
alt={props.alt}
style={{ position: "absolute", width: "100%", height: "100%", top: 0, left: 0 }}
/>
</div>
);
};
3 changes: 2 additions & 1 deletion src/components/WelcomeStepsModal/WelcomeModal1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import { Typography } from "@material-ui/core";
import { makeStyles } from "@material-ui/core/styles";
import { useCommonWelcomeModalStyles } from "./useCommonWelcomeModalStyles";
import { FullWidthFixedAspectImage } from "./FullWidthFixedAspectImage";

const useStyles = makeStyles(() => ({
listItemDiv: {
Expand Down Expand Up @@ -29,7 +30,7 @@ export const WelcomeModal1: React.FC = () => {
<>
<Typography className={classes.title}>Willkommen bei der CovMap</Typography>

<img src={"/images/WelcomeModalImage1.svg"} alt="Welcome" width="100%" />
<FullWidthFixedAspectImage aspect={62.1} src="/images/WelcomeModalImage1.svg" alt="Welcome" />

<div className={classes.infoTextDiv}>
<div className={classes.listItemDiv}>
Expand Down
5 changes: 3 additions & 2 deletions src/components/WelcomeStepsModal/WelcomeModal2.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import { Typography } from "@material-ui/core";
import { useCommonWelcomeModalStyles } from "./useCommonWelcomeModalStyles";
import { FullWidthFixedAspectImage } from "./FullWidthFixedAspectImage";

export const WelcomeModal2: React.FC = () => {
const classes = useCommonWelcomeModalStyles();
Expand All @@ -9,8 +10,8 @@ export const WelcomeModal2: React.FC = () => {
<>
<Typography className={classes.title}>Was ist die CovMap?</Typography>

<img src={"/images/WelcomeModalImage2.svg"} alt="Welcome" width="100%" />
<img src={"/images/WelcomeModalImage2_sub.svg"} alt="Welcome" />
<FullWidthFixedAspectImage aspect={62.1} src="/images/WelcomeModalImage2.svg" alt="Welcome" />
<img src={"/images/WelcomeModalImage2_sub.svg"} alt="Welcome" width="124px" height="36px" />

<div className={classes.infoTextDiv}>
<Typography className={classes.largeText}>
Expand Down
5 changes: 3 additions & 2 deletions src/components/WelcomeStepsModal/WelcomeModal3.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import { Typography } from "@material-ui/core";
import { useCommonWelcomeModalStyles } from "./useCommonWelcomeModalStyles";
import { FullWidthFixedAspectImage } from "./FullWidthFixedAspectImage";

export const WelcomeModal3: React.FC = () => {
const classes = useCommonWelcomeModalStyles();
Expand All @@ -9,8 +10,8 @@ export const WelcomeModal3: React.FC = () => {
<>
<Typography className={classes.title}>Was zeigt mir die CovMap an?</Typography>

<img src={"/images/WelcomeModalImage3.svg"} alt="Welcome" width="100%" />
<img src={"/images/WelcomeModalImage3_sub.svg"} alt="Welcome" />
<FullWidthFixedAspectImage aspect={62.1} src="/images/WelcomeModalImage3.svg" alt="Welcome" />
<img src={"/images/WelcomeModalImage3_sub.svg"} alt="Welcome" width="113px" height="46px" />

<div className={classes.infoTextDiv}>
<Typography className={classes.largeText}>
Expand Down