Skip to content

Commit 7f73f07

Browse files
author
Zdravko
authored
Merge pull request #91 from NativeScript/zbranzov/front-camera
fix: saveToGallery to default to true on both platforms
2 parents 1d0f44c + ba6fd98 commit 7f73f07

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ npm install nativescript-camera --save
4343
| width | 0 | Defines the desired width (in device independent pixels) of the taken image. It should be used with height property. If `keepAspectRatio` actual image width could be different in order to keep the aspect ratio of the original camera image. The actual image width will be greater than requested if the display density of the device is higher (than 1) (full HD+ resolutions). |
4444
| height | 0 | Defines the desired height (in device independent pixels) of the taken image. It should be used with width property. If `keepAspectRatio` actual image width could be different in order to keep the aspect ratio of the original camera image. The actual image height will be greater than requested if the display density of the device is higher (than 1) (full HD+ resolutions). |
4545
| keepAspectRatio | true | Defines if camera picture aspect ratio should be kept during picture resizing. This property could affect width or height return values. |
46-
| saveToGallery | false | Defines if camera picture should be copied to photo Gallery (Android) or Photos (iOS) |
46+
| saveToGallery | true | Defines if camera picture should be copied to photo Gallery (Android) or Photos (iOS) |
4747
| cameraFacing | rear | The initial camera facing. Use 'front' for selfies. |
4848

4949
## Usage

demo/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"typescript": "~2.2.2",
4747
"webpack": "~3.8.1",
4848
"webpack-bundle-analyzer": "^2.8.2",
49-
"webpack-sources": "~1.0.1"
49+
"webpack-sources": "~1.0.1",
50+
"uglifyjs-webpack-plugin": "~1.1.6"
5051
}
5152
}

src/camera.android.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ export let takePicture = function (options?): Promise<any> {
2525
let types: typeof typesModule = require("tns-core-modules/utils/types");
2626
let utils: typeof utilsModule = require("tns-core-modules/utils/utils");
2727

28-
let saveToGallery;
29-
let reqWidth;
30-
let reqHeight;
31-
let shouldKeepAspectRatio;
28+
let saveToGallery = true;
29+
let reqWidth = 0;
30+
let reqHeight = 0;
31+
let shouldKeepAspectRatio = true;
3232

3333
let density = utils.layout.getDisplayDensity();
3434
if (options) {
35-
saveToGallery = options.saveToGallery ? true : false;
36-
reqWidth = options.width ? options.width * density : 0;
35+
saveToGallery = types.isNullOrUndefined(options.saveToGallery) ? saveToGallery : options.saveToGallery;
36+
reqWidth = options.width ? options.width * density : reqWidth;
3737
reqHeight = options.height ? options.height * density : reqWidth;
38-
shouldKeepAspectRatio = types.isNullOrUndefined(options.keepAspectRatio) ? true : options.keepAspectRatio;
38+
shouldKeepAspectRatio = types.isNullOrUndefined(options.keepAspectRatio) ? shouldKeepAspectRatio : options.keepAspectRatio;
3939
}
4040

4141
if ((<any>android.support.v4.content.ContextCompat).checkSelfPermission(
@@ -77,6 +77,9 @@ export let takePicture = function (options?): Promise<any> {
7777
if (options && options.cameraFacing === "front") {
7878
takePictureIntent.putExtra("android.intent.extras.CAMERA_FACING",
7979
android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);
80+
} else {
81+
takePictureIntent.putExtra("android.intent.extras.CAMERA_FACING",
82+
android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK);
8083
}
8184

8285
if (takePictureIntent.resolveActivity(utils.ad.getApplicationContext().getPackageManager()) != null) {

src/camera.ios.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ export let takePicture = function (options): Promise<any> {
124124
if (options) {
125125
reqWidth = options.width || 0;
126126
reqHeight = options.height || reqWidth;
127-
keepAspectRatio = types.isNullOrUndefined(options.keepAspectRatio) ? true : options.keepAspectRatio;
128-
saveToGallery = options.saveToGallery ? true : false;
127+
keepAspectRatio = types.isNullOrUndefined(options.keepAspectRatio) ? keepAspectRatio : options.keepAspectRatio;
128+
saveToGallery = types.isNullOrUndefined(options.saveToGallery) ? saveToGallery : options.saveToGallery;
129129
}
130130

131131
let authStatus = PHPhotoLibrary.authorizationStatus();

src/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-camera",
3-
"version": "3.2.1",
3+
"version": "4.0.0",
44
"description": "Provides API for using device camera",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)