Skip to content

Commit 3dd9e0e

Browse files
authored
feat: Add Windows AsyncStorage (#327)
* Add Windows AsyncStorage
1 parent e7e3a4f commit 3dd9e0e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2494
-663
lines changed

docs/Linking.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,14 @@ protected List<ReactPackage> getPackages() {
6969
);
7070
}
7171
```
72+
## Windows
73+
### Add `ReactNativeAsnycStorage` project to your solution.
74+
1. Open your solution in Visual Studio.
75+
2. Right click Solution icon in Solution Explorer > Add > Existing Project.
76+
Select `node_modules\@react-native-community\async-storage\windows\ReactNativeAsyncStorage\ReactNativeAsyncStorage.vcxproj`
77+
78+
### Add a reference to `ReactNativeAsyncStorage` in your main application project.
79+
1. Right click main application project > Add > Reference...
80+
Check `ReactNativeAsyncStorage` from Solution Projects.
81+
2. Add `#include "winrt/ReactNativeAsyncStorage.h"` to `pch.h`.
82+
3. Add `PackageProviders().Append(winrt::ReactNativeAscynStorage::ReactPackageProvider());` before `InitializeComponent();` in `app.cpp`.

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/AsyncStorageExample.sln

Lines changed: 228 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "pch.h"
2+
#include "App.h"
3+
#include "ReactPackageProvider.h"
4+
5+
using namespace winrt::AsyncStorageExample;
6+
using namespace winrt::AsyncStorageExample::implementation;
7+
8+
/// <summary>
9+
/// Initializes the singleton application object. This is the first line of
10+
/// authored code executed, and as such is the logical equivalent of main() or
11+
/// WinMain().
12+
/// </summary>
13+
App::App() noexcept
14+
{
15+
MainComponentName(L"AsyncStorageExample");
16+
17+
#if BUNDLE
18+
JavaScriptBundleFile(L"index.windows");
19+
InstanceSettings().UseWebDebugger(false);
20+
InstanceSettings().UseFastRefresh(false);
21+
#else
22+
JavaScriptMainModuleName(L"example/index");
23+
InstanceSettings().UseWebDebugger(true);
24+
InstanceSettings().UseFastRefresh(true);
25+
#endif
26+
27+
#if _DEBUG
28+
InstanceSettings().EnableDeveloperMenu(true);
29+
#else
30+
InstanceSettings().EnableDeveloperMenu(false);
31+
#endif
32+
33+
PackageProviders().Append(make<ReactPackageProvider>()); // Includes all modules in this project
34+
PackageProviders().Append(winrt::ReactNativeAsyncStorage::ReactPackageProvider());
35+
36+
REACT_REGISTER_NATIVE_MODULE_PACKAGES(); //code-gen macro from autolink
37+
38+
InitializeComponent();
39+
40+
// This works around a cpp/winrt bug with composable/aggregable types tracked
41+
// by 22116519
42+
AddRef();
43+
m_inner.as<::IUnknown>()->Release();
44+
}
45+
46+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
#include "App.xaml.g.h"
4+
5+
namespace winrt::AsyncStorageExample::implementation
6+
{
7+
struct App : AppT<App>
8+
{
9+
App() noexcept;
10+
};
11+
} // namespace winrt::AsyncStorageExample::implementation
12+
13+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace AsyncStorageExample
2+
{
3+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<react:ReactApplication
2+
x:Class="AsyncStorageExample.App"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:AsyncStorageExample"
6+
xmlns:react="using:Microsoft.ReactNative">
7+
<Application.Resources>
8+
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
9+
</Application.Resources>
10+
</react:ReactApplication>
Loading
Loading
Loading

0 commit comments

Comments
 (0)