Skip to content
Open
Show file tree
Hide file tree
Changes from 9 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
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
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
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
20 changes: 9 additions & 11 deletions packages/google-maps/utils/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function intoNativeMarkerOptions(options: MarkerOptions) {
opts.icon(com.google.android.gms.maps.model.BitmapDescriptorFactory.defaultMarker(hueFromColor(color)));
}

if(typeof options?.opacity === 'number') {
if (typeof options?.opacity === 'number') {
opts.alpha(options.opacity);
}

Expand Down Expand Up @@ -153,14 +153,15 @@ export function intoNativePolygonOptions(options: PolygonOptions) {
}

if (Array.isArray(options?.holes)) {
const holes = new java.util.ArrayList();
options.holes.forEach((hole) => {
holes.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));
});
opts.addHole(nativeHole);
}
});

if (options.holes.length) {
opts.addHole(holes);
}
}

if (typeof options?.tappable === 'boolean') {
Expand Down Expand Up @@ -275,10 +276,7 @@ export function intoNativeGroundOverlayOptions(options: GroundOverlayOptions) {
}

if (options?.bounds) {
opts.positionFromBounds(new com.google.android.gms.maps.model.LatLngBounds(
new com.google.android.gms.maps.model.LatLng(options.bounds.southwest.lat, options.bounds.southwest.lng),
new com.google.android.gms.maps.model.LatLng(options.bounds.northeast.lat, options.bounds.northeast.lng)
));
opts.positionFromBounds(new com.google.android.gms.maps.model.LatLngBounds(new com.google.android.gms.maps.model.LatLng(options.bounds.southwest.lat, options.bounds.southwest.lng), new com.google.android.gms.maps.model.LatLng(options.bounds.northeast.lat, options.bounds.northeast.lng)));
}

if (typeof options?.transparency) {
Expand Down
17 changes: 11 additions & 6 deletions packages/google-maps/utils/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,17 @@ export function intoNativePolygonOptions(options: PolygonOptions) {
const opts = path ? GMSPolygon.polygonWithPath(path) : GMSPolygon.new();

if (Array.isArray(options?.holes)) {
if (options.holes.length) {
opts.holes = options.holes.map((hole) => {
const res = GMSMutablePath.path();
res.addCoordinate(CLLocationCoordinate2DMake(hole.lat, hole.lng));
}) as any;
}
const nativeHoles = NSMutableArray.new<GMSMutablePath>();
options.holes.forEach((hole) => {
if (Array.isArray(hole) && hole.length) {
const path = GMSMutablePath.path();
hole.forEach((coordinate) => {
path.addCoordinate(CLLocationCoordinate2DMake(coordinate.lat, coordinate.lng));
});
nativeHoles.addObject(path);
}
});
opts.holes = nativeHoles;
}

if (typeof options?.tappable === 'boolean') {
Expand Down
5 changes: 4 additions & 1 deletion packages/google-signin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Make sure you've filled out all the required fields in the console for [OAuth co
2. Select `GoogleService-Info.plist` from the file manager.
3. Select the `Runner` target from the dialog that appears.

4. Add the `CFBundleURLTypes` attributes below to the `App_Resources/iOS/Info.plist` file.
4. Add the `CFBundleURLTypes` and `GIDClientID` attributes below to the `App_Resources/iOS/Info.plist` file.

```xml
<!-- Google Sign-in Section -->
Expand All @@ -102,6 +102,9 @@ Make sure you've filled out all the required fields in the console for [OAuth co
</array>
</dict>
</array>
<key>GIDClientID</key>
<!-- Copied from GoogleService-Info.plist key CLIENT_ID -->
<string><749673967192-c24phj29u2otpict36e71ocjo2g5i3hs.apps.googleusercontent.com/string>
<!-- End of the Google Sign-in Section -->
```

Expand Down
38 changes: 23 additions & 15 deletions packages/imagepicker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ Install the plugin by running the following command in the root directory of you
npm install @nativescript/imagepicker
```

**Note: Version 3.0 contains breaking changes:**
* authorize() now returns a `Promise<AuthorizationResult>` for both android and ios.
* In the returned result from `present()` each `result[i].thumbnail` is now an `ImageSource`.
* `result[i].duration` is now typed correctly as a `number`.

**Note: Version 2.0 contains breaking changes. In order supply more information about your selection, the ImageSource asset is nested in the response so you'll need to update your code to use `result.asset` instead of `result` as your src for your Images.**

## Android required permissions
Expand Down Expand Up @@ -97,22 +102,25 @@ The `present` method resolves with the selected media assets that can you to pro
```ts
imagePickerObj
.authorize()
.then(function() {
return imagePickerObj.present();
})
.then(function(selection) {
selection.forEach(function(selected) {
this.imageSource = selected.asset;
this.type = selected.type;
this.filesize = selected.filesize;
//etc
});
list.items = selection;
}).catch(function (e) {
.then((authResult) => {
if(authResult.authorized) {
return imagePickerObj.present()
.then(function(selection) {
selection.forEach(function(selected) {
this.imageSource = selected.asset;
this.type = selected.type;
this.filesize = selected.filesize;
//etc
});
});
} else {
// process authorization not granted.
}
})
.catch(function (e) {
// process error
});
```
> **Note** To request permissions for Android 6+ (API 23+), use [nativescript-permissions](https://www.npmjs.com/package/nativescript-permissions) plugin.

### Demo
You can play with the plugin on StackBlitz at any of the following links:
Expand All @@ -131,8 +139,8 @@ The class that provides the media selection API. It offers the following methods
| Method | Returns | Description
|:-------|:--------|:-----------
| `constructor(options: Options)` | `ImagePicker` | Instanciates the ImagePicker class with the optional `options` parameter. See [Options](#options)
| `authorize()` | `Promise<void>` | Requests the required permissions. Call it before calling `present()`. In case of a failed authorization, consider notifying the user for degraded functionality.
| `present()` | `Promise<ImageAsset[]>` | Presents the image picker UI.
| `authorize()` | `Promise<AuthorizationResult>` | Requests the required permissions. Call it before calling `present()`. In case of a failed authorization, consider notifying the user for degraded functionality. The returned `AuthorizationResult` will have it's `authorized` property set to `true` if permission has been granted.
| `present()` | `Promise<ImagePickerSelection[]>` | Presents the image picker UI.
| `create(options: Options, hostView: View)` | `ImagePicker` | Creates an instance of the ImagePicker class. The `hostView` parameter can be set to the view that hosts the image picker. Intended to be used when opening the picker from a modal page.

### Options
Expand Down
Loading