New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@nativescript/camera

Package Overview
Dependencies
Maintainers
0
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nativescript/camera - npm Package Compare versions

Comparing version 5.1.1 to 6.0.0-rc.0

6

index.android.d.ts
import { CameraOptions } from '.';
export declare const takePicture: (options?: CameraOptions) => Promise<any>;
export declare const isAvailable: () => boolean;
export declare const requestPermissions: () => Promise<any>;
export declare const requestPhotosPermissions: () => Promise<any>;
export declare const requestCameraPermissions: () => Promise<any>;
export declare function requestPermissions(): Promise<boolean>;
export declare function requestPhotosPermissions(): Promise<boolean>;
export declare function requestCameraPermissions(): Promise<boolean>;
import { Utils, Application, Device, Trace, ImageAsset } from '@nativescript/core';
import * as permissions from 'nativescript-permissions';
import * as permissions from '@nativescript-community/perms';
const REQUEST_IMAGE_CAPTURE = 3453;

@@ -9,5 +9,6 @@ const useAndroidX = function () {

export const takePicture = function (options) {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
try {
if (!permissions.hasPermission(android.Manifest.permission.CAMERA)) {
const hasPerm = await permissions.check(android.Manifest.permission.CAMERA);
if (!hasPerm[1]) {
reject(new Error('Application does not have permissions to use Camera'));

@@ -27,3 +28,4 @@ return;

}
if (!api30() && !permissions.hasPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
const hasStoragePerm = await permissions.check(android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (!api30() && !hasStoragePerm[1]) {
saveToGallery = false;

@@ -158,16 +160,21 @@ }

}
export const requestPermissions = function () {
export async function requestPermissions() {
if (api30()) {
return permissions.requestPermissions([android.Manifest.permission.CAMERA]);
const hasPerm = await permissions.check('android.permission.CAMERA');
return hasPerm[1];
}
else {
return permissions.requestPermissions([android.Manifest.permission.WRITE_EXTERNAL_STORAGE, android.Manifest.permission.CAMERA]);
const hasPerm1 = await permissions.check('android.permission.WRITE_EXTERNAL_STORAGE');
const hasPerm2 = await permissions.check('android.permission.CAMERA');
return hasPerm1[1] && hasPerm2[1];
}
};
export const requestPhotosPermissions = function () {
return permissions.requestPermissions([android.Manifest.permission.WRITE_EXTERNAL_STORAGE]);
};
export const requestCameraPermissions = function () {
return permissions.requestPermissions([android.Manifest.permission.CAMERA]);
};
}
export async function requestPhotosPermissions() {
const hasPerm = await permissions.check('android.permission.WRITE_EXTERNAL_STORAGE');
return hasPerm[1];
}
export async function requestCameraPermissions() {
const hasPerm = await permissions.check('android.permission.CAMERA');
return hasPerm[1];
}
const createDateTimeStamp = function () {

@@ -174,0 +181,0 @@ let result = '';

@@ -180,6 +180,12 @@ import { Utils, ImageSource, ImageAsset, Trace, Frame } from '@nativescript/core';

return new Promise(function (resolve, reject) {
let authStatus = PHPhotoLibrary.authorizationStatus();
let authStatus;
if (Utils.SDK_VERSION >= 14) {
authStatus = PHPhotoLibrary.authorizationStatusForAccessLevel(2 /* PHAccessLevel.ReadWrite */);
}
else {
authStatus = PHPhotoLibrary.authorizationStatus();
}
switch (authStatus) {
case 0 /* PHAuthorizationStatus.NotDetermined */: {
PHPhotoLibrary.requestAuthorization((auth) => {
const handler = (auth) => {
if (auth === 3 /* PHAuthorizationStatus.Authorized */) {

@@ -194,3 +200,9 @@ if (Trace.isEnabled()) {

}
});
};
if (Utils.SDK_VERSION >= 14) {
PHPhotoLibrary.requestAuthorizationForAccessLevelHandler(2 /* PHAccessLevel.ReadWrite */, handler);
}
else {
PHPhotoLibrary.requestAuthorization(handler);
}
break;

@@ -197,0 +209,0 @@ }

{
"name": "@nativescript/camera",
"version": "5.1.1",
"version": "6.0.0-rc.0",
"description": "Provides API for using device camera",

@@ -38,5 +38,4 @@ "main": "index",

"dependencies": {
"nativescript-permissions": "1.3.11"
},
"types": "./index.d.d.ts"
}
"@nativescript-community/perms": "^2.3.1"
}
}

@@ -175,23 +175,23 @@ # @nativescript/camera

| Function | Returns | Description |
| ------------------------------------ |------------| ----------------------------------------------------------------------------------------------------------------------- |
| `takePicture(options?: CameraOptions) `| `Promise<ImageAsset>`| Takes a photo using the camera with an optional parameter for setting different camera options. |
| `requestPermissions()` | `Promise<any>`| Requests permission from the user to access their saved photos as well as access their camera.|
| `requestCameraPermissions() ` | `Promise<any>` |Requests permission from the user for access to their camera. |
| `requestPhotosPermissions()` | `Promise<any>`|Requests permission from the user for access to their saved photos. Returns a Promise. |
| `isAvailable()` | `boolean`|Check if the device camera available to use. |
| Function | Returns | Description |
| --------------------------------------- | --------------------- | ----------------------------------------------------------------------------------------------- |
| `takePicture(options?: CameraOptions) ` | `Promise<ImageAsset>` | Takes a photo using the camera with an optional parameter for setting different camera options. |
| `requestPermissions()` | `Promise<any>` | Requests permission from the user to access their saved photos as well as access their camera. |
| `requestCameraPermissions() ` | `Promise<any>` | Requests permission from the user for access to their camera. |
| `requestPhotosPermissions()` | `Promise<any>` | Requests permission from the user for access to their saved photos. Returns a Promise. |
| `isAvailable()` | `boolean` | Check if the device camera available to use. |
### CameraOptions interface
| Property | Default | Description
|:---------|:--------|:-----------
| `width` | `0` | _Optional_: The desired width of the picture (in device independent pixels). The actual image width will be greater than requested if the display density of the device is higher (than 1) (full HD+ resolutions). |
| `height` | `0` | _Optional_: The desired height of the picture (in device independent pixels). The actual image height will be greater than requested if the display density of the device is higher (than 1) (full HD+ resolutions). |
| `keepAspectRatio` | `true` | _Optional_: Defines if camera picture aspect ratio should be kept during picture resizing. The camera will return an image with the correct aspect ratio but generally only one (width or height) will be the same as requested; the other value will be calculated in order to preserve the aspect of the original image.|
| `saveToGallery` | `true` | _Optional_: A boolean parameter that indicates if the original taken photo will be saved in `Photos` for Android and in `Camera Roll` in iOS. |
| `allowsEditing` | `false` | _Optional_: (`iOS-only`)Defines if camera "Retake" or "Use Photo". Screen forces the user to crop camera picture to a square and optionally lets them zoom in. |
| `cameraFacing` | `'rear'` | _Optional_: The initial camera facing. Use `'front'` for selfies. | `modalPresentationStyle` | `0` | _Optional_: (`iOS-only`)Set a custom UIModalPresentationStyle (Defaults to UIModalPresentationStyle.FullScreen). |
| Property | Default | Description |
| :----------------------- | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `width` | `0` | _Optional_: The desired width of the picture (in device independent pixels). The actual image width will be greater than requested if the display density of the device is higher (than 1) (full HD+ resolutions). |
| `height` | `0` | _Optional_: The desired height of the picture (in device independent pixels). The actual image height will be greater than requested if the display density of the device is higher (than 1) (full HD+ resolutions). |
| `keepAspectRatio` | `true` | _Optional_: Defines if camera picture aspect ratio should be kept during picture resizing. The camera will return an image with the correct aspect ratio but generally only one (width or height) will be the same as requested; the other value will be calculated in order to preserve the aspect of the original image. |
| `saveToGallery` | `true` | _Optional_: A boolean parameter that indicates if the original taken photo will be saved in `Photos` for Android and in `Camera Roll` in iOS. |
| `allowsEditing` | `false` | _Optional_: (`iOS-only`) Defines if camera "Retake" or "Use Photo". Screen forces the user to crop camera picture to a square and optionally lets them zoom in. |
| `cameraFacing` | `'rear'` | _Optional_: The initial camera facing. Use `'front'` for selfies. |
| `modalPresentationStyle` | `0` | _Optional_: (`iOS-only`) Set a custom UIModalPresentationStyle (Defaults to UIModalPresentationStyle.FullScreen). |
> **Note**: The `saveToGallery` option might have unexpected behavior on Android! Some vendor camera apps (e.g. LG) will save all captured images to the gallery regardless of what the value of `saveToGallery` is. This behavior cannot be controlled by the camera plugin and if you need to exclude the captured image from the photo gallery, you will need to get a local storage read/write permission and write custom code to find the gallery location and delete the new image from there.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc