Skip to content

Commit aee4bcc

Browse files
AndroidX compatibility for NativeScript 6 #55
1 parent 7e1dc0c commit aee4bcc

16 files changed

+545
-9006
lines changed

demo/app/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import "./bundle-config";
22
import * as application from 'tns-core-modules/application';
3-
application.start({ moduleName: "main-page" });
3+
application.run({ moduleName: "main-page" });

demo/app/main-page.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<TabViewItem.view>
66
<ScrollView>
77
<StackLayout class="tab-content">
8-
<Image margin="10" src="~/res/telerik-logo.png" />
98
<Label text="Calendar plugin demo" class="title"/>
109
<Label text="The Calendar plugin allows you to manipulate events in the user's calendar. You can find, create and delete events in either the default or a custom calendar." textWrap="true"/>
1110
</StackLayout>

demo/app/main-view-model.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import { Observable } from "tns-core-modules/data/observable";
22
import { alert } from "tns-core-modules/ui/dialogs/dialogs";
33

4+
// import the plugin like this:
5+
import {
6+
createEvent,
7+
requestPermission,
8+
findEvents,
9+
deleteCalendar,
10+
listCalendars, deleteEvents
11+
} from "nativescript-calendar";
12+
13+
// .. or alternatively like this:
414
import * as Calendar from "nativescript-calendar";
515

616
export class DemoAppModel extends Observable {
@@ -20,11 +30,11 @@ export class DemoAppModel extends Observable {
2030
}
2131

2232
doRequestPermission(): void {
23-
Calendar.requestPermission().then(() => console.log("Permission requested"));
33+
requestPermission().then(() => console.log("Permission requested"));
2434
}
2535

2636
private createEvent(options): void {
27-
Calendar.createEvent(options).then(
37+
createEvent(options).then(
2838
createdId => {
2939
alert({
3040
title: "Event created with ID",
@@ -103,7 +113,7 @@ export class DemoAppModel extends Observable {
103113
}
104114

105115
doFindEventByTitle(): void {
106-
Calendar.findEvents({
116+
findEvents({
107117
// any event containing this string will be returned
108118
title: 'groceries',
109119
// dates are mandatory, the event must be within this interval
@@ -122,7 +132,7 @@ export class DemoAppModel extends Observable {
122132
}
123133

124134
doFindAllEvents(): void {
125-
Calendar.findEvents({
135+
findEvents({
126136
// dates are mandatory, the event must be within this interval
127137
startDate: new Date(new Date().getTime() - (50 * 24 * 60 * 60 * 1000)),
128138
endDate: new Date(new Date().getTime() + (50 * 24 * 60 * 60 * 1000))
@@ -146,7 +156,7 @@ export class DemoAppModel extends Observable {
146156
}
147157

148158
doListCalendars(): void {
149-
Calendar.listCalendars().then(
159+
listCalendars().then(
150160
calendars => {
151161
alert({
152162
title: "Found " + calendars.length + " calendars",
@@ -159,7 +169,7 @@ export class DemoAppModel extends Observable {
159169
}
160170

161171
doDeleteCalendar(): void {
162-
Calendar.deleteCalendar({
172+
deleteCalendar({
163173
name: DemoAppModel.CUSTOM_CALENDAR_NAME
164174
}).then(
165175
deletedCalendarId => {
@@ -174,7 +184,7 @@ export class DemoAppModel extends Observable {
174184
}
175185

176186
doDeleteEvents(): void {
177-
Calendar.deleteEvents({
187+
deleteEvents({
178188
// id: 'EF33E6DE-D36E-473B-A50B-FEFAEF700031',
179189
title: 'groceries', // only when the title contains this
180190
startDate: new Date(new Date().getTime() - (24 * 60 * 60 * 1000)), // 1 day ago

demo/app/vendor-platform.android.ts

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

demo/app/vendor-platform.ios.ts

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

demo/app/vendor.ts

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

demo/karma.conf.js

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
module.exports = function(config) {
2-
config.set({
1+
module.exports = function (config) {
2+
const options = {
33

44
// base path that will be used to resolve all patterns (eg. files, exclude)
55
basePath: '',
@@ -11,9 +11,7 @@ module.exports = function(config) {
1111

1212

1313
// list of files / patterns to load in the browser
14-
files: [
15-
'app/**/*.js'
16-
],
14+
files: ['app/tests/**/*.*'],
1715

1816

1917
// list of files to exclude
@@ -72,6 +70,39 @@ module.exports = function(config) {
7270

7371
// Continuous Integration mode
7472
// if true, Karma captures browsers, runs the tests and exits
75-
singleRun: true
76-
});
77-
};
73+
singleRun: false
74+
};
75+
76+
setWebpackPreprocessor(config, options);
77+
setWebpack(config, options);
78+
79+
config.set(options);
80+
}
81+
82+
function setWebpackPreprocessor(config, options) {
83+
if (config && config.bundle) {
84+
if (!options.preprocessors) {
85+
options.preprocessors = {};
86+
}
87+
88+
options.files.forEach(file => {
89+
if (!options.preprocessors[file]) {
90+
options.preprocessors[file] = [];
91+
}
92+
options.preprocessors[file].push('webpack');
93+
});
94+
}
95+
}
96+
97+
function setWebpack(config, options) {
98+
if (config && config.bundle) {
99+
const env = {};
100+
env[config.platform] = true;
101+
env.sourceMap = config.debugBrk;
102+
options.webpack = require('./webpack.config')(env);
103+
delete options.webpack.entry;
104+
delete options.webpack.output.libraryTarget;
105+
const invalidPluginsForUnitTesting = ["GenerateBundleStarterPlugin", "GenerateNativeScriptEntryPointsPlugin"];
106+
options.webpack.plugins = options.webpack.plugins.filter(p => !invalidPluginsForUnitTesting.includes(p.constructor.name));
107+
}
108+
}

0 commit comments

Comments
 (0)