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

Diff for: docs/Linking.md

+11
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`.

Diff for: example/windows/.gitignore

+92
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+

Diff for: example/windows/AsyncStorageExample.sln

+228
Large diffs are not rendered by default.

Diff for: example/windows/AsyncStorageExample/App.cpp

+46
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+

Diff for: example/windows/AsyncStorageExample/App.h

+13
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+

Diff for: example/windows/AsyncStorageExample/App.idl

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace AsyncStorageExample
2+
{
3+
}

Diff for: example/windows/AsyncStorageExample/App.xaml

+10
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
Loading
Loading
1.42 KB
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.props')" />
4+
<PropertyGroup Label="Globals">
5+
<CppWinRTOptimized>true</CppWinRTOptimized>
6+
<CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
7+
<MinimalCoreWin>true</MinimalCoreWin>
8+
<ProjectGuid>{2337bc5e-985c-4b3b-acd7-c9e2fb5d3209}</ProjectGuid>
9+
<ProjectName>AsyncStorageExample</ProjectName>
10+
<RootNamespace>AsyncStorageExample</RootNamespace>
11+
<DefaultLanguage>en-US</DefaultLanguage>
12+
<MinimumVisualStudioVersion>15.0</MinimumVisualStudioVersion>
13+
<AppContainerApplication>true</AppContainerApplication>
14+
<ApplicationType>Windows Store</ApplicationType>
15+
<ApplicationTypeRevision>10.0</ApplicationTypeRevision>
16+
<WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0.18362.0</WindowsTargetPlatformVersion>
17+
<WindowsTargetPlatformMinVersion>10.0.15063.0</WindowsTargetPlatformMinVersion>
18+
<PackageCertificateKeyFile>AsyncStorageExample_TemporaryKey.pfx</PackageCertificateKeyFile>
19+
<PackageCertificateThumbprint>6D20FDF32BD30D0DD6A435E6134297ED6037C34E</PackageCertificateThumbprint>
20+
<PackageCertificatePassword>password</PackageCertificatePassword>
21+
</PropertyGroup>
22+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
23+
<ItemGroup Label="ProjectConfigurations">
24+
<ProjectConfiguration Include="Debug|ARM">
25+
<Configuration>Debug</Configuration>
26+
<Platform>ARM</Platform>
27+
</ProjectConfiguration>
28+
<ProjectConfiguration Include="Debug|ARM64">
29+
<Configuration>Debug</Configuration>
30+
<Platform>ARM64</Platform>
31+
</ProjectConfiguration>
32+
<ProjectConfiguration Include="Debug|Win32">
33+
<Configuration>Debug</Configuration>
34+
<Platform>Win32</Platform>
35+
</ProjectConfiguration>
36+
<ProjectConfiguration Include="Debug|x64">
37+
<Configuration>Debug</Configuration>
38+
<Platform>x64</Platform>
39+
</ProjectConfiguration>
40+
<ProjectConfiguration Include="Release|ARM">
41+
<Configuration>Release</Configuration>
42+
<Platform>ARM</Platform>
43+
</ProjectConfiguration>
44+
<ProjectConfiguration Include="Release|ARM64">
45+
<Configuration>Release</Configuration>
46+
<Platform>ARM64</Platform>
47+
</ProjectConfiguration>
48+
<ProjectConfiguration Include="Release|Win32">
49+
<Configuration>Release</Configuration>
50+
<Platform>Win32</Platform>
51+
</ProjectConfiguration>
52+
<ProjectConfiguration Include="Release|x64">
53+
<Configuration>Release</Configuration>
54+
<Platform>x64</Platform>
55+
</ProjectConfiguration>
56+
</ItemGroup>
57+
<PropertyGroup Label="Configuration">
58+
<ConfigurationType>Application</ConfigurationType>
59+
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
60+
<CharacterSet>Unicode</CharacterSet>
61+
</PropertyGroup>
62+
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
63+
<UseDebugLibraries>true</UseDebugLibraries>
64+
<LinkIncremental>true</LinkIncremental>
65+
</PropertyGroup>
66+
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
67+
<UseDebugLibraries>false</UseDebugLibraries>
68+
<WholeProgramOptimization>true</WholeProgramOptimization>
69+
<LinkIncremental>false</LinkIncremental>
70+
</PropertyGroup>
71+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
72+
<ImportGroup Label="ExtensionSettings">
73+
</ImportGroup>
74+
<ImportGroup Label="Shared">
75+
<Import Project="..\..\..\node_modules\react-native-windows\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems" Label="Shared" />
76+
</ImportGroup>
77+
<ImportGroup Label="PropertySheets">
78+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
79+
</ImportGroup>
80+
<ImportGroup Label="PropertySheets">
81+
<Import Project="PropertySheet.props" />
82+
</ImportGroup>
83+
<PropertyGroup Label="UserMacros" />
84+
<ItemDefinitionGroup>
85+
<ClCompile>
86+
<PrecompiledHeader>Use</PrecompiledHeader>
87+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
88+
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
89+
<WarningLevel>Level4</WarningLevel>
90+
<AdditionalOptions>%(AdditionalOptions) /bigobj</AdditionalOptions>
91+
<DisableSpecificWarnings>4453;28204</DisableSpecificWarnings>
92+
</ClCompile>
93+
</ItemDefinitionGroup>
94+
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
95+
<ClCompile>
96+
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
97+
</ClCompile>
98+
</ItemDefinitionGroup>
99+
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
100+
<ClCompile>
101+
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
102+
</ClCompile>
103+
</ItemDefinitionGroup>
104+
<ItemGroup>
105+
<ClInclude Include="ReactPackageProvider.h" />
106+
<ClInclude Include="pch.h" />
107+
<ClInclude Include="App.h">
108+
<DependentUpon>App.xaml</DependentUpon>
109+
</ClInclude>
110+
</ItemGroup>
111+
<ItemGroup>
112+
<ApplicationDefinition Include="App.xaml">
113+
<SubType>Designer</SubType>
114+
</ApplicationDefinition>
115+
</ItemGroup>
116+
<ItemGroup>
117+
<AppxManifest Include="Package.appxmanifest">
118+
<SubType>Designer</SubType>
119+
</AppxManifest>
120+
</ItemGroup>
121+
<ItemGroup>
122+
<Image Include="Assets\LockScreenLogo.scale-200.png" />
123+
<Image Include="Assets\SplashScreen.scale-200.png" />
124+
<Image Include="Assets\Square150x150Logo.scale-200.png" />
125+
<Image Include="Assets\Square44x44Logo.scale-200.png" />
126+
<Image Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
127+
<Image Include="Assets\StoreLogo.png" />
128+
<Image Include="Assets\Wide310x150Logo.scale-200.png" />
129+
</ItemGroup>
130+
<ItemGroup>
131+
<ClCompile Include="ReactPackageProvider.cpp" />
132+
<ClCompile Include="pch.cpp">
133+
<PrecompiledHeader>Create</PrecompiledHeader>
134+
</ClCompile>
135+
<ClCompile Include="App.cpp">
136+
<DependentUpon>App.xaml</DependentUpon>
137+
</ClCompile>
138+
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
139+
</ItemGroup>
140+
<ItemGroup>
141+
<Midl Include="App.idl">
142+
<DependentUpon>App.xaml</DependentUpon>
143+
</Midl>
144+
</ItemGroup>
145+
<ItemGroup>
146+
<None Include="packages.config" />
147+
<None Include="PropertySheet.props" />
148+
<Text Include="readme.txt">
149+
<DeploymentContent>false</DeploymentContent>
150+
</Text>
151+
</ItemGroup>
152+
<ItemGroup>
153+
<ProjectReference Include="..\..\..\node_modules\react-native-windows\Microsoft.ReactNative\Microsoft.ReactNative.vcxproj">
154+
<Project>{f7d32bd0-2749-483e-9a0d-1635ef7e3136}</Project>
155+
</ProjectReference>
156+
<ProjectReference Include="..\..\..\windows\ReactNativeAsyncStorage\ReactNativeAsyncStorage.vcxproj">
157+
<Project>{4855d892-e16c-404d-8286-0089e0f7f9c4}</Project>
158+
</ProjectReference>
159+
</ItemGroup>
160+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
161+
<PropertyGroup>
162+
<BundleCommand>
163+
npx --no-install react-native bundle --platform windows --entry-file index.js --bundle-output $(MSBuildThisFileDirectory)/Bundle/index.windows.bundle --assets-dest $(MSBuildThisFileDirectory)/Bundle
164+
</BundleCommand>
165+
</PropertyGroup>
166+
<Import Project="..\..\..\node_modules\react-native-windows\PropertySheets\Bundle.Cpp.targets" />
167+
<ImportGroup Label="ExtensionTargets">
168+
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.targets')" />
169+
<Import Project="..\packages\Microsoft.UI.Xaml.2.3.191129002\build\native\Microsoft.UI.Xaml.targets" Condition="Exists('..\packages\Microsoft.UI.Xaml.2.3.191129002\build\native\Microsoft.UI.Xaml.targets')" />
170+
</ImportGroup>
171+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
172+
<PropertyGroup>
173+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
174+
</PropertyGroup>
175+
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.props'))" />
176+
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.targets'))" />
177+
<Error Condition="!Exists('..\packages\Microsoft.UI.Xaml.2.3.191129002\build\native\Microsoft.UI.Xaml.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.UI.Xaml.2.3.191129002\build\native\Microsoft.UI.Xaml.targets'))" />
178+
</Target>
179+
</Project>

0 commit comments

Comments
 (0)