Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 41197b1

Browse files
Merge pull request #727 from deckgo/feed-card-img-ratio
fix: preserve card and image ratio on feed
2 parents aca88b0 + 5470fc2 commit 41197b1

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

studio/src/app/components/feed/card/app-feed-card/app-feed-card.scss

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
app-feed-card {
2+
display: block;
3+
24
ion-card {
35
--background: white;
46

@@ -22,10 +24,15 @@ app-feed-card {
2224

2325
deckgo-lazy-img {
2426
display: block;
25-
height: 48vw;
26-
max-height: 400px;
2727
--deckgo-lazy-img-width: 100%;
28-
--deckgo-lazy-img-height: auto;
28+
--deckgo-lazy-img-height: calc(((var(--card-width) - 20px) * 576) / 1024);
29+
--deckgo-lazy-img-display: block;
30+
}
31+
32+
&.ios {
33+
deckgo-lazy-img {
34+
--deckgo-lazy-img-height: calc(((var(--card-width) - 32px) * 576) / 1024);
35+
}
2936
}
3037
}
3138

studio/src/app/components/feed/card/app-feed-card/app-feed-card.tsx

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {Component, Prop, State, h} from '@stencil/core';
1+
import { Component, Prop, State, h, Element } from "@stencil/core";
2+
3+
import { debounce } from "@deckdeckgo/utils";
24

35
import DateTimeFormatOptions = Intl.DateTimeFormatOptions;
46

@@ -12,6 +14,8 @@ import {EnvironmentConfigService} from '../../../../services/core/environment/en
1214
shadow: false
1315
})
1416
export class AppFeedCard {
17+
@Element() el: HTMLElement;
18+
1519
@Prop()
1620
compact: boolean = true;
1721

@@ -39,8 +43,37 @@ export class AppFeedCard {
3943
@State()
4044
private screenshot: string;
4145

46+
@State()
47+
private width: number;
48+
4249
async componentWillLoad() {
4350
await this.init();
51+
52+
this.initWindowResize();
53+
}
54+
55+
async componentDidLoad() {
56+
await this.onWindowResize();
57+
}
58+
59+
componentDidUnload() {
60+
this.removeWindowResize();
61+
}
62+
63+
private initWindowResize() {
64+
if (window) {
65+
window.addEventListener('resize', debounce(this.onWindowResize));
66+
}
67+
}
68+
69+
private removeWindowResize() {
70+
if (window) {
71+
window.removeEventListener('resize', debounce(this.onWindowResize));
72+
}
73+
}
74+
75+
private onWindowResize = async () => {
76+
this.width = this.el.offsetWidth;
4477
}
4578

4679
private init(): Promise<void> {
@@ -125,7 +158,7 @@ export class AppFeedCard {
125158
}
126159

127160
render() {
128-
return <ion-card class="ion-margin-top">{this.renderCardContent()}</ion-card>;
161+
return <ion-card class="ion-margin-top" style={{'--card-width': `${this.width}px`}}>{this.renderCardContent()}</ion-card>;
129162
}
130163

131164
private renderCardContent() {

0 commit comments

Comments
 (0)