Skip to content

Commit 69693d9

Browse files
Merge pull request #11 from ionic-team/refactor/minor-api-changes
refactor: Minor API chanegs
2 parents ddcc235 + 33c70c8 commit 69693d9

11 files changed

Lines changed: 92 additions & 94 deletions

File tree

README.md

Lines changed: 33 additions & 25 deletions
Large diffs are not rendered by default.

android/src/main/java/com/capacitorjs/plugins/camera/CameraPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class CameraPlugin : Plugin() {
5353
const val STORE = "CameraStore"
5454
const val EDIT_FILE_NAME_KEY = "EditFileName"
5555
const val ERROR_FORMAT_PREFIX = "OS-PLUG-CAMR-"
56-
const val MEDIA_TYPE_PICTURE = 0
56+
const val MEDIA_TYPE_PHOTO = 0
5757
}
5858

5959
private lateinit var legacyFlow: LegacyCameraFlow

android/src/main/java/com/capacitorjs/plugins/camera/IonCameraFlow.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ class IonCameraFlow(
188188
allowEdit = call.getBoolean("allowEdit") ?: false,
189189
editInApp = call.getBoolean("editInApp") ?: true,
190190
quality = call.getInt("quality") ?: DEFAULT_QUALITY,
191-
width = call.getInt("width") ?: 0,
192-
height = call.getInt("height") ?: 0,
191+
width = call.getInt("targetWidth") ?: 0,
192+
height = call.getInt("targetWidth") ?: 0,
193193
correctOrientation = call.getBoolean("correctOrientation") ?: DEFAULT_CORRECT_ORIENTATION
194194
)
195195
}
@@ -210,15 +210,15 @@ class IonCameraFlow(
210210
fun getCameraSettings(call: PluginCall): IonCameraSettings {
211211
val settings = IonCameraSettings()
212212
settings.quality = call.getInt("quality", IonCameraSettings.DEFAULT_QUALITY)!!
213-
settings.width = call.getInt("width", 0)!!
214-
settings.height = call.getInt("height", 0)!!
213+
settings.targetWidth = call.getInt("targetWidth", 0)!!
214+
settings.targetHeight = call.getInt("targetHeight", 0)!!
215215
settings.correctOrientation = call.getBoolean("correctOrientation", IonCameraSettings.DEFAULT_CORRECT_ORIENTATION)!!
216216
settings.encodingType = call.getInt("encodingType", IonCameraSettings.DEFAULT_ENCODING_TYPE)!!
217217
settings.saveToGallery = call.getBoolean("saveToGallery", IonCameraSettings.DEFAULT_SAVE_IMAGE_TO_GALLERY)!!
218218
settings.allowEdit = call.getBoolean("allowEdit", false)!!
219219
settings.editInApp = call.getBoolean("editInApp", true)!!
220220
settings.includeMetadata = call.getBoolean("includeMetadata", false)!!
221-
settings.shouldResize = settings.width > 0 || settings.height > 0
221+
settings.shouldResize = settings.targetWidth > 0 || settings.targetHeight > 0
222222
return settings
223223
}
224224

@@ -286,7 +286,7 @@ class IonCameraFlow(
286286
return
287287
}
288288

289-
val videoUri = call.getString("videoURI")
289+
val videoUri = call.getString("uri")
290290
?: return sendError(IONCAMRError.PLAY_VIDEO_GENERAL_ERROR)
291291
manager.playVideo(plugin.activity, videoUri, {
292292
call.resolve()
@@ -912,10 +912,10 @@ class IonCameraFlow(
912912
private fun IonCameraSettings.toIonParameters(): IONCAMRCameraParameters {
913913
return IONCAMRCameraParameters(
914914
mQuality = quality,
915-
targetWidth = width,
916-
targetHeight = height,
915+
targetWidth = targetWidth,
916+
targetHeight = targetHeight,
917917
encodingType = encodingType,
918-
mediaType = CameraPlugin.MEDIA_TYPE_PICTURE,
918+
mediaType = CameraPlugin.MEDIA_TYPE_PHOTO,
919919
allowEdit = allowEdit,
920920
correctOrientation = correctOrientation,
921921
saveToPhotoAlbum = saveToGallery,

android/src/main/java/com/capacitorjs/plugins/camera/IonCameraSettings.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package com.capacitorjs.plugins.camera
22

33
class IonCameraSettings {
44
var quality: Int = DEFAULT_QUALITY
5-
var width: Int = 0
6-
var height: Int = 0
5+
var targetWidth: Int = 0
6+
var targetHeight: Int = 0
77
var correctOrientation: Boolean = DEFAULT_CORRECT_ORIENTATION
88
var encodingType: Int = 0 //JPEG
99
var saveToGallery: Boolean = DEFAULT_SAVE_IMAGE_TO_GALLERY

android/src/main/java/com/capacitorjs/plugins/camera/LegacyCameraFlow.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ private CameraResultType getResultType(String resultType) {
231231
}
232232
}
233233

234-
235234
public void openCamera(final PluginCall call) {
236235
if (checkCameraPermissions(call)) {
237236
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

example-app/package-lock.json

Lines changed: 1 addition & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example-app/src/components/camera/ChooseFromGalleryConfigurable.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import React from "react";
1313
import {
1414
Camera,
1515
MediaResult,
16-
MediaType,
16+
MediaTypeSelection,
1717
ChooseFromGalleryOptions,
1818
} from "@capacitor/camera";
1919

@@ -36,7 +36,7 @@ class ChooseFromGalleryConfigurable extends React.Component<
3636
// Initialize with API defaults from ChooseFromGalleryOptions
3737
this.state = {
3838
config: {
39-
mediaType: MediaType.picture,
39+
mediaType: MediaTypeSelection.Photo,
4040
allowMultipleSelection: false,
4141
limit: 0,
4242
includeMetadata: false,
@@ -58,7 +58,7 @@ class ChooseFromGalleryConfigurable extends React.Component<
5858
executeDefault = async (): Promise<void> => {
5959
try {
6060
const result = await Camera.chooseFromGallery({
61-
mediaType: MediaType.picture
61+
mediaType: MediaTypeSelection.Photo
6262
});
6363
console.log('chooseFromGallery result', result);
6464

@@ -82,8 +82,8 @@ class ChooseFromGalleryConfigurable extends React.Component<
8282
editInApp: config.editInApp,
8383
presentationStyle: config.presentationStyle,
8484
quality: config.quality,
85-
width: config.width,
86-
height: config.height,
85+
targetWidth: config.targetWidth,
86+
targetHeight: config.targetHeight,
8787
correctOrientation: config.correctOrientation,
8888
webUseInput: config.webUseInput,
8989
});
@@ -168,29 +168,29 @@ class ChooseFromGalleryConfigurable extends React.Component<
168168
</IonItem>
169169

170170
<IonItem>
171-
<IonLabel position="stacked">Width (optional)</IonLabel>
171+
<IonLabel position="stacked">Target Width (optional)</IonLabel>
172172
<IonInput
173173
type="number"
174174
placeholder="Leave empty for no constraint"
175-
value={config.width ?? ""}
175+
value={config.targetWidth ?? ""}
176176
onIonChange={(e) =>
177177
this.updateConfig(
178-
"width",
178+
"targetWidth",
179179
e.detail.value ? parseInt(e.detail.value) : undefined
180180
)
181181
}
182182
/>
183183
</IonItem>
184184

185185
<IonItem>
186-
<IonLabel position="stacked">Height (optional)</IonLabel>
186+
<IonLabel position="stacked">Target Height (optional)</IonLabel>
187187
<IonInput
188188
type="number"
189189
placeholder="Leave empty for no constraint"
190-
value={config.height ?? ""}
190+
value={config.targetHeight ?? ""}
191191
onIonChange={(e) =>
192192
this.updateConfig(
193-
"height",
193+
"targetHeight",
194194
e.detail.value ? parseInt(e.detail.value) : undefined
195195
)
196196
}

example-app/src/components/camera/MediaCarousel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ const MediaCarousel: React.FC<IMediaCarouselProps> = ({ media, onEditPhoto }) =>
2525

2626
const isVideo = (item: MediaResult): boolean => {
2727
// Primary detection: check MediaType
28-
if (item.type === MediaType.video) {
28+
if (item.type === MediaType.Video) {
2929
return true;
3030
}
31-
if (item.type === MediaType.picture) {
31+
if (item.type === MediaType.Photo) {
3232
return false;
3333
}
3434

example-app/src/components/camera/TakePictureConfigurable.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,29 +169,29 @@ class TakePictureConfigurable extends React.Component<
169169

170170
{/* Dimensions */}
171171
<IonItem>
172-
<IonLabel position="stacked">Width (optional)</IonLabel>
172+
<IonLabel position="stacked">Target Width (optional)</IonLabel>
173173
<IonInput
174174
type="number"
175175
placeholder="Leave empty for no constraint"
176-
value={config.width ?? ""}
176+
value={config.targetWidth ?? ""}
177177
onIonChange={(e) =>
178178
this.updateConfig(
179-
"width",
179+
"targetWidth",
180180
e.detail.value ? parseInt(e.detail.value) : undefined
181181
)
182182
}
183183
/>
184184
</IonItem>
185185

186186
<IonItem>
187-
<IonLabel position="stacked">Height (optional)</IonLabel>
187+
<IonLabel position="stacked">Target Height (optional)</IonLabel>
188188
<IonInput
189189
type="number"
190190
placeholder="Leave empty for no constraint"
191-
value={config.height ?? ""}
191+
value={config.targetHeight ?? ""}
192192
onIonChange={(e) =>
193193
this.updateConfig(
194-
"height",
194+
"targetHeight",
195195
e.detail.value ? parseInt(e.detail.value) : undefined
196196
)
197197
}

example-app/src/pages/RecordVideoPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class RecordVideoPage extends React.Component<{}, IRecordVideoPageState> {
5454
if (!this.state.filePath) return;
5555

5656
try {
57-
await Camera.playVideo({ videoURI: this.state.filePath });
57+
await Camera.playVideo({ uri: this.state.filePath });
5858
} catch (e) {
5959
const error = e as any;
6060
const errorMessage = error.code ? `[${error.code}] ${error.message}` : error.message;

0 commit comments

Comments
 (0)