Skip to content

Commit

Permalink
Started RNW implementations
Browse files Browse the repository at this point in the history
* Created the RN app, issue microsoft#2378
* Added the RNW Current page to the host app, issue microsoft#2377
  • Loading branch information
jonthysell committed May 21, 2019
1 parent 1ff9ad9 commit 5bc0cc1
Show file tree
Hide file tree
Showing 7 changed files with 291 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apps/PerfCompare/PerfCompare/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private void Button_Click(object sender, RoutedEventArgs e)
}
else if (sender == rnwcsBtn)
{

rootFrame.Navigate(typeof(ReactNativeCurrentPage));
}
else if (sender == rnwcppBtn)
{
Expand Down
35 changes: 33 additions & 2 deletions apps/PerfCompare/PerfCompare/PerfCompare.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
<WindowsXamlEnableOverview>true</WindowsXamlEnableOverview>
<PackageCertificateKeyFile>PerfCompare_TemporaryKey.pfx</PackageCertificateKeyFile>
<PackageCertificateThumbprint>FBBDAAAD53D1DBF6BF5834906D875E833F228C97</PackageCertificateThumbprint>
<GenerateAppInstallerFile>False</GenerateAppInstallerFile>
<AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
<AppxBundle>Always</AppxBundle>
<AppxBundlePlatforms>x86|x64|arm</AppxBundlePlatforms>
<AppInstallerUpdateFrequency>1</AppInstallerUpdateFrequency>
<AppInstallerCheckForUpdateFrequency>OnApplicationRun</AppInstallerCheckForUpdateFrequency>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -104,16 +110,21 @@
</Compile>
<Compile Include="PerfStats.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReactNativeCurrentPage.xaml.cs">
<DependentUpon>ReactNativeCurrentPage.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
<None Include="app.json" />
<None Include="PerfCompare_TemporaryKey.pfx" />
</ItemGroup>
<ItemGroup>
<Content Include="images\blueuser.png" />
<Content Include="images\reduser.png" />
<None Include="index.js" />
</ItemGroup>
<ItemGroup>
<Content Include="Properties\Default.rd.xml" />
<Content Include="Assets\LockScreenLogo.scale-200.png" />
<Content Include="Assets\SplashScreen.scale-200.png" />
Expand All @@ -123,6 +134,11 @@
<Content Include="Assets\StoreLogo.png" />
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
</ItemGroup>
<ItemGroup>
<Content Include="ReactAssets\**\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
Expand All @@ -136,6 +152,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ReactNativeCurrentPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
Expand All @@ -152,10 +172,21 @@
<Name>ReactNative</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<ItemGroup>
<Content Include="..\..\..\current\Yoga\csharp\Yoga\bin\Universal\$(Platform)\$(Configuration)\yoga.dll">
<Link>%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>False</Visible>
</Content>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>$(ProjectDir)\bundle.cmd</PreBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
14 changes: 14 additions & 0 deletions apps/PerfCompare/PerfCompare/ReactNativeCurrentPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Page
x:Class="PerfCompare.ReactNativeCurrentPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:PerfCompare"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
Loaded="Page_Loaded">

<Grid />

</Page>
61 changes: 61 additions & 0 deletions apps/PerfCompare/PerfCompare/ReactNativeCurrentPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

using ReactNative;
using ReactNative.Modules.Core;
using ReactNative.Shell;

namespace PerfCompare
{
public sealed partial class ReactNativeCurrentPage : Page
{
private MainReactNativeHost _host = new MainReactNativeHost();

public ReactNativeCurrentPage()
{
this.InitializeComponent();
this.InitializeReactNative();
}

private void InitializeReactNative()
{
_host.OnResume(null);
_host.ApplyArguments(null);
this.Content = _host.OnCreate();
}

private async void Page_Loaded(object sender, RoutedEventArgs e)
{
await Dispatcher.RunIdleAsync((args) =>
{
App.PerfStats.Stop();
App.ShowStats();
});
}
}

public sealed class MainReactNativeHost : ReactNativeHost
{
public override string MainComponentName => "PerfCompareRN";

#if DEBUG
public override bool UseDeveloperSupport => true;
#else
public override bool UseDeveloperSupport => false;
#endif

protected override string JavaScriptMainModuleName => "index";

protected override string JavaScriptBundleFile => "ms-appx:///ReactAssets/index.windows.bundle";

protected override List<IReactPackage> Packages => new List<IReactPackage>
{
new MainReactPackage(),
};
}
}
4 changes: 4 additions & 0 deletions apps/PerfCompare/PerfCompare/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "PerfCompareRN",
"displayName": "PerfCompareRN"
}
25 changes: 25 additions & 0 deletions apps/PerfCompare/PerfCompare/bundle.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@echo off
setlocal

set AppName=PerfCompareRN

set AppRoot=%~dp0
set CurrentRoot=%AppRoot%..\..\..\current
set VNextRoot=%AppRoot%..\..\..\current

pushd %CurrentRoot%

rmdir /s /q %AppName%
mkdir %AppName%

xcopy /q %AppRoot%images\* %AppName%\images\
xcopy /q %AppRoot%app.json %AppName%\
xcopy /q %AppRoot%index.js %AppName%\

call react-native bundle --platform windows --entry-file %AppName%\index.js --bundle-output %AppRoot%ReactAssets\index.windows.bundle --assets-dest %AppRoot%ReactAssets

rmdir /s /q %AppName%

popd

endlocal
153 changes: 153 additions & 0 deletions apps/PerfCompare/PerfCompare/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
ScrollView,
FlatList,
Image,
View,
} from 'react-native';

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#dddddd',
},
message: {
flex: 1,
flexDirection: 'row',
alignItems: 'flex-start',
marginLeft: 20,
marginTop: 10,
marginRight: 20,
marginBottom: 10,
},
messageAvatar: {
width: 50,
height: 50,
marginRight: 10,
},
messageContents: {
backgroundColor: '#ffffff',
flexDirection: 'column',
paddingLeft: 20,
paddingTop: 10,
paddingRight: 20,
paddingBottom: 10,
},
messageHeader: {
flexDirection: 'row',
alignItems: 'flex-start',
},
messageUserName: {
color: '#333333',
fontWeight: 'bold',
fontSize: 12,
},
messageTime: {
color: '#666666',
fontWeight: 'bold',
marginLeft: 10,
fontSize: 12,
},
messageText: {
fontSize: 12,
}
});

var TextValues = [
"What time did the man go to the dentist?",
"I don't know.",
"Tooth hurt-y.",
"Did you hear about the guy who invented Lifesavers?",
"No.",
"They say he made a mint.",
"A ham sandwich walks into a bar and orders a beer. Bartender says, 'Sorry we don't serve food here.'",
"Whenever the cashier at the grocery store asks my dad if he would like the milk in a bag he replies, 'No, just leave it in the carton!'",
"Why do chicken coops only have two doors?",
"I don't know, why?",
"Because if they had four, they would be chicken sedans!",
];

var UserNameValues = [
"Parent",
"Child",
];

var AvatarValues = [
require("./images/blueuser.png"),
require("./images/reduser.png"),
];

class Message {
constructor() {
this.Text = "";
this.UserName = "";
this.Avatar = null;
this.Timestamp = null;
this.Time = "";
}
}

function GetValue(index, values) {
return values[index % values.length];
}

function CreateMessage(id) {
let m = new Message();
m.Text = GetValue(id, TextValues);
m.UserName = GetValue(id, UserNameValues);
m.Avatar = GetValue(id, AvatarValues);
m.Timestamp = new Date(new Date().getTime() + id * 60000);
m.Time = '' + m.Timestamp.getHours() % 12 + ':' + ('0' + m.Timestamp.getMinutes()).slice(-2) + ' ' + (m.Timestamp.getHours() > 12 ? 'PM' : 'AM' );
return m;
}

function LoadMessages(count) {
let messages = [];
for (var i = 0; i < count; i++) {
messages[i] = CreateMessage(i);
}
return messages;
}

var messages = LoadMessages(1000);

class MessageView extends Component {
render() {
return (
<View style={styles.message}>
<Image style={styles.messageAvatar} source={this.props.message.Avatar} />
<View style={styles.messageContents}>
<View style={styles.messageHeader}>
<Text style={styles.messageUserName}>{this.props.message.UserName}</Text>
<Text style={styles.messageTime}>{this.props.message.Time}</Text>
</View>
<Text style={styles.messageText}>{this.props.message.Text}</Text>
</View>
</View>
);
}
};

class App extends Component {
render() {
return (
<View style={styles.container}>
<ScrollView>
<FlatList
data={messages}
renderItem={({item}) => <MessageView message={item} />}
keyExtractor={(item, index) => index.toString()}
/>
</ScrollView>
</View>
);
}
};

AppRegistry.registerComponent('PerfCompareRN', () => App);

0 comments on commit 5bc0cc1

Please sign in to comment.