Skip to content

Commit

Permalink
feat(camera): make prompt strings localizable (#2631)
Browse files Browse the repository at this point in the history
  • Loading branch information
rdlabo committed Apr 30, 2020
1 parent 89c64af commit 0c09fc8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,13 @@ private void doShow(PluginCall call) {

private void showPrompt(final PluginCall call) {
// We have all necessary permissions, open the camera
String promptLabelPhoto = call.getString("promptLabelPhoto", "From Photos");
String promptLabelPicture = call.getString("promptLabelPicture", "Take Picture");

JSObject fromPhotos = new JSObject();
fromPhotos.put("title", "From Photos");
fromPhotos.put("title", promptLabelPhoto);
JSObject takePicture = new JSObject();
takePicture.put("title", "Take Picture");
takePicture.put("title", promptLabelPicture);
Object[] options = new Object[] {
fromPhotos,
takePicture
Expand Down
13 changes: 13 additions & 0 deletions core/src/core-plugin-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,19 @@ export interface CameraOptions {
* iOS only: The presentation style of the Camera. Defaults to fullscreen.
*/
presentationStyle?: 'fullscreen' | 'popover';

/**
* If use CameraSource.Prompt only, can change Prompt label.
* default:
* promptLabelHeader : 'Photo' // iOS only
* promptLabelCancel : 'Cancel' // iOS only
* promptLabelPhoto : 'From Photos'
* promptLabelPicture : 'Take Picture'
*/
promptLabelHeader?: string;
promptLabelCancel?: string;
promptLabelPhoto?: string;
promptLabelPicture?: string;
}

export enum CameraSource {
Expand Down
13 changes: 9 additions & 4 deletions ios/Capacitor/Capacitor/Plugins/Camera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,21 @@ public class CAPCameraPlugin : CAPPlugin, UIImagePickerControllerDelegate, UINav

func showPrompt(_ call: CAPPluginCall) {
// Build the action sheet
let alert = UIAlertController(title: "Photo", message: nil, preferredStyle: UIAlertController.Style.actionSheet)
alert.addAction(UIAlertAction(title: "From Photos", style: .default, handler: { (action: UIAlertAction) in
let promptLabelHeader = call.getString("promptLabelHeader") ?? "Photo"
let promptLabelPhoto = call.getString("promptLabelPhoto") ?? "From Photos"
let promptLabelPicture = call.getString("promptLabelPicture") ?? "Take Picture"
let promptLabelCancel = call.getString("promptLabelCancel") ?? "Cancel"

let alert = UIAlertController(title: promptLabelHeader, message: nil, preferredStyle: UIAlertController.Style.actionSheet)
alert.addAction(UIAlertAction(title: promptLabelPhoto, style: .default, handler: { (action: UIAlertAction) in
self.showPhotos(call)
}))

alert.addAction(UIAlertAction(title: "Take Picture", style: .default, handler: { (action: UIAlertAction) in
alert.addAction(UIAlertAction(title: promptLabelPicture, style: .default, handler: { (action: UIAlertAction) in
self.showCamera(call)
}))

alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (action: UIAlertAction) in
alert.addAction(UIAlertAction(title: promptLabelCancel, style: .cancel, handler: { (action: UIAlertAction) in
self.call?.error("User cancelled photos app")
}))

Expand Down

0 comments on commit 0c09fc8

Please sign in to comment.