-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add WinRT example page #415
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ import {TrackPlayerExamplePage} from './examples/TrackPlayerExamplePage'; | |
import {WindowsHelloExamplePage} from './examples/WindowsHelloExamplePage'; | ||
import {ExpanderExamplePage} from './examples/ExpanderExamplePage'; | ||
import {VirtualizedListExamplePage} from './examples/VirtualizedListExamplePage'; | ||
import {WinRTExamplePage} from './examples/WinRTExamplePage'; | ||
|
||
let RNGalleryCategories = [ | ||
'Basic Input', | ||
|
@@ -266,6 +267,12 @@ export const RNGalleryList: Array<IRNGalleryExample> = [ | |
icon: '\uE8A4', | ||
type: 'Layout', | ||
}, | ||
{ | ||
key: 'WinRT', | ||
component: WinRTExamplePage, | ||
icon: '\uEF15', | ||
type: 'Layout', | ||
}, | ||
Comment on lines
+270
to
+275
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI when you have to merge this later, look for: |
||
{ | ||
key: 'Xaml', | ||
component: XamlExamplePage, | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,55 @@ | ||||||||||||||||||||||||||
const Notifications = Windows.UI.Notifications; | ||||||||||||||||||||||||||
const ToastTemplateType = Notifications.ToastTemplateType; | ||||||||||||||||||||||||||
const ToastNotificationManager = Notifications.ToastNotificationManager; | ||||||||||||||||||||||||||
const ToastNotification = Notifications.ToastNotification; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
export function showNotification(notification) { | ||||||||||||||||||||||||||
var type = ToastTemplateType.toastText01; | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I'm surprised we don't have lint rules setup about |
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
var obj = {}; | ||||||||||||||||||||||||||
if (typeof notification === 'string') { | ||||||||||||||||||||||||||
obj.text = notification; | ||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||
obj = notification; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
if (obj.template != undefined) { | ||||||||||||||||||||||||||
type = obj.template; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
var xml = ToastNotificationManager.getTemplateContent(type); | ||||||||||||||||||||||||||
for (var tagName in obj) { | ||||||||||||||||||||||||||
var xmlElements = xml.getElementsByTagName(tagName); | ||||||||||||||||||||||||||
var value = obj[tagName]; | ||||||||||||||||||||||||||
if (typeof value === 'string') { | ||||||||||||||||||||||||||
fillXmlElements(xml, xmlElements, [value]); | ||||||||||||||||||||||||||
} else if (Array.isArray(value)) { | ||||||||||||||||||||||||||
fillXmlElements(xml, xmlElements, value); | ||||||||||||||||||||||||||
} else if (typeof value === 'object') { | ||||||||||||||||||||||||||
fillXmlElements(xml, xmlElements, [value]); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
Comment on lines
+24
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like case 1 and 3 are the same. Is this still correct?
Suggested change
Or do you get types other than string/object in there? (like numeric literals or something) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If your goal is "if it's an array, leave it; otherwise, place in an array" there might be other options. Like:
Does that do the right thing? It definitely spreads a source array into a new array. But for a single item... I think still the same thing? Hmmm... except strings are iterable so that'll break apart the string. Anyway, might be some syntactic magic here. |
||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
var toast = new ToastNotification(xml); | ||||||||||||||||||||||||||
ToastNotificationManager.createToastNotifier().show(toast); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
function fillXmlElements(xml, xmlElements, arr) { | ||||||||||||||||||||||||||
var i = 0; | ||||||||||||||||||||||||||
for (var arrValue of arr) { | ||||||||||||||||||||||||||
var node = xmlElements[i++]; | ||||||||||||||||||||||||||
Comment on lines
+39
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's happening here? Are |
||||||||||||||||||||||||||
if (typeof arrValue === 'string') { | ||||||||||||||||||||||||||
node.appendChild(xml.createTextNode(arrValue)); | ||||||||||||||||||||||||||
} else if (typeof arrValue === 'object') { | ||||||||||||||||||||||||||
for (var attrName in arrValue) { | ||||||||||||||||||||||||||
var attr = node.attributes.getNamedItem(attrName); | ||||||||||||||||||||||||||
if (!attr) { | ||||||||||||||||||||||||||
attr = xml.createAttribute(attrName); | ||||||||||||||||||||||||||
node.attributes.setNamedItem(attr); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
attr.nodeValue = arrValue[attrName]; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,121 @@ | ||||||
'use strict'; | ||||||
import React, {useState} from 'react'; | ||||||
import {Example} from '../components/Example'; | ||||||
import {Page} from '../components/Page'; | ||||||
import { | ||||||
Image, | ||||||
SafeAreaView, | ||||||
StyleSheet, | ||||||
ScrollView, | ||||||
View, | ||||||
Text, | ||||||
StatusBar, | ||||||
Platform, | ||||||
PlatformColor, | ||||||
Pressable, | ||||||
Linking, | ||||||
} from 'react-native'; | ||||||
|
||||||
import {useTheme} from '@react-navigation/native'; | ||||||
|
||||||
import {showNotification} from '../components/Notifications'; | ||||||
|
||||||
export const WinRTExamplePage: React.FunctionComponent<{}> = () => { | ||||||
const {colors} = useTheme(); | ||||||
const example1jsx = ` | ||||||
<View | ||||||
style={{ | ||||||
flexDirection: 'row', | ||||||
flexWrap: 'wrap', | ||||||
alignItems: 'center', | ||||||
}}> | ||||||
<Pressable | ||||||
style={{ | ||||||
width: 200, | ||||||
height: 50, | ||||||
borderRadius: 2, | ||||||
backgroundColor: | ||||||
Platform.OS === 'windows' | ||||||
? PlatformColor('SystemColorButtonFaceColor') | ||||||
: 'silver', | ||||||
}} | ||||||
onPress={() => { | ||||||
showNotification({ | ||||||
template: | ||||||
Windows.UI.Notifications.ToastTemplateType | ||||||
.toastImageAndText01, | ||||||
// The template schema can be found at https://docs.microsoft.com/previous-versions/windows/apps/hh761494(v=win.10) | ||||||
text: 'hello world', | ||||||
image: { | ||||||
src: 'https://microsoft.github.io/react-native-windows/img/header_logo.svg', | ||||||
alt: 'React logo', | ||||||
}, | ||||||
}); | ||||||
}}> | ||||||
<Text | ||||||
style={{ | ||||||
textAlign: 'center', | ||||||
paddingVertical: 15, | ||||||
color: colors.text, | ||||||
}}> | ||||||
Press Me | ||||||
</Text> | ||||||
</Pressable> | ||||||
</View>`; | ||||||
|
||||||
return ( | ||||||
<Page | ||||||
title="WinRT" | ||||||
description="A React Native Windows module that allows use of native (non-XAML) WinRT APIs" | ||||||
componentType="Community" | ||||||
pageCodeUrl="https://github.com/microsoft/react-native-gallery/blob/main/src/examples/WinRTExamplePage.tsx" | ||||||
documentation={[ | ||||||
{ | ||||||
label: 'WinRT Source Code', | ||||||
url: 'https://github.com/asklar/react-native-winrt', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}, | ||||||
]}> | ||||||
<Example title="A Windows Notification example" code={example1jsx}> | ||||||
<View | ||||||
style={{ | ||||||
flexDirection: 'row', | ||||||
flexWrap: 'wrap', | ||||||
alignItems: 'center', | ||||||
}}> | ||||||
<Pressable | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason this doesn't just use a |
||||||
style={{ | ||||||
width: 200, | ||||||
height: 50, | ||||||
borderRadius: 2, | ||||||
backgroundColor: | ||||||
Platform.OS === 'windows' | ||||||
? PlatformColor('SystemColorButtonFaceColor') | ||||||
: 'silver', | ||||||
}} | ||||||
onPress={() => { | ||||||
showNotification({ | ||||||
template: | ||||||
Windows.UI.Notifications.ToastTemplateType | ||||||
.toastImageAndText01, | ||||||
// The template schema can be found at https://docs.microsoft.com/previous-versions/windows/apps/hh761494(v=win.10) | ||||||
text: 'hello world', | ||||||
image: { | ||||||
src: 'https://microsoft.github.io/react-native-windows/img/header_logo.svg', | ||||||
alt: 'React logo', | ||||||
}, | ||||||
}); | ||||||
}}> | ||||||
<Text | ||||||
style={{ | ||||||
textAlign: 'center', | ||||||
paddingVertical: 15, | ||||||
color: colors.text, | ||||||
}}> | ||||||
Press Me | ||||||
</Text> | ||||||
</Pressable> | ||||||
</View> | ||||||
</Example> | ||||||
</Page> | ||||||
); | ||||||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3320,10 +3320,10 @@ | |
resolved "https://registry.yarnpkg.com/@opentelemetry/semantic-conventions/-/semantic-conventions-1.22.0.tgz#d7502533a7c96e25baab86bac965468e0703a8b4" | ||
integrity sha512-CAOgFOKLybd02uj/GhCdEeeBjOS0yeoDeo/CA7ASBSmenpZHAKGB3iDm/rv3BQLcabb/OprDEsSQ1y0P8A7Siw== | ||
|
||
"@react-native-clipboard/clipboard@^1.13.2": | ||
version "1.13.2" | ||
resolved "https://registry.yarnpkg.com/@react-native-clipboard/clipboard/-/clipboard-1.13.2.tgz#28adcfc43ed2addddf79a59198ec1b25087c115e" | ||
integrity sha512-uVM55oEGc6a6ZmSATDeTcMm55A/C1km5X47g0xaoF0Zagv7N/8RGvLceA5L/izPwflIy78t7XQeJUcnGSib0nA== | ||
"@react-native-clipboard/clipboard@^1.14.0": | ||
version "1.14.0" | ||
resolved "https://registry.yarnpkg.com/@react-native-clipboard/clipboard/-/clipboard-1.14.0.tgz#ae3b7b59f51b1da1fc6a362244c18ddec113d1f6" | ||
integrity sha512-kDLfA6HzP4T+kfGTEGdbsc2r4q0xQALshRQp8Ph/5YD5qT4CZdgkQM3oloKHIdh+AVks+QjtVHK1cZ1xb0Or7w== | ||
|
||
"@react-native-community/checkbox@^0.5.16": | ||
version "0.5.16" | ||
|
@@ -9956,6 +9956,11 @@ [email protected]: | |
ws "^6.2.2" | ||
yargs "^17.6.2" | ||
|
||
react-native-winrt@^0.72.1: | ||
version "0.72.1" | ||
resolved "https://registry.yarnpkg.com/react-native-winrt/-/react-native-winrt-0.72.1.tgz#d5b2bc0fe27080c03a85c33bd477b6da3e70f0f9" | ||
integrity sha512-uhUAzKjOFpsfeoByBBA1FTgsCZuwLYN9y9C/Zg+StZRUYVBcqpOT46avwxHKkgWHN1ixoDc/jUFdE5lmV4DuoQ== | ||
|
||
react-native-xaml@^0.0.74: | ||
version "0.0.74" | ||
resolved "https://registry.yarnpkg.com/react-native-xaml/-/react-native-xaml-0.0.74.tgz#fc747308320eb1fda6dd69f5317bfeae37686b57" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.