Skip to content

Commit c5b48cb

Browse files
committed
feat(scroll): native scrolling for scroll view
1 parent 853453c commit c5b48cb

File tree

3 files changed

+98
-3
lines changed

3 files changed

+98
-3
lines changed

Diff for: js/angular/directive/scroll.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,22 @@ IonicModule
4444
'$timeout',
4545
'$controller',
4646
'$ionicBind',
47-
function($timeout, $controller, $ionicBind) {
47+
'$ionicConfig',
48+
function($timeout, $controller, $ionicBind, $ionicConfig) {
4849
return {
4950
restrict: 'E',
5051
scope: true,
5152
controller: function() {},
52-
compile: function(element) {
53+
compile: function(element, attr) {
5354
element.addClass('scroll-view ionic-scroll');
5455

5556
//We cannot transclude here because it breaks element.data() inheritance on compile
5657
var innerElement = jqLite('<div class="scroll"></div>');
5758
innerElement.append(element.contents());
5859
element.append(innerElement);
5960

61+
var nativeScrolling = attr.overflowScroll !== "false" && (attr.overflowScroll === "true" || !$ionicConfig.scrolling.jsScrolling());
62+
6063
return { pre: prelink };
6164
function prelink($scope, $element, $attr) {
6265
$ionicBind($scope, $attr, {
@@ -84,6 +87,12 @@ function($timeout, $controller, $ionicBind) {
8487
if (!$scope.direction) { $scope.direction = 'y'; }
8588
var isPaging = $scope.$eval($scope.paging) === true;
8689

90+
if(nativeScrolling) {
91+
$element.addClass('overflow-scroll');
92+
}
93+
94+
$element.addClass('scroll-' + $scope.direction);
95+
8796
var scrollViewOptions = {
8897
el: $element[0],
8998
delegateHandle: $attr.delegateHandle,
@@ -97,8 +106,10 @@ function($timeout, $controller, $ionicBind) {
97106
zooming: $scope.$eval($scope.zooming) === true,
98107
maxZoom: $scope.$eval($scope.maxZoom) || 3,
99108
minZoom: $scope.$eval($scope.minZoom) || 0.5,
100-
preventDefault: true
109+
preventDefault: true,
110+
nativeScrolling: nativeScrolling
101111
};
112+
102113
if (isPaging) {
103114
scrollViewOptions.speedMultiplier = 0.8;
104115
scrollViewOptions.bouncing = false;

Diff for: scss/_scaffolding.scss

+8
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ body.grade-c {
8383
display: block;
8484
overflow: hidden;
8585

86+
&.overflow-scroll {
87+
position: relative;
88+
}
89+
90+
&.scroll-x { overflow-x: scroll; overflow-y: hidden; }
91+
&.scroll-y { overflow-x: hidden; overflow-y: scroll; }
92+
&.scroll-xy { overflow-x: scroll; overflow-y: scroll; }
93+
8694
// Hide the top border if any
8795
margin-top: -1px;
8896
}

Diff for: test/html/scroll_content.html

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<!DOCTYPE html>
2+
<html ng-app="navTest">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Scroll Click Tests</title>
6+
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
7+
<link rel="stylesheet" href="../../../../dist/css/ionic.css">
8+
<!--<link rel="stylesheet" href="../../../../dist/css/ionic.css">-->
9+
<script src="../../../../dist/js/ionic.bundle.js"></script>
10+
<style>
11+
#click-notify {
12+
position: absolute;
13+
top: 0;
14+
left: 0;
15+
z-index: 9997;
16+
display: none;
17+
padding: 8px;
18+
background: red;
19+
color: white;
20+
}
21+
#mousemove-notify {
22+
position: absolute;
23+
top: 40px;
24+
left: 0;
25+
z-index: 9998;
26+
display: none;
27+
padding: 8px;
28+
background: orange;
29+
}
30+
#touchmove-notify {
31+
position: absolute;
32+
top: 80px;
33+
left: 0;
34+
z-index: 9999;
35+
display: none;
36+
padding: 8px;
37+
background: yellow;
38+
}
39+
#touchcancel-notify {
40+
position: absolute;
41+
top: 120px;
42+
left: 0;
43+
z-index: 9999;
44+
display: none;
45+
padding: 8px;
46+
background: purple;
47+
color: white;
48+
}
49+
a {
50+
display: block;
51+
background: blue;
52+
margin: 40px 80px;
53+
padding: 40px;
54+
-webkit-tap-highlight-color: transparent;
55+
text-decoration: none;
56+
}
57+
.activated {
58+
background: yellow;
59+
}
60+
</style>
61+
</head>
62+
<body>
63+
<ion-view title="Home" hide-nav-bar="true">
64+
<ion-content>
65+
<f style="display: block; width: 80%; margin: auto; background-color: green; height: 500px"></f>
66+
<ion-scroll zooming="true" direction="xy" style="width: 500px; height: 200px">
67+
<div style="width: 5000px; height: 5000px; background: url('https://upload.wikimedia.org/wikipedia/commons/a/ad/Europe_geological_map-en.jpg') repeat"></div>
68+
</ion-scroll>
69+
<f style="display: block; width: 80%; margin: auto; background-color: red; height: 2000px"></f>
70+
</ion-content>
71+
</ion-view>
72+
<script>
73+
angular.module('navTest', ['ionic']);
74+
</script>
75+
</body>
76+
</html>

0 commit comments

Comments
 (0)