Skip to content

Commit e5fb04d

Browse files
committed
feat(Windows): Adds initial Windows implementation for ANH
APIs likely to change as other platforms are introduced.
1 parent 2ef292c commit e5fb04d

27 files changed

+978
-0
lines changed

.gitattributes

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
###############################################################################
2+
# Set default behavior to automatically normalize line endings.
3+
###############################################################################
4+
* text=auto
5+
6+
###############################################################################
7+
# Set default behavior for command prompt diff.
8+
#
9+
# This is need for earlier builds of msysgit that does not have it on by
10+
# default for csharp files.
11+
# Note: This is only used by command line
12+
###############################################################################
13+
#*.cs diff=csharp
14+
15+
###############################################################################
16+
# Set the merge driver for project and solution files
17+
#
18+
# Merging from the command prompt will add diff markers to the files if there
19+
# are conflicts (Merging from VS is not affected by the settings below, in VS
20+
# the diff markers are never inserted). Diff markers may cause the following
21+
# file extensions to fail to load in VS. An alternative would be to treat
22+
# these files as binary and thus will always conflict and require user
23+
# intervention with every merge. To do so, just uncomment the entries below
24+
###############################################################################
25+
#*.sln merge=binary
26+
#*.csproj merge=binary
27+
#*.vbproj merge=binary
28+
#*.vcxproj merge=binary
29+
#*.vcproj merge=binary
30+
#*.dbproj merge=binary
31+
#*.fsproj merge=binary
32+
#*.lsproj merge=binary
33+
#*.wixproj merge=binary
34+
#*.modelproj merge=binary
35+
#*.sqlproj merge=binary
36+
#*.wwaproj merge=binary
37+
38+
###############################################################################
39+
# behavior for image files
40+
#
41+
# image files are treated as binary by default.
42+
###############################################################################
43+
#*.jpg binary
44+
#*.png binary
45+
#*.gif binary
46+
47+
###############################################################################
48+
# diff behavior for common document formats
49+
#
50+
# Convert binary document formats to text before diffing them. This feature
51+
# is only available from the command line. Turn it on by uncommenting the
52+
# entries below.
53+
###############################################################################
54+
#*.doc diff=astextplain
55+
#*.DOC diff=astextplain
56+
#*.docx diff=astextplain
57+
#*.DOCX diff=astextplain
58+
#*.dot diff=astextplain
59+
#*.DOT diff=astextplain
60+
#*.pdf diff=astextplain
61+
#*.PDF diff=astextplain
62+
#*.rtf diff=astextplain
63+
#*.RTF diff=astextplain

Playground.windows.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import {
2+
AppRegistry,
3+
NativeModules,
4+
StyleSheet,
5+
Text,
6+
TouchableOpacity,
7+
View,
8+
} from 'react-native';
9+
10+
const NotificationHub = NativeModules.AzureNotificationHub;
11+
const {connectionString, hubName} = require('./config');
12+
13+
import React, {Component} from 'react';
14+
15+
class Playground extends Component
16+
{
17+
register()
18+
{
19+
NotificationHub.register({connectionString, hubName})
20+
.catch(reason => console.warn(reason));
21+
}
22+
23+
unregister()
24+
{
25+
NotificationHub.unregister({connectionString, hubName})
26+
.catch(reason => console.warn(reason));
27+
}
28+
29+
render()
30+
{
31+
return (
32+
<View style={styles.container}>
33+
<TouchableOpacity onPress={this.register.bind(this)}>
34+
<View style={styles.button}>
35+
<Text style={styles.buttonText}>
36+
Register
37+
</Text>
38+
</View>
39+
</TouchableOpacity>
40+
<TouchableOpacity onPress={this.unregister.bind(this)}>
41+
<View style={styles.button}>
42+
<Text style={styles.buttonText}>
43+
Unregister
44+
</Text>
45+
</View>
46+
</TouchableOpacity>
47+
</View>
48+
);
49+
}
50+
}
51+
52+
const styles = StyleSheet.create({
53+
container: {
54+
flex: 1,
55+
justifyContent: 'center',
56+
alignItems: 'center',
57+
},
58+
button: {
59+
backgroundColor: 'blue',
60+
borderRadius: 5,
61+
padding: 10,
62+
margin: 2,
63+
minWidth: 200,
64+
},
65+
buttonText: {
66+
color: 'white',
67+
fontSize: 16,
68+
},
69+
});
70+
71+
AppRegistry.registerComponent('Playground', () => Playground);

config.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"connectionString": "<your Azure Notification Hub connection string>",
3+
"hubName": "<your Azure Notification Hub name>"
4+
}

index.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import {NativeModules} from 'react-native';
2+
module.exports = NativeModules.AzureNotificationHub;

package.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "react-native-azurenotificationhub",
3+
"version": "1.0.0",
4+
"description": "React Native module to support Azure Notification Hub push notifications on Android, iOS, and Windows.",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/rozele/react-native-azurenotificationhub.git"
12+
},
13+
"keywords": [
14+
"Azure",
15+
"React",
16+
"Native",
17+
"Push",
18+
"Notifications",
19+
"Hub"
20+
],
21+
"author": "rozele",
22+
"license": "MIT",
23+
"bugs": {
24+
"url": "https://github.com/rozele/react-native-azurenotificationhub/issues"
25+
},
26+
"homepage": "https://github.com/rozele/react-native-azurenotificationhub#readme",
27+
"devDependencies": {
28+
"react": "^15.3.0",
29+
"react-native": "^0.32.0",
30+
"react-native-windows": "^0.32.0"
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Application
2+
x:Class="Playground.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:Playground"
6+
RequestedTheme="Light">
7+
8+
</Application>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
using ReactNative;
2+
using System;
3+
using Windows.ApplicationModel;
4+
using Windows.ApplicationModel.Activation;
5+
using Windows.UI.Xaml;
6+
using Windows.UI.Xaml.Controls;
7+
using Windows.UI.Xaml.Navigation;
8+
9+
namespace Playground
10+
{
11+
/// <summary>
12+
/// Provides application-specific behavior to supplement the default Application class.
13+
/// </summary>
14+
sealed partial class App : Application
15+
{
16+
private readonly ReactPage _reactPage;
17+
18+
/// <summary>
19+
/// Initializes the singleton application object. This is the first line of authored code
20+
/// executed, and as such is the logical equivalent of main() or WinMain().
21+
/// </summary>
22+
public App()
23+
{
24+
this.InitializeComponent();
25+
this.Suspending += OnSuspending;
26+
this.Resuming += OnResuming;
27+
28+
_reactPage = new MainPage();
29+
}
30+
31+
/// <summary>
32+
/// Invoked when the application is launched normally by the end user. Other entry points
33+
/// will be used such as when the application is launched to open a specific file.
34+
/// </summary>
35+
/// <param name="e">Details about the launch request and process.</param>
36+
protected override void OnLaunched(LaunchActivatedEventArgs e)
37+
{
38+
_reactPage.OnResume(Exit);
39+
40+
#if DEBUG
41+
if (System.Diagnostics.Debugger.IsAttached)
42+
{
43+
this.DebugSettings.EnableFrameRateCounter = true;
44+
}
45+
#endif
46+
Frame rootFrame = Window.Current.Content as Frame;
47+
48+
// Do not repeat app initialization when the Window already has content,
49+
// just ensure that the window is active
50+
if (rootFrame == null)
51+
{
52+
_reactPage.OnCreate(e.Arguments);
53+
54+
// Create a Frame to act as the navigation context and navigate to the first page
55+
rootFrame = new Frame();
56+
57+
rootFrame.NavigationFailed += OnNavigationFailed;
58+
59+
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
60+
{
61+
//TODO: Load state from previously suspended application
62+
}
63+
64+
// Place the frame in the current Window
65+
Window.Current.Content = rootFrame;
66+
}
67+
68+
if (e.PrelaunchActivated == false)
69+
{
70+
if (rootFrame.Content == null)
71+
{
72+
// When the navigation stack isn't restored navigate to the first page,
73+
// configuring the new page by passing required information as a navigation
74+
// parameter
75+
rootFrame.Content = _reactPage;
76+
}
77+
// Ensure the current window is active
78+
Window.Current.Activate();
79+
}
80+
}
81+
82+
/// <summary>
83+
/// Invoked when Navigation to a certain page fails
84+
/// </summary>
85+
/// <param name="sender">The Frame which failed navigation</param>
86+
/// <param name="e">Details about the navigation failure</param>
87+
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
88+
{
89+
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
90+
}
91+
92+
/// <summary>
93+
/// Invoked when application execution is being suspended. Application state is saved
94+
/// without knowing whether the application will be terminated or resumed with the contents
95+
/// of memory still intact.
96+
/// </summary>
97+
/// <param name="sender">The source of the suspend request.</param>
98+
/// <param name="e">Details about the suspend request.</param>
99+
private void OnSuspending(object sender, SuspendingEventArgs e)
100+
{
101+
var deferral = e.SuspendingOperation.GetDeferral();
102+
_reactPage.OnSuspend();
103+
deferral.Complete();
104+
}
105+
106+
private void OnResuming(object sender, object e)
107+
{
108+
_reactPage.OnResume(Exit);
109+
}
110+
}
111+
}
Loading
Loading
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using ReactNative;
2+
using ReactNative.Modules.Core;
3+
using ReactNative.Shell;
4+
using ReactWindowsAzureNotificationHub;
5+
using System.Collections.Generic;
6+
7+
namespace Playground
8+
{
9+
class MainPage : ReactPage
10+
{
11+
public override string MainComponentName
12+
{
13+
get
14+
{
15+
return "Playground";
16+
}
17+
}
18+
19+
public override string JavaScriptMainModuleName
20+
{
21+
get
22+
{
23+
return "Playground";
24+
}
25+
}
26+
27+
public override List<IReactPackage> Packages
28+
{
29+
get
30+
{
31+
return new List<IReactPackage>
32+
{
33+
new MainReactPackage(),
34+
new ReactAzureNotificationHubPackage(),
35+
};
36+
}
37+
}
38+
39+
public override bool UseDeveloperSupport
40+
{
41+
get
42+
{
43+
return true;
44+
}
45+
}
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp">
3+
<Identity Name="24620EricRozell.ReactNativeAzureNotificationHubTes" Publisher="CN=1CD927F1-C3A6-4C2C-8282-63E9FC79A416" Version="1.1.0.0" />
4+
<mp:PhoneIdentity PhoneProductId="db8d2264-2e38-4e28-a268-ef50866a2733" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
5+
<Properties>
6+
<DisplayName>React Native Azure Notification Hub Test</DisplayName>
7+
<PublisherDisplayName>Eric Rozell</PublisherDisplayName>
8+
<Logo>Assets\StoreLogo.png</Logo>
9+
</Properties>
10+
<Dependencies>
11+
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
12+
</Dependencies>
13+
<Resources>
14+
<Resource Language="x-generate" />
15+
</Resources>
16+
<Applications>
17+
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="Playground.App">
18+
<uap:VisualElements DisplayName="React Native Azure Notification Hub Test" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="Playground" BackgroundColor="transparent">
19+
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png">
20+
</uap:DefaultTile>
21+
<uap:SplashScreen Image="Assets\SplashScreen.png" />
22+
</uap:VisualElements>
23+
</Application>
24+
</Applications>
25+
<Capabilities>
26+
<Capability Name="internetClient" />
27+
</Capabilities>
28+
</Package>

0 commit comments

Comments
 (0)