From 16c5afe99ebaef1827fb936eeb289c3fc69d976b Mon Sep 17 00:00:00 2001 From: Nicholas Blackwell Date: Tue, 22 Sep 2020 00:02:10 -0700 Subject: [PATCH 1/8] update to support ns 7 --- src/geolocation.android.ts | 27 +++++++++++++-------------- src/geolocation.ios.ts | 13 ++++++------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/geolocation.android.ts b/src/geolocation.android.ts index e003613..0878626 100644 --- a/src/geolocation.android.ts +++ b/src/geolocation.android.ts @@ -1,6 +1,5 @@ -import { on as applicationOn, android as androidAppInstance, AndroidApplication, uncaughtErrorEvent, UnhandledErrorEventData } from "application"; -import { Accuracy } from "tns-core-modules/ui/enums"; -import { setTimeout, clearTimeout } from "tns-core-modules/timer"; +import { Application, AndroidApplication, UnhandledErrorEventData, Enums } from "@nativescript/core"; +import { setTimeout, clearTimeout } from "@nativescript/core/timer"; import { LocationBase, defaultGetLocationTimeout, fastestTimeUpdate, minTimeUpdate } from "./geolocation.common"; import { Options, successCallbackType, errorCallbackType } from "./location-monitor"; import * as permissions from "nativescript-permissions"; @@ -18,10 +17,10 @@ let attachedForErrorHandling = false; function _ensureLocationClient() { // Wrapped in a function as we should not access java object there because of the snapshots. fusedLocationClient = fusedLocationClient || - com.google.android.gms.location.LocationServices.getFusedLocationProviderClient(androidAppInstance.context); + com.google.android.gms.location.LocationServices.getFusedLocationProviderClient(Application.android.context); } -androidAppInstance.on(AndroidApplication.activityResultEvent, function (args: any) { +Application.android.on(AndroidApplication.activityResultEvent, function (args: any) { if (args.requestCode === REQUEST_ENABLE_LOCATION) { if (args.resultCode === 0) { if (_onEnableLocationFail) { @@ -34,13 +33,13 @@ androidAppInstance.on(AndroidApplication.activityResultEvent, function (args: an }); function isAirplaneModeOn(): boolean { - return android.provider.Settings.System.getInt(androidAppInstance.context.getContentResolver(), + return android.provider.Settings.System.getInt(Application.android.context.getContentResolver(), android.provider.Settings.System.AIRPLANE_MODE_ON) !== 0; } function isProviderEnabled(provider: string): boolean { try { - const locationManager: android.location.LocationManager = (androidAppInstance.context) + const locationManager: android.location.LocationManager = (Application.android.context) .getSystemService(android.content.Context.LOCATION_SERVICE); return locationManager.isProviderEnabled(provider); } catch (ex) { @@ -115,7 +114,7 @@ function _getLocationRequest(options: Options): any { if (options.updateDistance) { mLocationRequest.setSmallestDisplacement(options.updateDistance); } - if (options.desiredAccuracy === Accuracy.high) { + if (options.desiredAccuracy === Enums.Accuracy.high) { mLocationRequest.setPriority(com.google.android.gms.location.LocationRequest.PRIORITY_HIGH_ACCURACY); } else { mLocationRequest.setPriority(com.google.android.gms.location.LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); @@ -178,7 +177,7 @@ export function watchLocation(successCallback: successCallbackType, errorCallbac if (!attachedForErrorHandling) { attachedForErrorHandling = true; - applicationOn(uncaughtErrorEvent, errorHandler.bind(this)); + Application.on(Application.uncaughtErrorEvent, errorHandler.bind(this)); } let locationRequest = _getLocationRequest(options); @@ -215,7 +214,7 @@ export function enableLocationRequest(always?: boolean): Promise { // on REQUEST_ENABLE_LOCATION Activity Result _onEnableLocationSuccess = resolve; _onEnableLocationFail = reject; - return ex.startResolutionForResult(androidAppInstance.foregroundActivity, REQUEST_ENABLE_LOCATION); + return ex.startResolutionForResult(Application.android.foregroundActivity, REQUEST_ENABLE_LOCATION); } catch (sendEx) { // Ignore the error. return resolve(); @@ -240,7 +239,7 @@ function _makeGooglePlayServicesAvailable(): Promise { return; } let googleApiAvailability = com.google.android.gms.common.GoogleApiAvailability.getInstance(); - googleApiAvailability.makeGooglePlayServicesAvailable(androidAppInstance.foregroundActivity) + googleApiAvailability.makeGooglePlayServicesAvailable(Application.android.foregroundActivity) .addOnSuccessListener(_getTaskSuccessListener(resolve)) .addOnFailureListener(_getTaskFailListener(reject)); }); @@ -253,7 +252,7 @@ function _isGooglePlayServicesAvailable(): boolean { let isLocationServiceEnabled = true; let googleApiAvailability = com.google.android.gms.common.GoogleApiAvailability.getInstance(); - let resultCode = googleApiAvailability.isGooglePlayServicesAvailable(androidAppInstance.context); + let resultCode = googleApiAvailability.isGooglePlayServicesAvailable(Application.android.context); if (resultCode !== com.google.android.gms.common.ConnectionResult.SUCCESS) { isLocationServiceEnabled = false; } @@ -268,12 +267,12 @@ function _isLocationServiceEnabled(options?: Options): Promise { return; } - options = options || { desiredAccuracy: Accuracy.high, updateTime: 0, updateDistance: 0, maximumAge: 0, timeout: 0 }; + options = options || { desiredAccuracy: Enums.Accuracy.high, updateTime: 0, updateDistance: 0, maximumAge: 0, timeout: 0 }; let locationRequest = _getLocationRequest(options); let locationSettingsBuilder = new com.google.android.gms.location.LocationSettingsRequest.Builder(); locationSettingsBuilder.addLocationRequest(locationRequest); locationSettingsBuilder.setAlwaysShow(true); - let locationSettingsClient = com.google.android.gms.location.LocationServices.getSettingsClient(androidAppInstance.context); + let locationSettingsClient = com.google.android.gms.location.LocationServices.getSettingsClient(Application.android.context); locationSettingsClient.checkLocationSettings(locationSettingsBuilder.build()) .addOnSuccessListener(_getTaskSuccessListener(resolve)) .addOnFailureListener(_getTaskFailListener(reject)); diff --git a/src/geolocation.ios.ts b/src/geolocation.ios.ts index 531e263..9f3f134 100644 --- a/src/geolocation.ios.ts +++ b/src/geolocation.ios.ts @@ -1,6 +1,5 @@ -import { Accuracy } from "tns-core-modules/ui/enums"; -import { setTimeout, clearTimeout } from "tns-core-modules/timer"; -import { on as applicationOn, uncaughtErrorEvent, UnhandledErrorEventData } from "tns-core-modules/application"; +import { Enums, Device, Application, UnhandledErrorEventData} from "@nativescript/core"; +import { setTimeout, clearTimeout } from "@nativescript/core/timer"; import { LocationBase, @@ -12,13 +11,13 @@ import { successCallbackType, errorCallbackType } from "./location-monitor"; -import * as Platform from "platform"; const locationManagers = {}; const locationListeners = {}; let watchId = 0; let attachedForErrorHandling = false; +@NativeClass class LocationListenerImpl extends NSObject implements CLLocationManagerDelegate { public static ObjCProtocols = [CLLocationManagerDelegate]; // tslint:disable-line:variable-name @@ -140,7 +139,7 @@ function errorHandler(errData: UnhandledErrorEventData) { } function getVersionMaj () { - return parseInt(Platform.device.osVersion.split(".")[0]); + return parseInt(Device.osVersion.split(".")[0]); } // options - desiredAccuracy, updateDistance, minimumUpdateTime, maximumAge, timeout @@ -184,7 +183,7 @@ export function getCurrentLocation(options: Options): Promise { return; } - if (options.desiredAccuracy !== Accuracy.any && !initLocation) { + if (options.desiredAccuracy !== Enums.Accuracy.any && !initLocation) { // regardless of desired accuracy ios returns first location as quick as possible even if not as accurate as requested initLocation = location; return; @@ -223,7 +222,7 @@ export function watchLocation(successCallback: successCallbackType, options: Options): number { if (!attachedForErrorHandling) { attachedForErrorHandling = true; - applicationOn(uncaughtErrorEvent, errorHandler.bind(this)); + Application.on(Application.uncaughtErrorEvent, errorHandler.bind(this)); } let zonedSuccessCallback = (global).zonedCallback(successCallback); From 261cdabfba40e68e62575511378a6b776ec83f8c Mon Sep 17 00:00:00 2001 From: Nicholas Blackwell Date: Tue, 22 Sep 2020 11:21:47 -0700 Subject: [PATCH 2/8] add project config updates --- src/package.json | 11 ++++++----- src/tsconfig.json | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/package.json b/src/package.json index c25a68d..6343bde 100644 --- a/src/package.json +++ b/src/package.json @@ -6,8 +6,8 @@ "typings": "index.d.ts", "nativescript": { "platforms": { - "android": "4.0.0", - "ios": "4.0.0" + "android": "7.0.0", + "ios": "7.0.0" } }, "scripts": { @@ -38,9 +38,10 @@ "homepage": "https://github.com/NativeScript/nativescript-geolocation", "readmeFilename": "README.md", "devDependencies": { - "tns-core-modules": "^5.0.0", - "tns-platform-declarations": "^5.0.0", - "typescript": "~3.1.6", + "@nativescript/core": "7.0.0", + "@nativescript/types": "7.0.0", + "@nativescript/webpack": "~3.0.0", + "typescript": "3.9.0", "prompt": "~1.0.0", "rimraf": "~2.6.2", "tslint": "~5.11.0" diff --git a/src/tsconfig.json b/src/tsconfig.json index 8110abf..154269e 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -1,7 +1,8 @@ { "compilerOptions": { - "target": "es5", - "module": "commonjs", + "target": "ES2017", + "module": "esnext", + "moduleResolution": "node", "declaration": false, "removeComments": true, "preserveConstEnums": true, From a2c0046b54db54d6335d5a8e8e410f4c1caccb2d Mon Sep 17 00:00:00 2001 From: Nicholas Blackwell Date: Thu, 8 Oct 2020 22:26:18 -0700 Subject: [PATCH 3/8] fixes two calls to Accuracy.high --- src/geolocation.ios.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/geolocation.ios.ts b/src/geolocation.ios.ts index 9f3f134..2df9da0 100644 --- a/src/geolocation.ios.ts +++ b/src/geolocation.ios.ts @@ -358,7 +358,7 @@ export class LocationMonitor { static createiOSLocationManager(locListener: any, options: Options): CLLocationManager { let iosLocManager = new CLLocationManager(); iosLocManager.delegate = locListener; - iosLocManager.desiredAccuracy = options ? options.desiredAccuracy : Accuracy.high; + iosLocManager.desiredAccuracy = options ? options.desiredAccuracy : Enums.Accuracy.high; iosLocManager.distanceFilter = options ? options.updateDistance : minRangeUpdate; locationManagers[locListener.id] = iosLocManager; locationListeners[locListener.id] = locListener; @@ -383,7 +383,7 @@ function getIOSLocationManager(locListener: any, options: Options): CLLocationMa let manager = new iosLocationManager(); manager.delegate = locListener; - manager.desiredAccuracy = options ? options.desiredAccuracy : Accuracy.high; + manager.desiredAccuracy = options ? options.desiredAccuracy : Enums.Accuracy.high; manager.distanceFilter = options ? options.updateDistance : minRangeUpdate; locationManagers[locListener.id] = manager; From 61b170c34665b10ae531439e98fe61492b7da39d Mon Sep 17 00:00:00 2001 From: Nicholas Blackwell Date: Thu, 8 Oct 2020 22:32:45 -0700 Subject: [PATCH 4/8] change typescript version --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index 6343bde..6012fb3 100644 --- a/src/package.json +++ b/src/package.json @@ -41,7 +41,7 @@ "@nativescript/core": "7.0.0", "@nativescript/types": "7.0.0", "@nativescript/webpack": "~3.0.0", - "typescript": "3.9.0", + "typescript": "~3.9.0", "prompt": "~1.0.0", "rimraf": "~2.6.2", "tslint": "~5.11.0" From 4c574333d294b63f3a23fcccb551c2b29c27a15a Mon Sep 17 00:00:00 2001 From: Nicholas Blackwell Date: Thu, 8 Oct 2020 23:01:57 -0700 Subject: [PATCH 5/8] update typescript refs --- src/references.d.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/references.d.ts b/src/references.d.ts index 1e5e961..d743326 100644 --- a/src/references.d.ts +++ b/src/references.d.ts @@ -1,2 +1 @@ -/// -/// +/// From 856a9a262142c156905b5d10a21da815881f691d Mon Sep 17 00:00:00 2001 From: Nicholas Blackwell Date: Fri, 9 Oct 2020 09:11:52 -0700 Subject: [PATCH 6/8] update demo app to work with ns-7, replace nativescript-toast with nativescript-toasty --- demo/app/app.css | 3 +++ demo/app/app.ts | 4 ++-- demo/app/background-service.ts | 9 ++++----- demo/app/main-page.ts | 8 ++------ demo/app/main-view-model.ts | 3 +-- demo/app/package.json | 8 -------- demo/nativescript.config.ts | 14 ++++++++++++++ demo/package.json | 27 ++++++++++----------------- demo/tsconfig.json | 12 +++++++----- 9 files changed, 43 insertions(+), 45 deletions(-) delete mode 100644 demo/app/package.json create mode 100644 demo/nativescript.config.ts diff --git a/demo/app/app.css b/demo/app/app.css index 911130f..360bea3 100644 --- a/demo/app/app.css +++ b/demo/app/app.css @@ -1 +1,4 @@ @import '~nativescript-theme-core/css/core.light.css'; +.ns-dark Button{ + color:black; +} \ No newline at end of file diff --git a/demo/app/app.ts b/demo/app/app.ts index 108a350..be7fdd9 100644 --- a/demo/app/app.ts +++ b/demo/app/app.ts @@ -1,2 +1,2 @@ -import * as application from 'tns-core-modules/application'; -application.run({ moduleName: "app-root" }); +import { Application as application } from '@nativescript/core'; +application.run({ moduleName: "app-root" }); \ No newline at end of file diff --git a/demo/app/background-service.ts b/demo/app/background-service.ts index 41ffa9e..aac7270 100644 --- a/demo/app/background-service.ts +++ b/demo/app/background-service.ts @@ -1,8 +1,7 @@ import * as geolocation from "nativescript-geolocation"; -import { Accuracy } from "tns-core-modules/ui/enums"; -import * as application from "tns-core-modules/application"; -import { device } from "tns-core-modules/platform"; -import * as Toast from "nativescript-toast"; +import { Accuracy } from "@nativescript/core/ui/enums"; +import {Application as application, Device as device } from "@nativescript/core"; +import {Toasty} from "nativescript-toasty"; let watchId; @@ -19,7 +18,7 @@ function _startWatch() { watchId = geolocation.watchLocation( function (loc) { if (loc) { - let toast = Toast.makeText('Background Location: \n' + loc.latitude + ', ' + loc.longitude); + let toast = new Toasty({text:'Background Location: \n' + loc.latitude + ', ' + loc.longitude}); toast.show(); console.log('Background Location: ' + loc.latitude + ' ' + loc.longitude); } diff --git a/demo/app/main-page.ts b/demo/app/main-page.ts index c1c7d8a..d0a69bc 100644 --- a/demo/app/main-page.ts +++ b/demo/app/main-page.ts @@ -1,11 +1,7 @@ import * as geolocation from "nativescript-geolocation"; -import { Accuracy } from "tns-core-modules/ui/enums"; -import { EventData } from "tns-core-modules/data/observable"; -import { Page } from "tns-core-modules/ui/page"; +import { Accuracy } from "@nativescript/core/ui/enums"; +import { EventData, Page, Application as application, Device as device, Utils as utils } from "@nativescript/core"; import { MainViewModel } from "./main-view-model"; -const utils = require("tns-core-modules/utils/utils"); -import * as application from "tns-core-modules/application"; -import { device } from "tns-core-modules/platform"; import { BackgroundServiceClass } from "./background-service"; let page: Page; diff --git a/demo/app/main-view-model.ts b/demo/app/main-view-model.ts index c66cca2..fc0faaa 100644 --- a/demo/app/main-view-model.ts +++ b/demo/app/main-view-model.ts @@ -1,6 +1,5 @@ import * as geolocation from "nativescript-geolocation"; -import { Observable } from "tns-core-modules/data/observable"; -import { ObservableArray } from "tns-core-modules/data/observable-array"; +import { Observable, ObservableArray } from "@nativescript/core"; export class MainViewModel extends Observable { private _locations: ObservableArray; diff --git a/demo/app/package.json b/demo/app/package.json deleted file mode 100644 index 670accf..0000000 --- a/demo/app/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "main": "app.js", - "android": { - "v8Flags": "--expose_gc", - "markingMode": "none", - "requireModules": ["nativescript-geolocation"] - } -} diff --git a/demo/nativescript.config.ts b/demo/nativescript.config.ts new file mode 100644 index 0000000..c314dc1 --- /dev/null +++ b/demo/nativescript.config.ts @@ -0,0 +1,14 @@ +import { NativeScriptConfig } from '@nativescript/core'; + +export default { + id: 'org.nativescript.demo', + appResourcesPath: 'app/App_Resources', + android: { + v8Flags: '--expose_gc', + markingMode: 'none', + requireModules: { + 0: 'nativescript-geolocation', + }, + }, + appPath: 'app', +} as NativeScriptConfig; diff --git a/demo/package.json b/demo/package.json index be54055..475b8a6 100644 --- a/demo/package.json +++ b/demo/package.json @@ -1,34 +1,27 @@ { - "nativescript": { - "id": "org.nativescript.demo", - "tns-android": { - "version": "6.2.0" - }, - "tns-ios": { - "version": "6.2.0" - } - }, "dependencies": { + "@nativescript/core": "7.0.0", + "@nativescript/webpack": "3.0.0", "nativescript-geolocation": "../src", "nativescript-theme-core": "^1.0.4", - "nativescript-toast": "~2.0.0", - "nativescript-unit-test-runner": "0.7.0", - "tns-core-modules": "^6.0.0" + "nativescript-toasty": "^3.0.0-alpha.2", + "nativescript-unit-test-runner": "0.7.0" }, "devDependencies": { + "@nativescript/ios": "7.0.1", + "@nativescript/types": "7.0.0", "jasmine-core": "^2.5.2", "karma": "4.1.0", "karma-jasmine": "2.0.1", "karma-nativescript-launcher": "^0.4.0", + "karma-webpack": "3.0.5", "nativescript-css-loader": "~0.26.0", - "nativescript-dev-webpack": "^1.3.0", - "tns-platform-declarations": "^6.0.0", "tslint": "~5.11.0", - "karma-webpack": "3.0.5", - "typescript": "~3.4.5" + "typescript": "3.9.7" }, "scripts": { "ci.tslint": "npm i && tslint --config '../tslint.json' 'app/**/*.ts' --exclude '**/node_modules/**'", "build.plugin": "cd ../src && npm run build" - } + }, + "main": "app.js" } diff --git a/demo/tsconfig.json b/demo/tsconfig.json index 20dcdf3..0eb7346 100644 --- a/demo/tsconfig.json +++ b/demo/tsconfig.json @@ -1,16 +1,17 @@ { "compilerOptions": { - "target": "es5", - "module": "commonjs", + "target": "es2017", + "module": "esnext", "declaration": false, - "removeComments": true, + "removeComments": false, "noLib": false, "emitDecoratorMetadata": true, "experimentalDecorators": true, "lib": [ "es6", "dom", - "es2015.iterable" + "es2015.iterable", + "es2017" ], "pretty": true, "allowUnreachableCode": false, @@ -30,7 +31,8 @@ "~/*": [ "app/*" ] - } + }, + "moduleResolution": "node" }, "include": [ "../src", From 4d84638ec49a4a2b988b11e3da40dc0335572f9e Mon Sep 17 00:00:00 2001 From: Nicholas Blackwell Date: Fri, 9 Oct 2020 12:01:09 -0700 Subject: [PATCH 7/8] fix demo app background service for nativescript 7 --- demo/app/background-service.ts | 13 ++++++++----- demo/package.json | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/demo/app/background-service.ts b/demo/app/background-service.ts index aac7270..76d2fe8 100644 --- a/demo/app/background-service.ts +++ b/demo/app/background-service.ts @@ -1,7 +1,6 @@ import * as geolocation from "nativescript-geolocation"; import { Accuracy } from "@nativescript/core/ui/enums"; import {Application as application, Device as device } from "@nativescript/core"; -import {Toasty} from "nativescript-toasty"; let watchId; @@ -18,8 +17,10 @@ function _startWatch() { watchId = geolocation.watchLocation( function (loc) { if (loc) { - let toast = new Toasty({text:'Background Location: \n' + loc.latitude + ', ' + loc.longitude}); - toast.show(); + + android.widget.Toast.makeText(application.android.context, 'Background Location: \n' + loc.latitude + ', ' + loc.longitude, android.widget.Toast.LENGTH_SHORT).show(); + //let toast = new Toasty({text:'Background Location: \n' + loc.latitude + ', ' + loc.longitude}); + //toast.show(); console.log('Background Location: ' + loc.latitude + ' ' + loc.longitude); } }, @@ -41,7 +42,8 @@ application.on(application.exitEvent, _clearWatch); export function getBackgroundServiceClass() { if (application.android) { if (device.sdkVersion < "26") { - @JavaProxy("com.nativescript.location.BackgroundService") + @NativeClass() + @JavaProxy('com.nativescript.location.BackgroundService') class BackgroundService extends (android).app.Service { constructor() { super(); @@ -69,7 +71,8 @@ export function getBackgroundServiceClass() { } return BackgroundService; } else { - @JavaProxy("com.nativescript.location.BackgroundService26") + @NativeClass() + @JavaProxy('com.nativescript.location.BackgroundService26') class BackgroundService26 extends (android.app).job.JobService { constructor() { super(); diff --git a/demo/package.json b/demo/package.json index 475b8a6..0cf1e09 100644 --- a/demo/package.json +++ b/demo/package.json @@ -4,10 +4,10 @@ "@nativescript/webpack": "3.0.0", "nativescript-geolocation": "../src", "nativescript-theme-core": "^1.0.4", - "nativescript-toasty": "^3.0.0-alpha.2", "nativescript-unit-test-runner": "0.7.0" }, "devDependencies": { + "@nativescript/android": "7.0.0", "@nativescript/ios": "7.0.1", "@nativescript/types": "7.0.0", "jasmine-core": "^2.5.2", From 4fd318dab56e510d2b016cf03799ab1771f209fc Mon Sep 17 00:00:00 2001 From: Nicholas Blackwell Date: Fri, 9 Oct 2020 12:16:03 -0700 Subject: [PATCH 8/8] fix comment --- demo/app/background-service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/app/background-service.ts b/demo/app/background-service.ts index 76d2fe8..48a28b7 100644 --- a/demo/app/background-service.ts +++ b/demo/app/background-service.ts @@ -19,8 +19,8 @@ function _startWatch() { if (loc) { android.widget.Toast.makeText(application.android.context, 'Background Location: \n' + loc.latitude + ', ' + loc.longitude, android.widget.Toast.LENGTH_SHORT).show(); - //let toast = new Toasty({text:'Background Location: \n' + loc.latitude + ', ' + loc.longitude}); - //toast.show(); + // let toast = new Toasty({text:'Background Location: \n' + loc.latitude + ', ' + loc.longitude}); + // toast.show(); console.log('Background Location: ' + loc.latitude + ' ' + loc.longitude); } },