Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

WIP: React Native Windows Support #193

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/happo-example-react-native-project/.happo.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ module.exports = {
platformVersion: '6.0',
deviceName: 'Android Emulator',
}),
new ReactNativeTarget({
platform: 'windows',
}),
],
};
1 change: 1 addition & 0 deletions packages/happo-example-react-native-project/happo.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ StoryManager.make('some red example', () => (
<Text>Hello World!</Text>
</View>
));

2 changes: 1 addition & 1 deletion packages/happo-example-react-native-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"happo-viewer": "../happo-viewer",
"happo-core": "../happo-core",
"happo-target-react-native": "../happo-target-react-native",
"happo-uploader-s3": "../happo-target-react-native"
"happo-uploader-s3": "../happo-uploader-s3"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

}
}
5 changes: 4 additions & 1 deletion packages/happo-target-react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
"scripts": {
"build:runner:ios": "./scripts/build-runner-ios.sh",
"build:runner:android": "./scripts/build-runner-android.sh",
"build:runner:windows": "./scripts/build-runner-windows.sh",
"build:server": "../../node_modules/.bin/babel src -d lib --ignore __tests__",
"build": "npm run build:runner:ios && npm run build:runner:android && npm run build:server",
"watch": "npm run build:server -- --watch"
},
"devDependencies": {
"react-native": "^0.40.0",
"react-native-view-shot": "^1.5.1"
"react-native-view-shot": "^1.5.1",
"react-native-windows": "^0.43.0-rc.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, but does having react-native and react-native-windows both in our dev deps preclude us from doing non react-native-windows development? I'm somewhat ignorant of how this works.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lelandrichardson It doesn't preclude non react-native-windows development but it is a fairly large dependency to include if you're not working on windows. I was thinking of including as an optional dependency but I wasn't sure if that was the right approach either.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I'm tempted to agree this should be an optionalDependency. We could even create happo-target-react-native-windows, which would include this dependency. It may be a bit more work to modularize the code properly then.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optionalDependency would be worse, as that would make all of our users install it as well

"rnpm-plugin-windows": "^0.2.4"
},
"peerDependencies": {
"react-native": "*",
Expand Down
89 changes: 89 additions & 0 deletions packages/happo-target-react-native/runner/windows/.gitignore
Original file line number Diff line number Diff line change
@@ -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
256 changes: 256 additions & 0 deletions packages/happo-target-react-native/runner/windows/HappoRunner.sln

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Application
x:Class="HappoRunner.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:HappoRunner"
RequestedTheme="Light">

</Application>
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
using ReactNative;
using ReactNative.Modules.Launch;
using System;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace HappoRunner
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
sealed partial class App : Application
{
private readonly ReactPage _reactPage;

/// <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()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
this.Resuming += OnResuming;

_reactPage = new MainPage();
}

/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
base.OnLaunched(e);
OnCreate(e.Arguments);
}

/// <summary>
/// Invoked when the application is activated.
/// </summary>
/// <param name="args">The activated event arguments.</param>
protected override void OnActivated(IActivatedEventArgs args)
{
base.OnActivated(args);

switch (args.Kind)
{
case ActivationKind.Protocol:
case ActivationKind.ProtocolForResults:
var protocolArgs = (IProtocolActivatedEventArgs)args;
LauncherModule.SetActivatedUrl(protocolArgs.Uri.AbsoluteUri);
break;
}

if (args.PreviousExecutionState != ApplicationExecutionState.Running &&
args.PreviousExecutionState != ApplicationExecutionState.Suspended)
{
OnCreate(null);
}
}

/// <summary>
/// Called whenever the app is opened to initia
/// </summary>
/// <param name="arguments"></param>
private void OnCreate(string arguments)
{
_reactPage.OnResume(Exit);

#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
this.DebugSettings.EnableFrameRateCounter = true;
}

SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
AppViewBackButtonVisibility.Visible;
#endif

Frame rootFrame = Window.Current.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
Window.Current.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
Window.Current.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 " + e.SourcePageType.FullName);
}

/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private void OnSuspending(object sender, SuspendingEventArgs e)
{
_reactPage.OnSuspend();
}

/// <summary>
/// Invoked when application execution is being resumed.
/// </summary>
/// <param name="sender">The source of the resume request.</param>
/// <param name="e">Details about the resume request.</param>
private void OnResuming(object sender, object e)
{
_reactPage.OnResume(Exit);
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading