Skip to content

Commit ae8ac06

Browse files
committed
for Chrome < 56 and Chrome iOS, fallback to use fixed size instead of "vh"
1 parent b0b14b7 commit ae8ac06

5 files changed

+54
-1
lines changed

index.html

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
background-size: 100% 100vh;
5454
}
5555

56+
body.fixed-viewport-height {
57+
background-size: 100% 600px;
58+
}
59+
5660
news-app[unresolved] {
5761
height: 22px;
5862
padding-top: 21px;

src/news-app.html

+15
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
padding: 8px;
4646
text-align: center;
4747
};
48+
49+
/* use this value for the viewport height instead of "vh" unit */
50+
--viewport-height: 600px;
4851
}
4952

5053
iron-pages {
@@ -206,6 +209,18 @@
206209
created: function() {
207210
// Custom elements polyfill safe way to indicate an element has been upgraded.
208211
this.removeAttribute('unresolved');
212+
213+
// Chrome on iOS recomputes "vh" unit when URL bar goes off screen. Since we use "vh" unit
214+
// to size the cover image and the title, those items will resize in response to the URL
215+
// bar being shown or hidden. FWIW, this is not an issue in Chrome 56 on Android or iOS
216+
// Safari. To workaround this on Chrome on iOS, we will use a
217+
// fixed viewport height in places where normally relying on "vh" unit and replace them with
218+
// custom property "--viewport-height".
219+
var ua = navigator.userAgent;
220+
var cMatch = navigator.userAgent.match(/Android.*Chrome[\/\s](\d+\.\d+)/);
221+
if (ua.match('CriOS') || (cMatch && cMatch[0] && cMatch[1] < 56)) {
222+
document.body.classList.add('fixed-viewport-height');
223+
}
209224
},
210225

211226
attached: function() {

src/news-article-cover.html

+15-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
6565
object-fit: cover;
6666
}
6767

68+
:host-context(.fixed-viewport-height) .cover-img-container > news-img {
69+
min-height: calc(var(--viewport-height) * 0.6);
70+
}
71+
6872
.timer-icon {
6973
margin-left: 30px;
7074
}
@@ -86,6 +90,10 @@
8690
z-index: 1;
8791
}
8892

93+
:host-context(.fixed-viewport-height) .cover-text {
94+
height: var(--viewport-height);
95+
}
96+
8997
.cover-text .category {
9098
border: var(--app-transparent-border-style);
9199
}
@@ -122,6 +130,12 @@
122130
-webkit-line-clamp: 7;
123131
-webkit-box-orient: vertical;
124132
}
133+
134+
:host-context(.fixed-viewport-height) h1 {
135+
font-size: calc(var(--viewport-height) * 0.06);
136+
line-height: calc(var(--viewport-height) * 0.07);
137+
max-height: calc(var(--viewport-height) * 0.49);
138+
}
125139
}
126140
</style>
127141

@@ -142,7 +156,7 @@ <h1>[[article.headline]]</h1>
142156
<news-img src="[[article.imageUrl]]" hidden$="[[!article.imageUrl]]"></news-img>
143157
<div class="scrim"></div>
144158
</div>
145-
159+
146160
</template>
147161

148162
<script>

src/news-article.html

+6
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@
149149
-webkit-line-clamp: 7;
150150
-webkit-box-orient: vertical;
151151
}
152+
153+
:host-context(.fixed-viewport-height) h1 {
154+
font-size: calc(var(--viewport-height) * 0.06);
155+
line-height: calc(var(--viewport-height) * 0.07);
156+
max-height: calc(var(--viewport-height) * 0.49);
157+
}
152158
}
153159
</style>
154160

src/news-list-featured-item.html

+14
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,18 @@
8585
color: var(--app-cover-text-color);
8686
}
8787

88+
:host-context(.fixed-viewport-height) a {
89+
height: var(--viewport-height);
90+
}
91+
8892
news-img {
8993
min-height: 60vh;
9094
}
9195

96+
:host-context(.fixed-viewport-height) news-img {
97+
min-height: calc(var(--viewport-height) * 0.6);
98+
}
99+
92100
.scrim {
93101
@apply(--layout-fit);
94102
background: linear-gradient(to bottom, rgba(0,0,0,0.6) 0%, rgba(0,0,0,0.25) 25%, rgba(0,0,0,0.25) 50%, rgba(0,0,0,0.7) 80%, rgba(0,0,0,1) 100%);
@@ -113,6 +121,12 @@
113121
-webkit-box-orient: vertical;
114122
}
115123

124+
:host-context(.fixed-viewport-height) h2 {
125+
font-size: calc(var(--viewport-height) * 0.06);
126+
line-height: calc(var(--viewport-height) * 0.07);
127+
max-height: calc(var(--viewport-height) * 0.49);
128+
}
129+
116130
.category {
117131
border: var(--app-transparent-border-style);
118132
}

0 commit comments

Comments
 (0)