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

Commit 4e2722c

Browse files
topherfangioThomasBurleson
authored andcommitted
fix(content): Reduce iOS flicker when scrolling.
Often times when scrolling on an iOS device, certain elements on the page would flicker. This was most noticeable with inputs, but happens elsewhere too. Add a new `md-no-flicker` CSS class which is automatically applied to the `<md-content>` which adds a non-changing CSS transform to the element which fixes the flicker. Update docs to mention new class and workarounds if it causes issues for developers. Fixes #7078. Closes #8680
1 parent da54670 commit 4e2722c

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

src/components/content/content.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ angular.module('material.components.content', [
3232
* momentum scrolling is disabled. Momentum scrolling can cause flickering issues while scrolling
3333
* SVG icons and some other components.
3434
*
35+
* Additionally, we now also automatically apply a new `md-no-flicker` class to the `<md-content>`
36+
* which applies a Webkit-specific transform of `translateX(0)` to help reduce the flicker. If you
37+
* need to disable this for any reason, you can do so globally with the following code, or on a
38+
* case-by-case basis by ensuring your CSS operator is more specific than our global class.
39+
*
40+
* <hljs lang="css">
41+
* .md-no-flicker { -webkit-transform: none }
42+
* </hljs>
43+
*
3544
* @usage
3645
*
3746
* Add the `[layout-padding]` attribute to make the content padded.
@@ -41,7 +50,6 @@ angular.module('material.components.content', [
4150
* Lorem ipsum dolor sit amet, ne quod novum mei.
4251
* </md-content>
4352
* </hljs>
44-
*
4553
*/
4654

4755
function mdContentDirective($mdTheming) {
@@ -50,6 +58,7 @@ function mdContentDirective($mdTheming) {
5058
controller: ['$scope', '$element', ContentController],
5159
link: function(scope, element) {
5260
element.addClass('_md'); // private md component indicator for styling
61+
element.addClass('md-no-flicker'); // add a class that helps prevent flickering on iOS devices
5362

5463
$mdTheming(element);
5564
scope.$broadcast('$mdContentLoaded', element);

src/components/content/content.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ md-content {
1616
&[md-scroll-xy] {
1717
}
1818

19-
// For iOS allow disabling of momentum scrolling
20-
// @see issue #2640.
21-
22-
&.md-no-momentum {
23-
-webkit-overflow-scrolling: auto;
24-
}
25-
2619
@media print {
2720
overflow: visible !important;
2821
}

src/components/content/demoBasicUsage/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
div.demo-content {
3-
height: 600px;
3+
height: 450px;
44
}
55
div[ng-controller] {
66
height:100%;

src/core/style/structure.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ input {
166166
}
167167
}
168168

169+
// For iOS allow disabling of momentum scrolling
170+
// @see issue #2640
171+
.md-no-momentum {
172+
-webkit-overflow-scrolling: auto;
173+
}
174+
175+
// Add a class to help reduce flicker
176+
// @see issue #7078
177+
.md-no-flicker {
178+
-webkit-transform: translateX(0);
179+
}
180+
169181
@media (min-width: $layout-breakpoint-sm) {
170182
.md-padding {
171183
padding: 16px;

0 commit comments

Comments
 (0)