Skip to content

Commit ecc6666

Browse files
committed
chore: plugin and demo schematics
1 parent 3bd2438 commit ecc6666

File tree

80 files changed

+3423
-155
lines changed

Some content is hidden

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

80 files changed

+3423
-155
lines changed

.npsrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"config": "./tools/workspace-scripts.js"
3+
}

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
/dist
44
/coverage
5+
native-src

.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2+
"useTabs": true,
3+
"printWidth": 600,
4+
"tabWidth": 2,
25
"singleQuote": true
36
}

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: node_js
2+
node_js:
3+
- "node"
4+
script:
5+
- npm run setup
6+
- npm start @nativescript.build-all

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,14 @@ npm run setup
55
npm start
66
```
77

8-
- @nativescript/local-notifications
9-
- @nativescript/shared-notification-delegate
8+
* @nativescript/email
9+
* @nativescript/local-notifications
10+
* @nativescript/shared-notification-delegate
11+
12+
# How to contribute?
13+
14+
* [Intro]()
15+
* [Fix a bug]()
16+
* [Add a new package]()
17+
18+

apps/demo/references.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/// <reference path="./node_modules/@nativescript/core/global-types.d.ts" />
1+
/// <reference path="../../references.d.ts" />

apps/demo/src/app.css

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
@import '~nativescript-theme-core/css/core.light.css';
2-
3-
.btn {
4-
font-size: 18;
5-
}
1+
@import '~nativescript-theme-core/css/core.light.css';

apps/demo/src/main-page.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
<StackLayout class="p-20">
77
<ScrollView class="h-full">
88
<StackLayout>
9-
<Button text="local-notifications" tap="{{ viewDemo }}" class="btn view-demo"/>
9+
<Button text="local-notifications" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
10+
<Button text="email" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
11+
<Button text="shared-notification-delegate" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
1012

1113
</StackLayout>
1214
</ScrollView>

apps/demo/src/plugin-demos/email.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Observable, EventData, Page } from '@nativescript/core';
2+
import { compose } from '@nativescript/email';
3+
4+
export function navigatingTo(args: EventData) {
5+
const page = <Page>args.object;
6+
page.bindingContext = new DemoModel();
7+
}
8+
9+
export class DemoModel extends Observable {
10+
testIt() {
11+
compose({
12+
subject: 'Yo',
13+
body: 'Hello <strong>dude</strong> :)',
14+
to: ['eddyverbruggen@gmail.com', 'to@person2.com'],
15+
cc: ['ccperson@somewhere.com'],
16+
bcc: ['eddy@combidesk.com', 'eddy@x-services.nl'],
17+
attachments: [
18+
{
19+
fileName: 'arrow1.png',
20+
path:
21+
'base64://iVBORw0KGgoAAAANSUhEUgAAABYAAAAoCAYAAAD6xArmAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAHGlET1QAAAACAAAAAAAAABQAAAAoAAAAFAAAABQAAAB5EsHiAAAAAEVJREFUSA1iYKAimDhxYjwIU9FIBgaQgZMmTfoPwlOmTJGniuHIhlLNxaOGwiNqNEypkwlGk9RokoIUfaM5ijo5Clh9AAAAAP//ksWFvgAAAEFJREFUY5g4cWL8pEmT/oMwiM1ATTBqONbQHA2W0WDBGgJYBUdTy2iwYA0BrILDI7VMmTJFHqv3yBUEBQsIg/QDAJNpcv6v+k1ZAAAAAElFTkSuQmCC',
22+
mimeType: 'image/png',
23+
},
24+
// {
25+
// fileName: 'logo.png',
26+
// path: logoPath,
27+
// mimeType: 'image/png',
28+
// },
29+
],
30+
}).then(
31+
function () {
32+
console.log('Email composer closed');
33+
},
34+
function (err) {
35+
console.log('Error: ' + err);
36+
}
37+
);
38+
}
39+
}

apps/demo/src/plugin-demos/email.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" class="page">
2+
<Page.actionBar>
3+
<ActionBar title="email" icon="" class="action-bar">
4+
</ActionBar>
5+
</Page.actionBar>
6+
<StackLayout class="p-20">
7+
<ScrollView class="h-full">
8+
<StackLayout>
9+
<Button text="Test Plugin" tap="{{ testIt }}" class="btn btn-primary"/>
10+
11+
</StackLayout>
12+
</ScrollView>
13+
</StackLayout>
14+
</Page>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { Observable, EventData, Page, isIOS } from '@nativescript/core';
2+
import { SharedNotificationDelegate } from '@nativescript/shared-notification-delegate';
3+
4+
export function navigatingTo(args: EventData) {
5+
const page = <Page>args.object;
6+
page.bindingContext = new DemoModel();
7+
}
8+
9+
export let invokeOnRunLoop = (function () {
10+
const runloop = CFRunLoopGetMain();
11+
return function (func) {
12+
CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, func);
13+
CFRunLoopWakeUp(runloop);
14+
};
15+
}());
16+
17+
export class DemoModel extends Observable {
18+
19+
message: string;
20+
notificationCenter: UNUserNotificationCenter;
21+
22+
constructor() {
23+
super();
24+
if (isIOS) {
25+
this.set("message", "initializing");
26+
this.notificationCenter = UNUserNotificationCenter.currentNotificationCenter();
27+
this.notificationCenter
28+
.requestAuthorizationWithOptionsCompletionHandler(UNAuthorizationOptions.Alert, (granted, error) => {
29+
if (!granted) {
30+
this.setMessageMainLoop("notification authorization must be set");
31+
return;
32+
}
33+
this.addObservers();
34+
this.setMessageMainLoop("initialized");
35+
this.scheduleNotification();
36+
});
37+
} else {
38+
this.set("message", "This application will only work in iOS");
39+
console.log("This application will only work in iOS");
40+
}
41+
}
42+
43+
addObservers() {
44+
SharedNotificationDelegate.addObserver({
45+
userNotificationCenterWillPresentNotificationWithCompletionHandler: (ncenter, notification, handler, next) => {
46+
// console.log(ncenter, notification);
47+
console.log("notification received by observer 1");
48+
this.setMessageMainLoop(`notification received\n${notification.request.content.title}\n${notification.request.content.body}`);
49+
next();
50+
}
51+
});
52+
SharedNotificationDelegate.addObserver({
53+
userNotificationCenterWillPresentNotificationWithCompletionHandler: (ncenter, notification, handler, next) => {
54+
// console.log(ncenter, notification);
55+
console.log("notification received by observer 2 with priority 1");
56+
this.setMessageMainLoop(`notification received\n${notification.request.content.title}\n${notification.request.content.body}`);
57+
next();
58+
}
59+
}, 1);
60+
}
61+
62+
scheduleNotification() {
63+
const content = UNMutableNotificationContent.new();
64+
content.title = "Test title";
65+
content.body = "Test body";
66+
const trigger = UNTimeIntervalNotificationTrigger.triggerWithTimeIntervalRepeats(5, false);
67+
const id = "UYLLocalNotification";
68+
const request = UNNotificationRequest.requestWithIdentifierContentTrigger(id, content, trigger);
69+
this.notificationCenter.addNotificationRequestWithCompletionHandler(request, (e) => {
70+
if (e) {
71+
console.log(e);
72+
return;
73+
}
74+
console.log("notification scheduled");
75+
});
76+
}
77+
78+
setMessageMainLoop(m: string) {
79+
invokeOnRunLoop(() => {
80+
this.set("message", m);
81+
});
82+
}
83+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" class="page">
2+
<Page.actionBar>
3+
<ActionBar title="shared-notification-delegate" icon="" class="action-bar">
4+
</ActionBar>
5+
</Page.actionBar>
6+
<StackLayout class="p-20">
7+
<ScrollView class="h-full">
8+
<StackLayout>
9+
<Label text="{{ message }}" class="t-20 text-center c-black" textWrap="true"/>
10+
11+
</StackLayout>
12+
</ScrollView>
13+
</StackLayout>
14+
</Page>

nx.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
},
3939
"email": {
4040
"tags": []
41+
},
42+
"all": {
43+
"tags": []
4144
}
4245
},
4346
"workspaceLayout": {

packages/email/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ You can use this plugin to compose an e-mail, have the user edit the draft manua
1515
> Note that this plugin depends on the default mail app. If you want a fallback to a third party client app like Gmail or Outlook, then check for availability, and if not available use a solution like [the Social Share plugin](https://github.com/tjvantoll/nativescript-social-share).
1616
1717
```javascript
18-
tns plugin add @nativescript/email
18+
ns plugin add @nativescript/email
1919
```
2020

2121
## Usage
@@ -63,9 +63,9 @@ var email = require("@nativescript/email");
6363
#### JavaScript
6464

6565
```js
66-
// let's first create a File object using the tns file module
67-
var fs = require("file-system");
68-
var appPath = fs.knownFolders.currentApp().path;
66+
// let's first create a File object
67+
import { knownFolders } from "@nativescript/core";
68+
var appPath = knownFolders.currentApp().path;
6969
var logoPath = appPath + "/res/telerik-logo.png";
7070

7171
email.compose({

packages/email/index.ios.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,3 @@ export class MFMailComposeViewControllerDelegateImpl extends NSObject {
160160
this._callback(result, error);
161161
}
162162
}
163-
// var MFMailComposeViewControllerDelegateImpl = (function (_super) {
164-
// __extends(MFMailComposeViewControllerDelegateImpl, _super);
165-
166-
// function MFMailComposeViewControllerDelegateImpl() {
167-
// _super.apply(this, arguments);
168-
// }
169-
170-
// MFMailComposeViewControllerDelegateImpl.new = function () {
171-
// return _super.new.call(this);
172-
// };
173-
// MFMailComposeViewControllerDelegateImpl.prototype.initWithCallback = function (callback) {
174-
// this._callback = callback;
175-
// return this;
176-
// };
177-
// MFMailComposeViewControllerDelegateImpl.prototype.mailComposeControllerDidFinishWithResultError = function (controller, result, error) {
178-
// this._callback(result, error);
179-
// };
180-
// MFMailComposeViewControllerDelegateImpl.ObjCProtocols = [MFMailComposeViewControllerDelegate];
181-
// return MFMailComposeViewControllerDelegateImpl;
182-
// })(NSObject);

packages/local-notifications/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
The Local Notifications plugin allows your app to show notifications when the app is not running.
1616
Just like remote push notifications, but a few orders of magnitude easier to set up.
1717

18-
> ⚠️ Plugin version 4.0.0 should be used with NativeScript 6+. If you have an older `tns --version`, please use an older plugin version.
18+
> ⚠️ Plugin version 4.0.0 should be used with NativeScript 6+. If you have an older `ns --version`, please use an older plugin version.
1919
2020
## Installation
2121
From the command prompt go to your app's root folder and execute:
2222
```bash
23-
tns plugin add @nativescript/local-notifications
23+
ns plugin add @nativescript/local-notifications
2424
```
2525

2626
## Setup (since plugin version 3.0.0)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* -crlf
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
out/
2+
.idea/
3+
.gradle/
4+
local.properties
5+
build/
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Local Notifications Plugin library for NativeScript Android apps
2+
3+
## Building the framework
4+
- Open this folder as "an existing project" in Android Studio
5+
- Change anything needed
6+
- In the Gradle build window run `app > Tasks > build > clean` and `app > Tasks > build > build`
7+
- Copy the release .aar: from the plugin project root, run: `cp native-src/android/app/build/outputs/aar/app-release.aar src/platforms/android/`
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module external.linked.project.id="android" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="java-gradle" name="Java-Gradle">
5+
<configuration>
6+
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
7+
<option name="BUILDABLE" value="false" />
8+
</configuration>
9+
</facet>
10+
</component>
11+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
12+
<exclude-output />
13+
<content url="file://$MODULE_DIR$">
14+
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
15+
</content>
16+
<orderEntry type="inheritedJdk" />
17+
<orderEntry type="sourceFolder" forTests="false" />
18+
</component>
19+
</module>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

0 commit comments

Comments
 (0)