From f2e423329dd177d62c314760c7d191e2b0dea98c Mon Sep 17 00:00:00 2001 From: Pepe Rivera Date: Tue, 19 May 2020 09:58:11 -0700 Subject: [PATCH] Improve launch performance by delay loading NavigationView (#1213) * Delay load graph engine * Remove default behavior * Delay load nav view * Add automation properties * clean up * handle shortcut keys * Include only navview changes * Address PR comments * manual merge fix * PR Changes * Undo other changes * reset resw file * fix margin --- src/Calculator/App.xaml | 2 +- .../Common/KeyboardShortcutManager.cpp | 6 ++ src/Calculator/Views/MainPage.xaml | 83 ++++++++++--------- src/Calculator/Views/MainPage.xaml.cpp | 4 +- src/Calculator/Views/MainPage.xaml.h | 2 +- 5 files changed, 57 insertions(+), 40 deletions(-) diff --git a/src/Calculator/App.xaml b/src/Calculator/App.xaml index 8a6ab230..b737ea2e 100644 --- a/src/Calculator/App.xaml +++ b/src/Calculator/App.xaml @@ -249,7 +249,7 @@ 14 16 - + diff --git a/src/Calculator/Common/KeyboardShortcutManager.cpp b/src/Calculator/Common/KeyboardShortcutManager.cpp index 3ce05d15..378db341 100644 --- a/src/Calculator/Common/KeyboardShortcutManager.cpp +++ b/src/Calculator/Common/KeyboardShortcutManager.cpp @@ -513,6 +513,12 @@ void KeyboardShortcutManager::OnKeyDownHandler(CoreWindow ^ sender, KeyEventArgs const auto& lookupMap = GetCurrentKeyDictionary(static_cast(key)); auto buttons = lookupMap.equal_range(static_cast(key)); auto navView = buttons.first->second.Resolve(); + + if (navView == nullptr) + { + return; + } + auto appViewModel = safe_cast(navView->DataContext); appViewModel->Mode = ViewMode::Date; auto categoryName = AppResourceProvider::GetInstance()->GetResourceString(L"DateCalculationModeText"); diff --git a/src/Calculator/Views/MainPage.xaml b/src/Calculator/Views/MainPage.xaml index 1fc2fddc..ee872121 100644 --- a/src/Calculator/Views/MainPage.xaml +++ b/src/Calculator/Views/MainPage.xaml @@ -118,6 +118,49 @@ + + + + + + + + + + + + + + + UseSystemFocusVisuals="True" + x:Load="False"> @@ -170,41 +214,6 @@ - - - - - - - - - - - diff --git a/src/Calculator/Views/MainPage.xaml.cpp b/src/Calculator/Views/MainPage.xaml.cpp index 225e992f..0454af69 100644 --- a/src/Calculator/Views/MainPage.xaml.cpp +++ b/src/Calculator/Views/MainPage.xaml.cpp @@ -270,12 +270,14 @@ void MainPage::OnPageLoaded(_In_ Object ^, _In_ RoutedEventArgs ^ args) // Delay load things later when we get a chance. this->Dispatcher->RunAsync( - CoreDispatcherPriority::Normal, ref new DispatchedHandler([]() { + CoreDispatcherPriority::Normal, ref new DispatchedHandler([this]() { if (TraceLogger::GetInstance()->IsWindowIdInLog(ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()))) { AppLifecycleLogger::GetInstance().LaunchUIResponsive(); AppLifecycleLogger::GetInstance().LaunchVisibleComplete(); } + + this->FindName(L"NavView"); })); } diff --git a/src/Calculator/Views/MainPage.xaml.h b/src/Calculator/Views/MainPage.xaml.h index f2c75d6a..2b71bdd6 100644 --- a/src/Calculator/Views/MainPage.xaml.h +++ b/src/Calculator/Views/MainPage.xaml.h @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #pragma once