-
-
Save ShoeBoom/1e2ec26df57c576c5f20e5b0f29800bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Application | |
x:Class="ReactInUWP.App" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:local="using:ReactInUWP"> | |
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Windows.ApplicationModel; | |
using Windows.ApplicationModel.Activation; | |
using Windows.UI.Xaml; | |
using Windows.UI.Xaml.Controls; | |
using Windows.UI.Xaml.Navigation; | |
using Microsoft.Gaming.XboxGameBar; | |
namespace ReactInUWP | |
{ | |
sealed partial class App : Application | |
{ | |
private XboxGameBarWidget widget1 = null; | |
public App() | |
{ | |
this.InitializeComponent(); | |
this.Suspending += OnSuspending; | |
} | |
protected override void OnActivated(IActivatedEventArgs args) | |
{ | |
XboxGameBarWidgetActivatedEventArgs widgetArgs = null; | |
if (args.Kind == ActivationKind.Protocol) | |
{ | |
var protocolArgs = args as IProtocolActivatedEventArgs; | |
string scheme = protocolArgs.Uri.Scheme; | |
if (scheme.Equals("ms-gamebarwidget")) | |
{ | |
widgetArgs = args as XboxGameBarWidgetActivatedEventArgs; | |
} | |
} | |
if (widgetArgs != null) | |
{ | |
if (widgetArgs.IsLaunchActivation) | |
{ | |
var rootFrame = new Frame(); | |
rootFrame.NavigationFailed += OnNavigationFailed; | |
Window.Current.Content = rootFrame; | |
widget1 = new XboxGameBarWidget( | |
widgetArgs, | |
Window.Current.CoreWindow, | |
rootFrame); | |
rootFrame.Navigate(typeof(ReactControl)); | |
Window.Current.Closed += Widget1Window_Closed; | |
Window.Current.Activate(); | |
} | |
} | |
} | |
private void Widget1Window_Closed(object sender, Windows.UI.Core.CoreWindowEventArgs e) | |
{ | |
widget1 = null; | |
Window.Current.Closed -= Widget1Window_Closed; | |
} | |
protected override void OnLaunched(LaunchActivatedEventArgs e) | |
{ | |
Frame rootFrame = Window.Current.Content as Frame; | |
if (rootFrame == null) | |
{ | |
rootFrame = new Frame(); | |
rootFrame.NavigationFailed += OnNavigationFailed; | |
Window.Current.Content = rootFrame; | |
} | |
if (e.PrelaunchActivated == false) | |
{ | |
if (rootFrame.Content == null) | |
{ | |
rootFrame.Navigate(typeof(ReactControl), e.Arguments); | |
} | |
Window.Current.Activate(); | |
} | |
} | |
void OnNavigationFailed(object sender, NavigationFailedEventArgs e) | |
{ | |
throw new Exception("Failed to load Page " + e.SourcePageType.FullName); | |
} | |
private void OnSuspending(object sender, SuspendingEventArgs e) | |
{ | |
var deferral = e.SuspendingOperation.GetDeferral(); | |
widget1 = null; | |
deferral.Complete(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Page | |
x:Class="ReactInUWP.ReactControl" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:local="using:ReactInUWP" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:react="using:Microsoft.ReactNative" | |
mc:Ignorable="d" | |
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | |
<Grid> | |
<react:ReactRootView x:Name="RootElement" /> | |
</Grid> | |
</Page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.ReactNative; | |
using Microsoft.ReactNative.Managed; | |
using Windows.UI.Xaml.Controls; | |
namespace ReactInUWP | |
{ | |
sealed partial class ReactControl : Page | |
{ | |
static readonly string JSFileName = "index"; | |
static readonly string JSComponentName = "ReactInUWP"; | |
public ReactControl() | |
{ | |
InitializeComponent(); | |
LoadReact(); | |
} | |
public void LoadReact() | |
{ | |
ReactNativeHost host = new ReactNativeHost(); | |
host.InstanceSettings.MainComponentName = JSFileName; | |
host.InstanceSettings.JavaScriptMainModuleName = JSFileName; | |
host.InstanceSettings.UseLiveReload = true; | |
host.InstanceSettings.UseWebDebugger = true; | |
host.InstanceSettings.EnableDeveloperMenu = true; | |
host.ReloadInstance(); | |
RootElement.ComponentName = JSComponentName; | |
JSValue initialProps = new JSValueObject { ["one"] = "1", ["two"] = "2" }; | |
RootElement.InitialProps = (IJSValueWriter writer) => writer.WriteValue(initialProps); | |
RootElement.ReactNativeHost = host; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment