Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Removes the turnstile navigation for startup." What?

The below code is provided in the default templates for creating WP8.1 XAML apps. (Universal / WinRT).

What is this code used for? I can't seem to get a breakpoint to hit when rootFrame.ContentTransitions != null. It could be cool for an app to provide its own opening animation instead of a turnstile. E.g. like cortana.

In App.xaml.cs

#if WINDOWS_PHONE_APP
            // Removes the turnstile navigation for startup.
            if (rootFrame.ContentTransitions != null)
            {
                _transitions = new TransitionCollection();
                foreach (var c in rootFrame.ContentTransitions)
                {
                    _transitions.Add(c);
                }
            }

            rootFrame.ContentTransitions = null;
            rootFrame.Navigated += this.RootFrame_FirstNavigated;
#endif

Edit: A clue I found - if all the above code is commented out then turnstile page transitions are everywhere. Now if only you uncomment: rootFrame.ContentTransitions = null; then all turnstile page transitions are taken away. That's weird because ContentTransitions was null before the setter, but transitions are different if the setter is set as null.

Edit Edit: Seems like this code is required due to a OS race condition. If all the code is commented out except for nulling the ContentTransitions at rare times the app has turnstile animations.

like image 521
Quincy Avatar asked May 06 '14 21:05

Quincy


2 Answers

Update (3 Dec 2014)

I just discovered a way of using animations to 'hide' the OS level turnstile when the app gets loaded the first time.

Three things are required to achieve this -

  1. The app doesn't have a splash image.
  2. ContentTransitions is set to null in your main page's NavigatedTo handler.
  3. Create a PageIn animation and animate your main page's LayoutRoot's background color - basically to have it aligned with system background color first and then animate it to whatever color you want in a short amount of time.

You can download a sample from here.


If you have all the code commented out. You would think that the ContentTransitions should still be null right? At least that's what I thought.

The answer is no. The ContentTransitions will later be assigned with a NavigationThemeTransition.

This might be because in the default Frame style, there's these lines of code.

<Setter Property="ContentTransitions">
    <Setter.Value>
        <TransitionCollection>
            <NavigationThemeTransition/>
        </TransitionCollection>
    </Setter.Value>
</Setter>

However, this property of Frame only gets set very late. If you put a breakpoint in the constructor of your MainPage. You will see it's still null. But if you put another breakpoint in the OnNavigatedTo, finally you will see both this.Frame and this.Frame.ContentTransitions with values in them.

What if I uncomment out

rootFrame.ContentTransitions = null;

I guess, in the setter of this property, there's no if (_contentTransitions != null) return; check, when you set it to null, there must be something that stops it from getting the default NavigationThemeTransition, and that's why you don't see the turnstile animation anymore.

However, there's still one animation you will always see no matter what you do.

Try suspending your app by pressing the back or home key and re-activate it. Yes, the turnstile animation is back! Though I think this turnstile animation is different from the ones we disabled in the Frame.ContentTransitions. Take a look at how an app is launched for the very first time - a splash screen coming up with the turnstile animation. This I believe, is the the same one, and it's probably controlled by the OS.

So, why do they put in this check?

if (rootFrame.ContentTransitions != null)

My guess is because since there's an OS level turnstile animation, if you don't provide a splash screen, the OS will simply animate your app launching so it makes sense to skip whatever is inside the Frame.ContentTransitions.

You would probably then ask but Frame.ContentTransitions is always null!

Here's one scenario that it won't be null. Try creating a custom Frame style with some default ContentTransitions, and instead of

rootFrame = new Frame(); 

do

rootFrame = new Frame { Style = (Style)App.Current.Resources["MyFrame"] };

This time, you will see the code go into the if statement as the ContentTransitions is no longer null.

like image 109
Justin XL Avatar answered Oct 20 '22 12:10

Justin XL


Remove rootFrame.Navigated += this.RootFrame_FirstNavigated;

And replace rootFrame.ContentTransitions = null;

by rootFrame.ContentTransitions = new TransitionCollection();

To specify the transition of each Page use:

<Page.Transitions>
    <TransitionCollection>
        <NavigationThemeTransition />
    </TransitionCollection>
</Page.Transitions>
like image 34
Ouadie Avatar answered Oct 20 '22 13:10

Ouadie