Answered by:
Grid App template: why handle "contentanimating" event in updateLayout: function?

Question
-
(1) File | New Project ... | Template=JavaScript => Grid App template
(2) Open groupDetail.js, look at lines 39-57:
// This function updates the page layout in response to viewState changes. updateLayout: function (element, viewState, lastViewState) { /// <param name="element" domElement="true" /> var listView = element.querySelector(".itemslist").winControl; if (lastViewState !== viewState) { if (lastViewState === appViewState.snapped || viewState === appViewState.snapped) { var handler = function (e) { listView.removeEventListener("contentanimating", handler, false); e.preventDefault(); } listView.addEventListener("contentanimating", handler, false); var firstVisible = listView.indexOfFirstVisible; this._initializeLayout(listView, viewState); if (firstVisible >= 0 && listView.itemDataSource.list.length > 0) { listView.indexOfFirstVisible = firstVisible; } } } },
I'm confused about the purpose of adding an event listener for "contentanimating" ... it seems that the only thing the handler (defined in the anonymous method above it) is attempting to do is first DISABLE the event listener then call preventDefault(). This happens when the ViewState changes to "snapped".
SO what is it about the "contentanimating" event that we're trying to mitigate by calling e.preventDefault()? Is it some default animation that we're attempting to stop in its tracks? My attempts at finding documentation on this haven't been successful, so any insight would be most appreciated!
- Edited by BobTabor Monday, September 3, 2012 5:26 PM clarifying my question
Monday, September 3, 2012 5:24 PM
Answers
-
You nailed it.
If we are going to a snapped view or coming from a snapped view, we don't want to display the page entrance animation!
You can actually see this. Click on the header for one of the groups you will see the page entrance animation.
Then put a bp on that e.preventDefault().
Snap the view... you see we hit it and there is no page animation.
Un snap and again... you see we hit it and there is no page animation.
-Jeff
Jeff Sanders (MSFT)
- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Tuesday, September 4, 2012 7:57 PM
- Marked as answer by BobTabor Thursday, September 6, 2012 4:14 PM
Tuesday, September 4, 2012 7:57 PMModerator
All replies
-
You nailed it.
If we are going to a snapped view or coming from a snapped view, we don't want to display the page entrance animation!
You can actually see this. Click on the header for one of the groups you will see the page entrance animation.
Then put a bp on that e.preventDefault().
Snap the view... you see we hit it and there is no page animation.
Un snap and again... you see we hit it and there is no page animation.
-Jeff
Jeff Sanders (MSFT)
- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Tuesday, September 4, 2012 7:57 PM
- Marked as answer by BobTabor Thursday, September 6, 2012 4:14 PM
Tuesday, September 4, 2012 7:57 PMModerator -
Thank you Jeff, marked as answered.
Any suggestions on where I could learn more about some of these "default" (?) animations like this "page entrance animation"? I'm guessing that -- in order to look / feel Metro Microsoft doesn't want us messing with those in most scenarios -- but I would like to learn a little more about what they are and how they work.
I already found this:
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh452703.aspx
... and it was very helpful. Just want to see if there's anything else out there I'm missing. Again, thank you ... much appreciated!
- Edited by BobTabor Thursday, September 6, 2012 4:18 PM Added hyperlink
Thursday, September 6, 2012 4:17 PM -
Yes, this is good:
http://msdn.microsoft.com/en-us/library/windows/apps/hh465201.aspx
http://msdn.microsoft.com/en-us/library/windows/apps/Hh465165(v=win.10).aspx
and then the samples help as well (first 3-4 links):
Jeff Sanders (MSFT)
Thursday, September 6, 2012 6:24 PMModerator