forked from microsoft/react-native-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Created the RN app, issue microsoft#2378 * Added the RNW Current page to the host app, issue microsoft#2377
- Loading branch information
1 parent
1ff9ad9
commit 5bc0cc1
Showing
7 changed files
with
291 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
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
61
apps/PerfCompare/PerfCompare/ReactNativeCurrentPage.xaml.cs
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
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(), | ||
}; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "PerfCompareRN", | ||
"displayName": "PerfCompareRN" | ||
} |
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
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 |
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
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); |