Skip to content

Commit c233b9a

Browse files
Merge main with 0.66 release (#149)
* Update sample to use nuget.org (#143) * Update project url on nuget.org (#145) * Link to nuget packages in the README * fix typo (#140) * Add version info (#139) * edits to readme (#146) * updates * Update README.md * feedback * Copy notifications code to sample (#147) * Copy notifications code to sample * Button is not needed * update sample image/readme (#148) * update image and readme * Update sample-app.png * Update sample-app.png Co-authored-by: angelazhangmsft <angzhang@microsoft.com>
1 parent 9ffb50c commit c233b9a

9 files changed

Lines changed: 119 additions & 13 deletions

File tree

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,33 @@
22

33
React Native WinRT is a module for [React Native for Windows](https://microsoft.github.io/react-native-windows/) developers who want to call native (non-XAML) WinRT APIs in their apps. It uses components from [xlang](https://github.com/Microsoft/xlang) to [parse metadata](https://github.com/microsoft/winmd) for public or private WinRT COM APIs and generate JSI (JavaScript Interface) wrappers for [C++/WinRT](https://github.com/microsoft/cppwinrt) types at compile-time. The code generator was itself derived from `cppwinrt.exe`.
44

5-
This repo generates the **Microsoft.ReactNative.WinRT** NuGet package for specific versions of React Native Windows.
5+
This repo generates the [Microsoft.ReactNative.WinRT NuGet packages](https://www.nuget.org/packages/Microsoft.ReactNative.WinRT) for specific versions of React Native Windows.
66

77
## Getting started
88

99
Refer to the [usage docs](docs/USAGE.md) for instructions on how to use React Native WinRT in your React Native Windows app to call projected WinRT APIs in Javascript.
1010

1111
### Sample code
1212

13-
See the [sample app](/samples/RNWinRTTestApp/) for an example of using the **Microsoft.ReactNative.WinRT** package to consume WinRT APIs.
13+
See the [sample app](/samples/RNWinRTTestApp/) for an example of using React Native WinRT to consume WinRT APIs.
14+
15+
<img src="samples/RNWinRTTestApp/images/sample-app.png" width="500">
16+
17+
*Note: This is an example of the sample app. The image is pulled from the user's photo library and will likely be different.*
18+
19+
## Versioning
20+
21+
The versioning scheme for React Native WinRT aligns with versions of React Native for Windows. A new major version of React Native for Windows is not guaranteed to be supported by a mismatched version of React Native WinRT. For example, a React Native for Windows 0.67 app may not be compatible with **Microsoft.ReactNative.WinRT** 0.66.* package versions due to potential breaking changes.
22+
23+
React Native WinRT currently supports the following versions of React Native for Windows:
24+
25+
- [release/0.66](https://github.com/microsoft/react-native-winrt/tree/release/0.66)
26+
- [release/0.65](https://github.com/microsoft/react-native-winrt/tree/release/0.65)
27+
- [release/0.64](https://github.com/microsoft/react-native-winrt/tree/release/0.64)
1428

1529
## Contributing
1630

17-
This project welcomes contributions and suggestions of all types. See our [Contributor's Guide](/CONTRIBUTING.md) for more information.
31+
_We want to hear from you!_ File a [new issue](https://github.com/microsoft/react-native-winrt/issues/new) to report a bug, ask a question, or make a suggestion. See our [Contributor's Guide](/CONTRIBUTING.md) for more information.
1832

1933
## Trademarks
2034

docs/USAGE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ The following steps demonstrate how to use the Microsoft.ReactNative.WinRT NuGet
6868
- When running Debug, you may see the error: "ReferenceError: Windows is not defined". The browser debugger is not supported with React Native Windows, so you may need to change this line in `App.cpp`:
6969

7070
```cpp
71-
`InstanceSettings().UseWebDebugger(true);`
71+
InstanceSettings().UseWebDebugger(true);
7272
```
7373
to this:
7474
```cpp
75-
`InstanceSettings().UseWebDebugger(false);`
75+
InstanceSettings().UseWebDebugger(false);
7676
```

rnwinrt/README

Lines changed: 0 additions & 2 deletions
This file was deleted.

rnwinrt/nuget/Microsoft.ReactNative.WinRT.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<tags>RN WinRT RNW rnwinrt WinMD xlang</tags>
1313
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
1414
<license type="file">LICENSE</license>
15-
<projectUrl>https://github.com/microsoft/react-native-windows/tree/main/</projectUrl>
15+
<projectUrl>https://github.com/microsoft/react-native-winrt</projectUrl>
1616
</metadata>
1717
<files>
1818
<file src="LICENSE"/>
@@ -25,4 +25,4 @@
2525
<file src="$reactnative_files$\WinRTTurboModule.targets" target="build\native" />
2626
<file src="$reactnative_files$\WinRTTurboModule.props" target="build\native" />
2727
</files>
28-
</package>
28+
</package>

samples/RNWinRTTestApp/App.tsx

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation.
1+
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

44
import React from "react";
@@ -10,18 +10,21 @@ import {
1010
View,
1111
Text,
1212
StatusBar,
13+
Pressable,
1314
} from "react-native";
1415

1516
import {
1617
Colors,
1718
Header,
1819
} from "react-native/Libraries/NewAppScreen";
1920

21+
import {showNotification} from './Notifications'
22+
2023
async function updateJumpListAsync(): Promise<void> {
2124
try {
2225
const StartScreenApi = Windows.UI.StartScreen;
2326
const jumplist = await StartScreenApi.JumpList.loadCurrentAsync();
24-
27+
2528
jumplist.systemGroupKind = StartScreenApi.JumpListSystemGroupKind.recent;
2629

2730
const items = jumplist.items;
@@ -97,7 +100,7 @@ async function getPictureThumbnailAsync(): Promise<string> {
97100

98101
const library = StorageApi.KnownFolders.picturesLibrary;
99102
let files = await library.getFilesAsync();
100-
103+
101104
let file: StorageApi.StorageFile | null = null;
102105
if (files.size > 0) {
103106
file = files.getAt(0);
@@ -199,6 +202,27 @@ const App = () => {
199202
</Text>
200203
</View>
201204
</View>
205+
<View style={styles.body}>
206+
<View style={styles.sectionContainer}>
207+
<Text style={styles.sectionTitle}>Windows.UI.Notifications Example</Text>
208+
<View style={{ flexDirection: 'row', flexWrap: 'wrap', alignItems: 'center' }}>
209+
<Text style={[{ paddingRight: 10 }, styles.sectionDescription]}>Click the button to show a notification: </Text>
210+
<Pressable style={styles.sectionDescriptionButton} onPress={() => {
211+
showNotification({
212+
template: Windows.UI.Notifications.ToastTemplateType.toastImageAndText01,
213+
// The template schema can be found at https://docs.microsoft.com/previous-versions/windows/apps/hh761494(v=win.10)
214+
text: "hello world",
215+
image: {
216+
src: "https://microsoft.github.io/react-native-windows/img/header_logo.svg",
217+
alt: "React logo",
218+
}
219+
});
220+
}}>
221+
<Text style={styles.sectionDescriptionButtonText}>Press</Text>
222+
</Pressable>
223+
</View>
224+
</View>
225+
</View>
202226
<View style={styles.body}>
203227
<View style={styles.sectionContainer}>
204228
<Text style={styles.sectionTitle}>Windows.Storage API + picturesLibrary capability Example</Text>
@@ -241,6 +265,19 @@ const styles = StyleSheet.create({
241265
fontWeight: "400",
242266
color: Colors.dark,
243267
},
268+
sectionDescriptionButton: {
269+
alignItems: 'center',
270+
justifyContent: 'center',
271+
paddingVertical: 4,
272+
paddingHorizontal: 24,
273+
borderRadius: 1,
274+
backgroundColor: Colors.light,
275+
},
276+
sectionDescriptionButtonText: {
277+
fontSize: 18,
278+
fontWeight: "400",
279+
color: Colors.dark,
280+
},
244281
highlight: {
245282
fontWeight: "700",
246283
},
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
const Notifications = Windows.UI.Notifications;
3+
const ToastTemplateType = Notifications.ToastTemplateType;
4+
const ToastNotificationManager = Notifications.ToastNotificationManager;
5+
const ToastNotification = Notifications.ToastNotification;
6+
7+
export function showNotification(notification) {
8+
var type = ToastTemplateType.toastText01;
9+
10+
var obj = {};
11+
if (typeof(notification) == 'string') {
12+
obj['text'] = notification;
13+
} else {
14+
obj = notification;
15+
}
16+
17+
if (obj.template != undefined) {
18+
type = obj.template;
19+
}
20+
21+
var xml = ToastNotificationManager.getTemplateContent(type);
22+
for (var tagName in obj) {
23+
var xmlElements = xml.getElementsByTagName(tagName);
24+
var value = obj[tagName];
25+
if (typeof(value) == 'string') {
26+
fillXmlElements(xml, xmlElements, [value]);
27+
} else if (Array.isArray(value)) {
28+
fillXmlElements(xml, xmlElements, value);
29+
} else if (typeof(value) == 'object') {
30+
fillXmlElements(xml, xmlElements, [value]);
31+
}
32+
}
33+
34+
var toast = new ToastNotification(xml);
35+
ToastNotificationManager.createToastNotifier().show(toast);
36+
}
37+
38+
function fillXmlElements(xml, xmlElements, arr) {
39+
var i = 0;
40+
for (var arrValue of arr) {
41+
var node = xmlElements[i++];
42+
if (typeof(arrValue) == 'string') {
43+
node.appendChild(xml.createTextNode(arrValue));
44+
} else if (typeof(arrValue) == 'object') {
45+
for (var attrName in arrValue) {
46+
var attr = node.attributes.getNamedItem(attrName);
47+
if (!attr) {
48+
attr = xml.createAttribute(attrName);
49+
node.attributes.setNamedItem(attr);
50+
}
51+
52+
attr.nodeValue = arrValue[attrName];
53+
}
54+
}
55+
}
56+
}

samples/RNWinRTTestApp/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The WinRT APIs demonstrated in this sample include:
77
- `Windows.Foundation.Uri`
88
- `Windows.Storage`
99
- `Windows.Foundation.Diagnostics`
10+
- `Windows.UI.Notifications`
1011

1112
## Prerequisites
1213

-177 KB
Loading

samples/RNWinRTTestApp/windows/WinRTTurboModule/WinRTTurboModule.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
2222
<CppWinRTGenerateWindowsMetadata>true</CppWinRTGenerateWindowsMetadata>
2323
<CppWinRTParameters>-base</CppWinRTParameters>
24-
<RnWinRTParameters>-include Windows.Foundation -include Windows.UI.StartScreen -include Windows.UI.ViewManagement -include Windows.Storage -include Windows.Security.Cryptography.CryptographicBuffer -include Windows.Security.Cryptography.ICryptographicBufferStatics -include Windows.Security.Cryptography.BinaryStringEncoding</RnWinRTParameters>
24+
<RnWinRTParameters>-include Windows.Foundation -include Windows.UI.StartScreen -include Windows.UI.ViewManagement -include Windows.Storage -include Windows.Security.Cryptography.CryptographicBuffer -include Windows.Security.Cryptography.ICryptographicBufferStatics -include Windows.Security.Cryptography.BinaryStringEncoding -include Windows.UI.Notifications -include Windows.Data.Xml.Dom</RnWinRTParameters>
2525
</PropertyGroup>
2626
<PropertyGroup Label="ReactNativeWindowsProps">
2727
<ReactNativeWindowsDir Condition="'$(ReactNativeWindowsDir)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(SolutionDir), 'node_modules\react-native-windows\package.json'))\node_modules\react-native-windows\</ReactNativeWindowsDir>

0 commit comments

Comments
 (0)