Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(camera): make prompt strings localizable #2631

Merged
merged 2 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -103,10 +103,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 @@ -342,6 +342,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
var promptLabelHeader = call.getString("promptLabelHeader") ?? "Photo"
var promptLabelPhoto = call.getString("promptLabelPhoto") ?? "From Photos"
var promptLabelPicture = call.getString("promptLabelPicture") ?? "Take Picture"
var promptLabelCancel = call.getString("promptLabelCancel") ?? "Cancel"
jcesarmobile marked this conversation as resolved.
Show resolved Hide resolved

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