Skip to content

Commit

Permalink
Added React Native Windows dotNet46 support (#684)
Browse files Browse the repository at this point in the history
Added support react-native-windows dotNet
Added example for react-native-windows UWP based
Added example for react-native-windows dotNet based

Project structure:

CodePush.Shared - shared code between UWP and dotNet
CodePush - UWP specific code
CodePush.Net46 - dotNet specific code

For UWP solution it needs to be added the following projects:

CodePush.Shared
CodePush
For dotNet solution it needs to be added the following projects:

CodePush.Shared
CodePush.Net46
Examples:

Examples\CodePushDemoApp\windows\CodePushDemoApp.sln the solution contains both examples (UWP and dotNet).

Notes

Example for ARM configuration has not been tested. Since there is no changes in UWP part of implementation, there is low risk of failure.

In this implementation we tried to reuse UWP library as much as possible. The following issues are relevant for both platforms:

ZipFile.ExtractToDirectory is not reliable and throws exception if:
folder exists already
path is too long (> 250 chars)
Un-zipping is quite long operation. Does it make sense for async?
await UpdateUtils.UnzipBundleAsync(downloadFile.Path, unzippedFolder.Path);
  • Loading branch information
abodalevsky authored and Richard Hua committed Feb 14, 2017
1 parent fc7c109 commit be96f07
Show file tree
Hide file tree
Showing 69 changed files with 2,866 additions and 87 deletions.
38 changes: 37 additions & 1 deletion .gitignore
@@ -1,3 +1,5 @@
# gitignore contributors: remember to update .npmignore

# OSX
#
.DS_Store
Expand Down Expand Up @@ -152,4 +154,38 @@ captures/
code-push-plugin-testing-framework/node_modules

# RN New Version App Generation
Examples/testapp_rn
Examples/testapp_rn

# Windows
windows/.vs/
windows/obj/

#Visual Studio files
*.[Oo]bj
*.user
*.aps
*.pch
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.[Cc]ache
*.ilk
*.log
*.lib
*.sbr
*.sdf
*.opensdf
*.opendb
*.unsuccessfulbuild
ipch/
[Oo]bj/
[Bb]in
[Dd]ebug*/
[Rr]elease*/
Ankh.NoLoad
42 changes: 42 additions & 0 deletions .npmignore
Expand Up @@ -43,3 +43,45 @@ android/local.properties
android/.gradle
android/**/*.iml
android/.idea


# Windows
windows/.vs/
windows/obj/

#Tests
windows/CodePush.Net46.Test

#Visual Studio files
*.[Oo]bj
*.user
*.aps
*.pch
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.[Cc]ache
*.ilk
*.log
*.lib
*.sbr
*.sdf
*.opensdf
*.opendb
*.unsuccessfulbuild
ipch/
[Oo]bj/
[Bb]in
[Dd]ebug*/
[Rr]elease*/
Ankh.NoLoad

#NuGet
packages/
*.nupkg
7 changes: 7 additions & 0 deletions Examples/CodePushDemoApp/NuGet.Config
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="myget.org" value="https://www.myget.org/F/chakracore-preview/api/v3/index.json" />
</packageSources>
</configuration>
1 change: 1 addition & 0 deletions Examples/CodePushDemoApp/index.windows.js
@@ -0,0 +1 @@
require("./demo");
3 changes: 2 additions & 1 deletion Examples/CodePushDemoApp/package.json
Expand Up @@ -9,6 +9,7 @@
"babel-preset-react-native-stage-0": "1.0.1",
"react": "15.4.0",
"react-native": "0.40.0",
"react-native-code-push": "file:../../"
"react-native-code-push": "file:../../",
"react-native-windows": "0.40.0-rc.1"
}
}
89 changes: 89 additions & 0 deletions Examples/CodePushDemoApp/windows/.gitignore
@@ -0,0 +1,89 @@
*AppPackages*
*BundleArtifacts*
*ReactAssets*

#OS junk files
[Tt]humbs.db
*.DS_Store

#Visual Studio files
*.[Oo]bj
*.user
*.aps
*.pch
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.[Cc]ache
*.ilk
*.log
*.lib
*.sbr
*.sdf
*.opensdf
*.opendb
*.unsuccessfulbuild
ipch/
[Oo]bj/
[Bb]in
[Dd]ebug*/
[Rr]elease*/
Ankh.NoLoad

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb

#MonoDevelop
*.pidb
*.userprefs

#Tooling
_ReSharper*/
*.resharper
[Tt]est[Rr]esult*
*.sass-cache

#Project files
[Bb]uild/

#Subversion files
.svn

# Office Temp Files
~$*

# vim Temp Files
*~

#NuGet
packages/
*.nupkg

#ncrunch
*ncrunch*
*crunch*.local.xml

# visual studio database projects
*.dbmdl

#Test files
*.testsettings

#Other files
*.DotSettings
.vs/
*project.lock.json
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
</startup>
</configuration>
5 changes: 5 additions & 0 deletions Examples/CodePushDemoApp/windows/CodePushDemoApp.Wpf/App.xaml
@@ -0,0 +1,5 @@
<Application x:Class="CodePushDemoApp.Wpf.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

</Application>
107 changes: 107 additions & 0 deletions Examples/CodePushDemoApp/windows/CodePushDemoApp.Wpf/App.xaml.cs
@@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;

namespace CodePushDemoApp.Wpf
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
private readonly AppReactPage _reactPage = new AppReactPage();

/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
}

/// <summary>
/// Override method fired prior to the Startup event when the Run method of the Application object is called...
/// </summary>
/// <param name="e"></param>
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
OnCreate(e.Args);
}

/// <summary>
/// Called whenever the app is opened to initialized...
/// </summary>
/// <param name="arguments"></param>
private void OnCreate(string[] arguments)
{
var shellWindow = Application.Current.MainWindow;

if (shellWindow == null)
{
shellWindow = new Window
{
ShowActivated = true,
ShowInTaskbar = true,
Title = "CodePushDemoApp.WPF",
Height = 768,
Width = 1024,
WindowStartupLocation = WindowStartupLocation.CenterScreen
};

Application.Current.MainWindow = shellWindow;
}

//Show Window if it is not already active...
if (!shellWindow.IsLoaded)
{
shellWindow.Show();
}

var rootFrame = shellWindow.Content as Frame;

// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
_reactPage.OnCreate(arguments);

// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();

rootFrame.NavigationFailed += OnNavigationFailed;

// Place the frame in the current Window
shellWindow.Content = rootFrame;
}

if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Content = _reactPage;
}

// Ensure the current window is active
shellWindow.Activate();
}

/// <summary>
/// Invoked when Navigation to a certain page fails
/// </summary>
/// <param name="sender">The Frame which failed navigation</param>
/// <param name="e">Details about the navigation failure</param>
private void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception("Failed to load Page...");
}
}
}

@@ -0,0 +1,60 @@
using CodePush.ReactNative;
using ReactNative;
using ReactNative.Modules.Core;
using ReactNative.Shell;
using System;
using System.Collections.Generic;

namespace CodePushDemoApp.Wpf
{
internal class AppReactPage : ReactPage
{
public override string MainComponentName
{
get
{
return "CodePushDemoApp";
}
}

private CodePushReactPackage codePushReactPackage = null;
public override string JavaScriptBundleFile
{
get
{
codePushReactPackage = new CodePushReactPackage("deployment-key-here", this);

#if BUNDLE
return codePushReactPackage.GetJavaScriptBundleFile();
#else
return null;
#endif
}
}


public override List<IReactPackage> Packages
{
get
{
return new List<IReactPackage>
{
new MainReactPackage(),
codePushReactPackage
};
}
}

public override bool UseDeveloperSupport
{
get
{
#if !BUNDLE || DEBUG
return true;
#else
return false;
#endif
}
}
}
}

0 comments on commit be96f07

Please sign in to comment.