Bläddra i källkod

rerenders of a view can accept an old views scroll state

Adam Shaw 9 år sedan
förälder
incheckning
1324cc3343
2 ändrade filer med 18 tillägg och 7 borttagningar
  1. 3 2
      src/Calendar.js
  2. 15 5
      src/common/View.js

+ 3 - 2
src/Calendar.js

@@ -584,7 +584,8 @@ function Calendar_constructor(element, overrides) {
 
 
 	// Renders a view because of a date change, view-type change, or for the first time.
 	// Renders a view because of a date change, view-type change, or for the first time.
 	// If not given a viewType, keep the current view but render different dates.
 	// If not given a viewType, keep the current view but render different dates.
-	function renderView(viewType) {
+	// Accepts an optional scroll state to restore to.
+	function renderView(viewType, explicitScrollState) {
 		ignoreWindowResize++;
 		ignoreWindowResize++;
 
 
 		// if viewType is changing, remove the old view's rendering
 		// if viewType is changing, remove the old view's rendering
@@ -619,7 +620,7 @@ function Calendar_constructor(element, overrides) {
 			) {
 			) {
 				if (elementVisible()) {
 				if (elementVisible()) {
 
 
-					currentView.display(date); // will call freezeContentHeight
+					currentView.display(date, explicitScrollState); // will call freezeContentHeight
 					unfreezeContentHeight(); // immediately unfreeze regardless of whether display is async
 					unfreezeContentHeight(); // immediately unfreeze regardless of whether display is async
 
 
 					// need to do this after View::render, so dates are calculated
 					// need to do this after View::render, so dates are calculated

+ 15 - 5
src/common/View.js

@@ -271,12 +271,12 @@ var View = FC.View = Class.extend(EmitterMixin, ListenerMixin, {
 	// Does everything necessary to display the view centered around the given unzoned date.
 	// Does everything necessary to display the view centered around the given unzoned date.
 	// Does every type of rendering EXCEPT rendering events.
 	// Does every type of rendering EXCEPT rendering events.
 	// Is asychronous and returns a promise.
 	// Is asychronous and returns a promise.
-	display: function(date) {
+	display: function(date, explicitScrollState) {
 		var _this = this;
 		var _this = this;
-		var scrollState = null;
+		var prevScrollState = null;
 
 
-		if (this.displaying) {
-			scrollState = this.queryScroll();
+		if (!explicitScrollState && this.displaying) { // don't need prevScrollState if explicitScrollState
+			prevScrollState = this.queryScroll();
 		}
 		}
 
 
 		this.calendar.freezeContentHeight();
 		this.calendar.freezeContentHeight();
@@ -285,7 +285,17 @@ var View = FC.View = Class.extend(EmitterMixin, ListenerMixin, {
 			return (
 			return (
 				_this.displaying =
 				_this.displaying =
 					syncThen(_this.displayView(date), function() { // displayView might return a promise
 					syncThen(_this.displayView(date), function() { // displayView might return a promise
-						_this.forceScroll(_this.computeInitialScroll(scrollState));
+
+						// caller of display() wants a specific scroll state?
+						if (explicitScrollState) {
+							// we make an assumption that this is NOT the initial render,
+							// and thus don't need forceScroll (is inconveniently asynchronous)
+							_this.setScroll(explicitScrollState);
+						}
+						else {
+							_this.forceScroll(_this.computeInitialScroll(prevScrollState));
+						}
+
 						_this.calendar.unfreezeContentHeight();
 						_this.calendar.unfreezeContentHeight();
 						_this.triggerRender();
 						_this.triggerRender();
 					})
 					})