Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 KB | None | 0 0
  1. using ReactNative;
  2. using ReactNative.Modules.Launch;
  3. using System;
  4. using Windows.ApplicationModel;
  5. using Windows.ApplicationModel.Activation;
  6. using Windows.UI.Core;
  7. using Windows.UI.Xaml;
  8. using Windows.UI.Xaml.Controls;
  9. using Windows.UI.Xaml.Navigation;
  10.  
  11. namespace AwesomeProject
  12. {
  13. /// <summary>
  14. /// Provides application-specific behavior to supplement the default Application class.
  15. /// </summary>
  16. sealed partial class App : Application
  17. {
  18. private readonly ReactPage _reactPage;
  19.  
  20. /// <summary>
  21. /// Initializes the singleton application object. This is the first line of authored code
  22. /// executed, and as such is the logical equivalent of main() or WinMain().
  23. /// </summary>
  24. public App()
  25. {
  26. this.InitializeComponent();
  27. this.Suspending += OnSuspending;
  28. this.Resuming += OnResuming;
  29.  
  30. _reactPage = new MainPage();
  31. }
  32.  
  33. /// <summary>
  34. /// Invoked when the application is launched normally by the end user. Other entry points
  35. /// will be used such as when the application is launched to open a specific file.
  36. /// </summary>
  37. /// <param name="e">Details about the launch request and process.</param>
  38. protected override void OnLaunched(LaunchActivatedEventArgs e)
  39. {
  40. base.OnLaunched(e);
  41. OnCreate(e.Arguments);
  42. }
  43.  
  44. /// <summary>
  45. /// Invoked when the application is activated.
  46. /// </summary>
  47. /// <param name="args">The activated event arguments.</param>
  48. protected override void OnActivated(IActivatedEventArgs args)
  49. {
  50. base.OnActivated(args);
  51.  
  52. switch (args.Kind)
  53. {
  54. case ActivationKind.Protocol:
  55. case ActivationKind.ProtocolForResults:
  56. var protocolArgs = (IProtocolActivatedEventArgs)args;
  57. LauncherModule.SetActivatedUrl(protocolArgs.Uri.AbsoluteUri);
  58. break;
  59. }
  60.  
  61. if (args.PreviousExecutionState != ApplicationExecutionState.Running &&
  62. args.PreviousExecutionState != ApplicationExecutionState.Suspended)
  63. {
  64. OnCreate(null);
  65. }
  66. }
  67.  
  68. /// <summary>
  69. /// Called whenever the app is opened to initia
  70. /// </summary>
  71. /// <param name="arguments"></param>
  72. private void OnCreate(string arguments)
  73. {
  74. _reactPage.OnResume(Exit);
  75.  
  76. #if DEBUG
  77. if (System.Diagnostics.Debugger.IsAttached)
  78. {
  79. this.DebugSettings.EnableFrameRateCounter = true;
  80. }
  81.  
  82. SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
  83. AppViewBackButtonVisibility.Visible;
  84. #endif
  85.  
  86. Frame rootFrame = Window.Current.Content as Frame;
  87.  
  88. // Do not repeat app initialization when the Window already has content,
  89. // just ensure that the window is active
  90. if (rootFrame == null)
  91. {
  92. _reactPage.OnCreate(arguments);
  93.  
  94. // Create a Frame to act as the navigation context and navigate to the first page
  95. rootFrame = new Frame();
  96.  
  97. rootFrame.NavigationFailed += OnNavigationFailed;
  98.  
  99. // Place the frame in the current Window
  100. Window.Current.Content = rootFrame;
  101. }
  102.  
  103. if (rootFrame.Content == null)
  104. {
  105. // When the navigation stack isn't restored navigate to the first page,
  106. // configuring the new page by passing required information as a navigation
  107. // parameter
  108. rootFrame.Content = _reactPage;
  109. }
  110.  
  111. // Ensure the current window is active
  112. Window.Current.Activate();
  113. }
  114.  
  115. /// <summary>
  116. /// Invoked when Navigation to a certain page fails
  117. /// </summary>
  118. /// <param name="sender">The Frame which failed navigation</param>
  119. /// <param name="e">Details about the navigation failure</param>
  120. private void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
  121. {
  122. throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
  123. }
  124.  
  125. /// <summary>
  126. /// Invoked when application execution is being suspended. Application state is saved
  127. /// without knowing whether the application will be terminated or resumed with the contents
  128. /// of memory still intact.
  129. /// </summary>
  130. /// <param name="sender">The source of the suspend request.</param>
  131. /// <param name="e">Details about the suspend request.</param>
  132. private void OnSuspending(object sender, SuspendingEventArgs e)
  133. {
  134. _reactPage.OnSuspend();
  135. }
  136.  
  137. /// <summary>
  138. /// Invoked when application execution is being resumed.
  139. /// </summary>
  140. /// <param name="sender">The source of the resume request.</param>
  141. /// <param name="e">Details about the resume request.</param>
  142. private void OnResuming(object sender, object e)
  143. {
  144. _reactPage.OnResume(Exit);
  145. }
  146. }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement