Skip to content

Commit 4d524d1

Browse files
authored
Merge pull request #25 from ShawnPavel/feature/configurable-confirm-text
Add ability to change confirmation dialog text
2 parents 3214b9b + 0ac1ed3 commit 4d524d1

File tree

7 files changed

+1649
-1031
lines changed

7 files changed

+1649
-1031
lines changed

README.md

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<a align="center" href="https://www.npmjs.com/package/@nstudio/nativescript-camera-plus">
22
<h3 align="center">NativeScript Camera Plus</h3>
33
</a>
4-
<h4 align="center">A NativeScript camera with all the bells and whistles which can be embedded inside a view. This plugin was sponsored by <a href="https://liveshopper.com">LiveShopper<a></h4>
4+
<h4 align="center">A NativeScript camera with all the bells and whistles which can be embedded inside a view. This plugin was sponsored by LiveShopper</h4>
55

66
<p align="center">
7+
<a href="https://liveshopper.com">
78
<img align="center" src="./src/logos/liveshopper.png" alt="LiveShopper Logo"/>
9+
<a>
810
</p>
911

1012
<p align="center">
@@ -84,6 +86,8 @@ npm run demo.ng.android.device
8486
| --------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------- |
8587
| **debug** | boolean | If true logs will be output in the console to help debug the Camera Plus events. |
8688
| **confirmPhotos** | boolean | If true the default take picture event will present a confirmation dialog before saving. Default is true. |
89+
| **confirmRetakeText** | string | When confirming capture this text will be presented to the user to retake the photo. Default is 'Retake' |
90+
| **confirmSaveText** | string | When confirming capture this text will be presented to the user to save the photo. Default is 'Save' |
8791
| **saveToGallery** | boolean | If true the default take picture event will save to device gallery. Default is true. |
8892
| **galleryPickerMode** | string | The gallery/library selection mode. 'single' allows one image to be selected. 'multiple' allows multiple images. Default is 'multiple' |
8993
| **showFlashIcon** | boolean | If true the default flash toggle icon/button will show on the Camera Plus layout. Default is true. |
@@ -92,6 +96,14 @@ npm run demo.ng.android.device
9296
| **showGalleryIcon** | boolean | If true the choose from gallery/library icon/button will show on the Camera Plus layout. Default is true. |
9397
| **enableVideo** | boolean | If true the CameraPlus instance can record video. |
9498

99+
## Static Properties
100+
_Note: These properties need set before the initialization of the camera. Users should set these in a component constructor before their view creates the component if the wish to change the default values._
101+
102+
| Name | Type | Description |
103+
| ------------------ | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
104+
| **enableVideo** | boolean | Video Support (off by default). Can reset it before using in different views if they want to go back/forth between photo/camera and video/camera |
105+
| **defaultCamera** | CameraTypes | Defaults the camera correctly on launch. Default `'rear'`. `'front'` or `'rear'` |
106+
95107
## Android Only Properties
96108

97109
| Name | Type | Description |
@@ -117,14 +129,14 @@ npm run demo.ng.android.device
117129
| **toggleFlash()** | Toggles the flash mode on the active camera. |
118130
| **toggleCamera()** | Toggles the active camera on the device. |
119131
| **chooseFromLibrary(opts?: IChooseOptions)** | Opens the device gallery (image library) for selecting images. |
120-
| **takePicture()** | Takes a picture of the current preview in the CameraPlus. |
121-
| **getFlashMode(): string** | Android: various strings possible: https://developer.android.com/reference/android/hardware/Camera.Parameters.html#getFlashMode() iOS: either 'on' or 'off' |
132+
| **takePicture(opts?: ICaptureOptions)** | Takes a picture of the current preview in the CameraPlus. |
133+
| **getFlashMode(): string** | Android: various strings possible: https://developer.android.com/reference/android/hardware/Camera.Parameters.html#getFlashMode() iOS: either `'on'` or `'off'` |
122134
| **record(opts?: IVideoOptions)** | Starts recording a video. |
123135
| **stop()** | Stops the video recording, when stopped the `videoRecordingReadyEvent` event will be emitted. |
124136

125137
## Android Only Public Methods
126138

127-
| Method | Description |
139+
| Method | Description |
128140
| ------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
129141
| **requestCameraPermissions(explanationText?: string)** | Prompts the user to grant runtime permission to use the device camera. Returns a Promise<boolean>. |
130142
| **hasCameraPermission()** | Returns true if the application has been granted access to the device camera. |
@@ -137,6 +149,41 @@ npm run demo.ng.android.device
137149

138150
| Name | Description |
139151
| ----------------------- | ------------------------------------------------------------------ |
152+
| **errorEvent** | Executes when an error is emitted from CameraPlu |
140153
| **photoCapturedEvent** | Executes when a photo is taken. |
141154
| **toggleCameraEvent** | Executes when the device camera is toggled. |
142155
| **imagesSelectedEvent** | Executes when images are selected from the device library/gallery. |
156+
| **videoRecordingStartedEvent** | Executes when video starts recording. |
157+
| **videoRecordingFinishedEvent** | Executes when video stops recording but has not process yet. |
158+
| **videoRecordingReadyEvent** | Executes when video has completed processing and is ready to be used. |
159+
160+
161+
## Option Interfaces
162+
```TS
163+
export interface ICameraOptions {
164+
confirm?: boolean;
165+
saveToGallery?: boolean;
166+
keepAspectRatio?: boolean;
167+
height?: number;
168+
width?: number;
169+
autoSquareCrop?: boolean;
170+
confirmRetakeText?: string;
171+
confirmSaveText?: string;
172+
}
173+
```
174+
```TS
175+
export interface IChooseOptions {
176+
width?: number;
177+
height?: number;
178+
keepAspectRatio?: boolean;
179+
}
180+
```
181+
182+
```TS
183+
export interface IVideoOptions {
184+
confirm?: boolean;
185+
saveToGallery?: boolean;
186+
height?: number;
187+
width?: number;
188+
}
189+
```

demo-ng/app/capture/capture.component.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,30 @@
22
</ActionBar>
33
<ScrollView>
44
<GridLayout rows="250, auto, *">
5-
6-
<CameraPlus debug="true"
5+
<CameraPlus height="250" debug="true"
76
galleryPickerMode="single"
87
showFlashIcon="true"
98
showToggleIcon="true"
109
showCaptureIcon="true"
1110
showGalleryIcon="true"
11+
confirmSaveText="CONFIRM!"
12+
confirmRetakeText="RETAKE!"
1213
(loaded)="camLoaded($event)"
1314
(toggleCameraEvent)="toggleCameraEvent($event)"
1415
(photoCapturedEvent)="photoCapturedEvent($event)"
1516
(imagesSelectedEvent)="imagesSelectedEvent($event)">
1617

17-
<!-- OVERLAY CONTENT-->
18-
<GridLayout rows="*, auto, *" columns="*, auto, *">
18+
<!-- OVERLAY CONTENT -->
19+
<!-- <GridLayout rows="*, auto, *" columns="*, auto, *">
1920
<GridLayout colSpan="3" class="bg-overlay"></GridLayout>
2021
<GridLayout row="1" class="bg-overlay"></GridLayout>
2122
<GridLayout row="1" col="2" class="bg-overlay"></GridLayout>
2223
<GridLayout row="2" colSpan="3" class="bg-overlay"></GridLayout>
2324
<Label row="1" col="1" class="overlay-label" text="📷➕"></Label>
2425
<Image src="https://d2odgkulk9w7if.cloudfront.net/images/default-source/default-album/nativescript.png" row="1" col="1" stretch="aspectFill"
25-
class="overlay"></Image>
26+
class="overlay" width="20" height="20"></Image>
2627
<Image src="res://nativescript" row="1" col="1" stretch="aspectFill" class="overlay"></Image>
27-
</GridLayout>
28+
</GridLayout> -->
2829

2930
</CameraPlus>
3031

src/camera-plus.android.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,8 @@ export class CameraPlus extends CameraPlusBase {
12001200
*/
12011201
private async _finishSavingAndConfirmingPicture(options: ICameraOptions, data) {
12021202
let confirmPic;
1203+
let confirmPicRetakeText;
1204+
let confirmPicSaveText;
12031205
let saveToGallery;
12041206
let reqWidth;
12051207
let reqHeight;
@@ -1209,6 +1211,8 @@ export class CameraPlus extends CameraPlusBase {
12091211
const density = utils.layout.getDisplayDensity();
12101212
if (options) {
12111213
confirmPic = options.confirm ? true : false;
1214+
confirmPicRetakeText = options.confirmRetakeText ? options.confirmRetakeText : this.confirmRetakeText;
1215+
confirmPicSaveText = options.confirmSaveText ? options.confirmSaveText : this.confirmSaveText;
12121216
saveToGallery = options.saveToGallery ? true : false;
12131217
reqWidth = options.width ? options.width * density : 0;
12141218
reqHeight = options.height ? options.height * density : reqWidth;
@@ -1360,7 +1364,11 @@ export class CameraPlus extends CameraPlusBase {
13601364
CLog('nativeFile', nativeFile);
13611365

13621366
if (saveToGallery === true && confirmPic === true) {
1363-
const result = await CamHelpers.createImageConfirmationDialog(data).catch(ex => {
1367+
const result = await CamHelpers.createImageConfirmationDialog(
1368+
data,
1369+
confirmPicRetakeText,
1370+
confirmPicSaveText
1371+
).catch(ex => {
13641372
CLog('Error createImageConfirmationDialog', ex);
13651373
});
13661374

src/camera-plus.common.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ export abstract class CameraPlusBase extends ContentView implements CameraPlusDe
7979
*/
8080
@GetSetProperty() public confirmPhotos: boolean = true;
8181

82+
/**
83+
* When confirming capture this text will be presented to the user to retake the photo. Default is 'Retake'
84+
*/
85+
@GetSetProperty() public confirmRetakeText?: string;
86+
87+
/**
88+
* When confirming capture this text will be presented to the user to save the photo. Default is 'Save'
89+
*/
90+
@GetSetProperty() public confirmSaveText?: string;
91+
8292
/**
8393
* If true the default videorecordingready event will present a confirmation dialog. Default is false.
8494
*/
@@ -298,6 +308,8 @@ export interface ICameraOptions {
298308
height?: number;
299309
width?: number;
300310
autoSquareCrop?: boolean;
311+
confirmRetakeText?: string;
312+
confirmSaveText?: string;
301313
}
302314

303315
export interface IChooseOptions {

0 commit comments

Comments
 (0)