Skip to content

Commit 2fd6e18

Browse files
authored
Merge pull request #443 from qmatteoq/windows-sample
Added Windows implementation of the sample
2 parents 4d46013 + 2783ed4 commit 2fd6e18

32 files changed

+24522
-16
lines changed

example/metro.config.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* Metro configuration for React Native
3+
* https://github.com/facebook/react-native
4+
*
5+
* @format
6+
*/
17
const path = require('path')
28
const blacklist = require('metro-config/src/defaults/exclusionList')
39
const escape = require('escape-string-regexp')
@@ -13,19 +19,21 @@ module.exports = {
1319
projectRoot: __dirname,
1420
watchFolders: [root],
1521

16-
// We need to make sure that only one version is loaded for peerDependencies
17-
// So we blacklist them at the root, and alias them to the versions in example's node_modules
1822
resolver: {
23+
blockList: blacklist([
24+
// This stops "react-native run-windows" from causing the metro server to crash if its already running
25+
new RegExp(`${path.resolve(__dirname, 'windows').replace(/[/\\]/g, '/')}.*`),
26+
// This prevents "react-native run-windows" from hitting: EBUSY: resource busy or locked, open msbuild.ProjectImports.zip
27+
/.*\.ProjectImports\.zip/,
28+
]),
1929
blacklistRE: blacklist(
2030
modules.map((m) => new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`)),
2131
),
22-
2332
extraNodeModules: modules.reduce((acc, name) => {
2433
acc[name] = path.join(__dirname, 'node_modules', name)
2534
return acc
2635
}, {}),
2736
},
28-
2937
transformer: {
3038
getTransformOptions: async () => ({
3139
transform: {

example/package-lock.json

Lines changed: 5844 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
"scripts": {
77
"android": "react-native run-android",
88
"ios": "react-native run-ios",
9-
"start": "react-native start"
9+
"start": "react-native start",
10+
"windows": "react-native run-windows"
1011
},
1112
"dependencies": {
1213
"react": "17.0.1",
13-
"react-native": "0.64.2"
14+
"react-native": "0.64.2",
15+
"react-native-windows": "^0.64.0-0"
1416
},
1517
"devDependencies": {
1618
"@babel/core": "^7.12.10",

example/windows/.gitignore

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
*AppPackages*
2+
*BundleArtifacts*
3+
4+
#OS junk files
5+
[Tt]humbs.db
6+
*.DS_Store
7+
8+
#Visual Studio files
9+
*.[Oo]bj
10+
*.user
11+
*.aps
12+
*.pch
13+
*.vspscc
14+
*.vssscc
15+
*_i.c
16+
*_p.c
17+
*.ncb
18+
*.suo
19+
*.tlb
20+
*.tlh
21+
*.bak
22+
*.[Cc]ache
23+
*.ilk
24+
*.log
25+
*.lib
26+
*.sbr
27+
*.sdf
28+
*.opensdf
29+
*.opendb
30+
*.unsuccessfulbuild
31+
ipch/
32+
[Oo]bj/
33+
[Bb]in
34+
[Dd]ebug*/
35+
[Rr]elease*/
36+
Ankh.NoLoad
37+
38+
# Visual C++ cache files
39+
ipch/
40+
*.aps
41+
*.ncb
42+
*.opendb
43+
*.opensdf
44+
*.sdf
45+
*.cachefile
46+
*.VC.db
47+
*.VC.VC.opendb
48+
49+
#MonoDevelop
50+
*.pidb
51+
*.userprefs
52+
53+
#Tooling
54+
_ReSharper*/
55+
*.resharper
56+
[Tt]est[Rr]esult*
57+
*.sass-cache
58+
59+
#Project files
60+
[Bb]uild/
61+
62+
#Subversion files
63+
.svn
64+
65+
# Office Temp Files
66+
~$*
67+
68+
# vim Temp Files
69+
*~
70+
71+
#NuGet
72+
packages/
73+
*.nupkg
74+
75+
#ncrunch
76+
*ncrunch*
77+
*crunch*.local.xml
78+
79+
# visual studio database projects
80+
*.dbmdl
81+
82+
#Test files
83+
*.testsettings
84+
85+
#Other files
86+
*.DotSettings
87+
.vs/
88+
*project.lock.json
89+
90+
#Files generated by the VS build
91+
**/Generated Files/**
92+

example/windows/DocumentPickerExample.sln

Lines changed: 240 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/Bundle
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<react:ReactApplication
2+
x:Class="DocumentPickerExample.App"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:react="using:Microsoft.ReactNative">
6+
<Application.Resources>
7+
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
8+
</Application.Resources>
9+
</react:ReactApplication>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using Microsoft.ReactNative;
2+
using Windows.ApplicationModel.Activation;
3+
using Windows.UI.Xaml;
4+
using Windows.UI.Xaml.Controls;
5+
6+
namespace DocumentPickerExample
7+
{
8+
sealed partial class App : ReactApplication
9+
{
10+
public App()
11+
{
12+
#if BUNDLE
13+
JavaScriptBundleFile = "index.windows";
14+
InstanceSettings.UseWebDebugger = false;
15+
InstanceSettings.UseFastRefresh = false;
16+
#else
17+
JavaScriptBundleFile = "index";
18+
InstanceSettings.UseWebDebugger = true;
19+
InstanceSettings.UseFastRefresh = true;
20+
#endif
21+
22+
#if DEBUG
23+
InstanceSettings.UseDeveloperSupport = true;
24+
#else
25+
InstanceSettings.UseDeveloperSupport = false;
26+
#endif
27+
28+
Microsoft.ReactNative.Managed.AutolinkedNativeModules.RegisterAutolinkedNativeModulePackages(PackageProviders); // Includes any autolinked modules
29+
30+
PackageProviders.Add(new Microsoft.ReactNative.Managed.ReactPackageProvider());
31+
PackageProviders.Add(new ReactNativeDocumentPicker.ReactPackageProvider());
32+
PackageProviders.Add(new ReactPackageProvider());
33+
InitializeComponent();
34+
}
35+
36+
/// <summary>
37+
/// Invoked when the application is launched normally by the end user. Other entry points
38+
/// will be used such as when the application is launched to open a specific file.
39+
/// </summary>
40+
/// <param name="e">Details about the launch request and process.</param>
41+
protected override void OnLaunched(LaunchActivatedEventArgs e)
42+
{
43+
base.OnLaunched(e);
44+
var frame = (Frame)Window.Current.Content;
45+
frame.Navigate(typeof(MainPage), e.Arguments);
46+
}
47+
48+
/// <summary>
49+
/// Invoked when the application is activated by some means other than normal launching.
50+
/// </summary>
51+
protected override void OnActivated(IActivatedEventArgs e)
52+
{
53+
var preActivationContent = Window.Current.Content;
54+
base.OnActivated(e);
55+
if (preActivationContent == null && Window.Current != null)
56+
{
57+
// Display the initial content
58+
var frame = (Frame)Window.Current.Content;
59+
frame.Navigate(typeof(MainPage), null);
60+
}
61+
}
62+
}
63+
}
1.4 KB
Loading
7.52 KB
Loading

0 commit comments

Comments
 (0)