Skip to content

Commit

Permalink
move get scroller logic to list refresh event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
js1972 committed Mar 23, 2014
1 parent f7a12b9 commit f53a573
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 35 deletions.
3 changes: 2 additions & 1 deletion Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Component details:
- Views: XML
- Navigation: EventBus
*/
/*globals FastClick*/
(function() {
"use strict";

Expand Down Expand Up @@ -43,4 +44,4 @@ Component details:
}
});

}());
}());
28 changes: 13 additions & 15 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function(grunt) {
src: "Gruntfile.js"
},
application: {
src: ["model/**/*.js", "util/**/*.js", "view/**/*.js", "*.js"]
src: ["model/**/*.js", "util/**/*.js", "view/**/*.js", "*.js", "!util/fastclick.js"]
}
},

Expand All @@ -57,14 +57,14 @@ module.exports = function(grunt) {
application: {
files: "<%= jshint.application.src %>",
tasks: ["jshint:application"]
} ,
livereload: {
options: {
livereload: "<%= connect.options.livereload %>"
},
//files: "<%= jshint.application.src %>" // Be careful to not watch npm dependencies
files: ["model/**/*.js", "util/**/*.js", "view/**/*.js", "*.js", "view/**/*.xml"]
}
},
livereload: {
options: {
livereload: "<%= connect.options.livereload %>"
},
//files: "<%= jshint.application.src %>" // Be careful to not watch npm dependencies
files: ["model/**/*.js", "util/**/*.js", "view/**/*.js", "*.js", "view/**/*.xml"]
}
},


Expand All @@ -80,11 +80,9 @@ module.exports = function(grunt) {

connect: {
options: {
port: 8080 ,

livereload: 35729,

hostname: "localhost",
port: 9000,
livereload: 35729,
hostname: "0.0.0.0",
base: [".", "../sapui5/latest"]
},

Expand Down Expand Up @@ -157,4 +155,4 @@ module.exports = function(grunt) {
"watch"
]);
});
};
};
30 changes: 13 additions & 17 deletions view/Master.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

currentRows: 0,
listInit: false,
scroller: null,
usingIScroll: true,

onInit: function() {
this.bus = sap.ui.getCore().getEventBus();
Expand All @@ -25,19 +23,12 @@

/**
* sap.m.PulltoRefresh : refresh event handler.
* Note that the iScroll library is only used in the mobile scenario. We need to work
* Note that the iScroll library is only used in the mobile scenario. We need to work
* with the UI5 scroller in desktop mode.
*/
refreshData: function(evt) {
var pullToRefreshControl = evt.getSource();
var model = this.getView().getModel();

// Get the scroller
this.scroller = pullToRefreshControl.getParent()._oScroller._scroller;
if (!this.scroller) {
this.scroller = pullToRefreshControl.getParent()._oScroller;
this.usingIScroll = false;
}

// Load some more data (dummy json) and pre-pend it to our model
jQuery.ajax("model/more_mock_data.json", {
Expand Down Expand Up @@ -68,17 +59,22 @@
var rowsToScroll = diff < 0 ? 0 : diff;

// Get scroller


if (this.scroller) {
var scroller = this.byId("idViewRoot--idViewMaster--idPageMaster").getScrollDelegate();
if (scroller._scroller) {
scroller = scroller._scroller; //using iScroll instead of native
}


if (scroller) {
setTimeout(function() {
var listItemSelector = "#__item0-idViewRoot--idViewMaster--list-" + rowsToScroll;
var offset;
if (this.usingIScroll) {
this.scroller.scrollToElement(listItemSelector, 400);

if (typeof(scroller.scrollToElement) === "function") {
scroller.scrollToElement(listItemSelector, 400);
} else {
offset = $(listItemSelector).position().top;
this.scroller.scrollTo(0, offset, 400);
scroller.scrollTo(0, offset, 400);
}

sap.m.MessageToast.show("Scroll up to see new items...");
Expand Down Expand Up @@ -164,4 +160,4 @@

});

}());
}());
4 changes: 2 additions & 2 deletions view/Master.view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns="sap.m"
xmlns:core="sap.ui.core"
xmlns:mvc="sap.ui.core.mvc" >
<Page title="{i18n>MasterTitle}" >
<Page id="idPageMaster" title="{i18n>MasterTitle}" >
<subHeader>
<Bar>
<contentLeft>
Expand Down Expand Up @@ -53,4 +53,4 @@
</Bar>
</footer>
</Page>
</core:View>
</core:View>

0 comments on commit f53a573

Please sign in to comment.