Skip to content
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

fix(geolocation): perm handling around wheninuse vs always #521

Open
wants to merge 16 commits into
base: feat/plugin-tools-updates
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions apps/demo-angular/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
}
]
},
"ios": {
"executor": "@nativescript/nx:build",
"debug": {
"executor": "@nativescript/nx:debug",
"options": {
"platform": "ios",
"noHmr": true
},
"dependsOn": [
Expand All @@ -34,10 +33,9 @@
}
]
},
"android": {
"executor": "@nativescript/nx:build",
"prepare": {
"executor": "@nativescript/nx:prepare",
"options": {
"platform": "android",
"noHmr": true
},
"dependsOn": [
Expand All @@ -48,10 +46,8 @@
]
},
"clean": {
"executor": "@nativescript/nx:build",
"options": {
"clean": true
}
"executor": "@nativescript/nx:clean",
"options": {}
},
"lint": {
"executor": "@nx/linter:eslint",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ListView [items]="imageAssets" *ngIf="!isSingleMode">
<ng-template let-image="item" let-i="index">
<GridLayout columns="auto, *">
<Image [width]="thumbSize" [height]="thumbSize" [src]="image" stretch="aspectFill"></Image>
<Image [width]="thumbSize" [height]="thumbSize" [src]="image.asset" stretch="aspectFill"></Image>
<Label col="1" [text]="'image ' + i"></Label>
</GridLayout>
</ng-template>
Expand Down
46 changes: 25 additions & 21 deletions apps/demo-angular/src/plugin-demos/imagepicker.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Component, NgZone } from '@angular/core';
import { ImageAsset } from '@nativescript/core';
import * as imagepicker from '@nativescript/imagepicker';
import { ImageAsset, ImageSource } from '@nativescript/core';
import { ImagePicker, create, ImagePickerSelection } from '@nativescript/imagepicker';

@Component({
selector: 'demo-imagepicker',
templateUrl: 'imagepicker.component.html',
})
export class ImagepickerComponent {
imageAssets = [];
imageSrc: any;
imageAssets: ImagePickerSelection[] = [];
imageSrc: ImageAsset | ImageSource;
isSingleMode: boolean = true;
thumbSize: number = 80;
previewSize: number = 300;
Expand All @@ -18,7 +18,7 @@ export class ImagepickerComponent {
public onSelectMultipleTap() {
this.isSingleMode = false;

let context = imagepicker.create({
let context = create({
mode: 'multiple',
});
this.startSelection(context);
Expand All @@ -27,36 +27,40 @@ export class ImagepickerComponent {
public onSelectSingleTap() {
this.isSingleMode = true;

let context = imagepicker.create({
let context = create({
mode: 'single',
});
this.startSelection(context);
}

private startSelection(context) {
private startSelection(context: ImagePicker) {
context
.authorize()
.then(() => {
.then((authResult) => {
this._ngZone.run(() => {
this.imageAssets = [];
this.imageSrc = null;
});
return context.present();
})
.then((selection) => {
this._ngZone.run(() => {
console.log('Selection done: ' + JSON.stringify(selection));
this.imageSrc = this.isSingleMode && selection.length > 0 ? selection[0] : null;
if (authResult.authorized) {
return context.present().then((selection) => {
this._ngZone.run(() => {
console.log('Selection done: ' + JSON.stringify(selection));
this.imageSrc = this.isSingleMode && selection.length > 0 ? selection[0].asset : null;

// set the images to be loaded from the assets with optimal sizes (optimize memory usage)
selection.forEach((el: ImageAsset) => {
el.options.width = this.isSingleMode ? this.previewSize : this.thumbSize;
el.options.height = this.isSingleMode ? this.previewSize : this.thumbSize;
});
// set the images to be loaded from the assets with optimal sizes (optimize memory usage)
selection.forEach((el) => {
el.asset.options.width = this.isSingleMode ? this.previewSize : this.thumbSize;
el.asset.options.height = this.isSingleMode ? this.previewSize : this.thumbSize;
});

this.imageAssets = selection;
});
this.imageAssets = selection;
});
});
} else {
console.log('Unauthorised');
}
})

.catch(function (e) {
console.log(e);
});
Expand Down
16 changes: 6 additions & 10 deletions apps/demo/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
}
]
},
"ios": {
"executor": "@nativescript/nx:build",
"debug": {
"executor": "@nativescript/nx:debug",
"options": {
"platform": "ios",
"noHmr": true
},
"dependsOn": [
Expand All @@ -34,10 +33,9 @@
}
]
},
"android": {
"executor": "@nativescript/nx:build",
"prepare": {
"executor": "@nativescript/nx:prepare",
"options": {
"platform": "android",
"noHmr": true
},
"dependsOn": [
Expand All @@ -48,10 +46,8 @@
]
},
"clean": {
"executor": "@nativescript/nx:build",
"options": {
"clean": true
}
"executor": "@nativescript/nx:clean",
"options": {}
},
"lint": {
"executor": "@nx/linter:eslint",
Expand Down
5 changes: 1 addition & 4 deletions apps/demo/src/main-page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,18 @@
<Button text="google-signin" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
<Button text="haptics" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
<Button text="imagepicker" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>

<Button text="ios-security" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
<Button text="iqkeyboardmanager" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>

<Button text="local-notifications" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
<Button text="localize" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
<Button text="pdf" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
<Button text="picker" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
<Button text="secure-storage" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
<Button text="shared-notification-delegate" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
<Button text="social-share" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>

<Button text="theme-switcher" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
<Button text="twitter" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
<Button text="zip" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
<Button text="secure-storage" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
</StackLayout>
</ScrollView>
</StackLayout>
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@
"shorthash": "0.0.2",
"simple-plist": "^1.1.0",
"sprintf-js": "^1.1.1",
"ts-patch": "^3.0.0",
"typescript": "~5.0.0",
"vue": "~2.6.12",
"zone.js": "~0.13.0"
},
"resolutions": {
"ts-patch": "^3.0.0"
},
"lint-staged": {
"**/*.{js,ts,scss,json,html}": [
"npx prettier --write"
Expand Down
17 changes: 17 additions & 0 deletions packages/appavailability/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@ For example, to query for `twitter://`, `whatsapp://` and `fb://`, edit `app/App
</array>
```

## Android Query Permission

Starting from Android API level 30 (Android 11), you must explicitly declare your app's intent to interact with other apps in the Android manifest file `AndroidManifest.xml`.

```xml
<manifest>
<queries>
<package android:name="com.whatsapp" />
</queries>

<application ...>
</application>
</manifest>
```

Replace `com.whatsapp` with the package name of the app you want to interact with.

## API

| Methods| Return Type| Description|
Expand Down
2 changes: 1 addition & 1 deletion packages/geolocation/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class LocationListenerImpl extends NSObject implements CLLocationManagerDelegate
}
break;
case CLAuthorizationStatus.kCLAuthorizationStatusAuthorizedWhenInUse:
if (this._resolve && !this.authorizeAlways) {
if (this._resolve) {
LocationMonitor.stopLocationMonitoring(this.id);
this._resolve();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/geolocation/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nativescript/geolocation",
"version": "8.2.0",
"version": "8.2.1",
"description": "Provides API for getting and monitoring location for NativeScript app.",
"main": "index",
"typings": "index.d.ts",
Expand Down
34 changes: 22 additions & 12 deletions packages/google-maps/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1356,26 +1356,36 @@ export class Polygon extends OverLayBase implements IPolygon {
}
}

get holes(): Coordinate[] {
const array: androidNative.Array<com.google.android.gms.maps.model.LatLng> = this.native.getHoles().toArray();
const holes: Coordinate[] = [];
get holes(): Coordinate[][] {
const array: androidNative.Array<java.util.List<com.google.android.gms.maps.model.LatLng>> = this.native.getHoles().toArray();
const holes: Coordinate[][] = [];
for (let i = 0; i < array.length; i++) {
const hole = array[i];
holes.push({
lat: hole.latitude,
lng: hole.longitude,
});
const nativeHole = array[i].toArray();
const hole: Coordinate[] = [];
for (let j = 0; j < nativeHole.length; j++) {
hole.push({
lat: nativeHole[j].latitude,
lng: nativeHole[j].longitude,
});
}
holes.push(hole);
}
return holes;
}

set holes(value) {
set holes(value: Coordinate[][]) {
if (Array.isArray(value)) {
const nativeArray = new java.util.ArrayList<com.google.android.gms.maps.model.LatLng>();
const nativeHoles = new java.util.ArrayList<java.util.ArrayList<com.google.android.gms.maps.model.LatLng>>();
value.forEach((hole) => {
nativeArray.add(new com.google.android.gms.maps.model.LatLng(hole.lat, hole.lng));
if (Array.isArray(hole) && hole.length) {
const nativeHole = new java.util.ArrayList<com.google.android.gms.maps.model.LatLng>();
hole.forEach((coordinate) => {
nativeHole.add(new com.google.android.gms.maps.model.LatLng(coordinate.lat, coordinate.lng));
});
nativeHoles.add(nativeHole);
}
});
this.native.setHoles(nativeArray);
this.native.setHoles(nativeHoles);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/google-maps/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ export class Circle implements ICircle {

export interface IPolygon {
points: Coordinate[];
holes: Coordinate[];
holes: Coordinate[][];
tappable: boolean;
strokeWidth: number;
strokeColor: Color | string;
Expand All @@ -512,7 +512,7 @@ export interface PolygonOptions extends Partial<IPolygon> {}
export class Polygon implements IPolygon {
fillColor: Color | string;
geodesic: boolean;
holes: Coordinate[];
holes: Coordinate[][];
points: Coordinate[];
strokeColor: Color | string;
strokeJointType: JointType;
Expand Down
36 changes: 22 additions & 14 deletions packages/google-maps/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1336,31 +1336,39 @@ export class Polygon extends OverLayBase implements IPolygon {
this.native.path = points;
}

get holes(): Coordinate[] {
get holes(): Coordinate[][] {
const nativeHoles = this.native?.holes;
const count = nativeHoles?.count || 0;
const holes: Coordinate[] = [];
const holes: Coordinate[][] = [];
for (let i = 0; i < count; i++) {
const hole = nativeHoles.objectAtIndex(i);
const coord = hole.coordinateAtIndex(0);
holes.push({
lat: coord.latitude,
lng: coord.longitude,
});
const nativeHole = nativeHoles.objectAtIndex(i);
const hole: Coordinate[] = [];
for (let j = 0; j < nativeHole.count(); j++) {
const coord = nativeHole.coordinateAtIndex(j);
hole.push({
lat: coord.latitude,
lng: coord.longitude,
});
}
holes.push(hole);
}
return holes;
}

set holes(value) {
const holes = [];
set holes(value: Coordinate[][]) {
const nativeHoles = [];
if (Array.isArray(value)) {
value.forEach((hole) => {
const path = GMSMutablePath.path();
path.addCoordinate(CLLocationCoordinate2DMake(hole.lat, hole.lng));
holes.push(path);
if (Array.isArray(hole) && hole.length) {
const path = GMSMutablePath.path();
hole.forEach((coordinate) => {
path.addCoordinate(CLLocationCoordinate2DMake(coordinate.lat, coordinate.lng));
});
nativeHoles.push(path);
}
});
}
this.native.holes = holes as any;
this.native.holes = nativeHoles as any;
}

get tappable(): boolean {
Expand Down
Loading