Skip to content

Commit

Permalink
Picture quality is now customizable.
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswilddev committed Jul 22, 2024
1 parent 3706c8c commit 6d6f2d1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
11 changes: 7 additions & 4 deletions react-native/services/PictureHelper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ export class PictureHelper implements PictureHelperInterface {
* @param fileStore The file store in which pictures are to be stored.
* @param permissionHelper The permission helper which will be used when
* acquiring pictures.
* @param quality The compression quality to use, where 0 is minimum
* and 1 is maximum.
*/
constructor (
private readonly fileStore: FileStoreInterface,
private readonly permissionHelper: PermissionHelper
private readonly permissionHelper: PermissionHelper,
private readonly quality: number
) {}

async takePicture (
Expand All @@ -30,7 +33,7 @@ export class PictureHelper implements PictureHelperInterface {
async () => {
const result = await ImagePicker.launchCameraAsync({
allowsEditing: true,
quality: 0.7,
quality: this.quality,
mediaTypes: ImagePicker.MediaTypeOptions.Images,
exif: false,
base64: false,
Expand Down Expand Up @@ -70,7 +73,7 @@ export class PictureHelper implements PictureHelperInterface {
async () => {
const result = await ImagePicker.launchImageLibraryAsync({
allowsEditing: true,
quality: 0.7,
quality: this.quality,
mediaTypes: ImagePicker.MediaTypeOptions.Images,
exif: false,
base64: false,
Expand Down Expand Up @@ -103,7 +106,7 @@ export class PictureHelper implements PictureHelperInterface {
async () => {
const result = await ImagePicker.launchImageLibraryAsync({
allowsEditing: true,
quality: 0.7,
quality: this.quality,
mediaTypes: ImagePicker.MediaTypeOptions.Images,
exif: false,
base64: false,
Expand Down
2 changes: 1 addition & 1 deletion react-native/services/PictureHelper/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Provides helpers for working with pictures.
```tsx
import type { PictureHelper } from "react-native-app-helpers";

const pictureHelper = new PictureHelper(fileStore, permissionHelper);
const pictureHelper = new PictureHelper(fileStore, permissionHelper, 0.7);

// Do NOT save to media library.
await permissionHelper.takePicture(
Expand Down
52 changes: 26 additions & 26 deletions react-native/services/PictureHelper/unit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test('take picture without saving to media library permission denied', async ()
const onCancel = jest.fn().mockResolvedValue(undefined)
const onSuccess = jest.fn()

const pictureHelper = new PictureHelper(fileStore, permissionHelper)
const pictureHelper = new PictureHelper(fileStore, permissionHelper, 0.35)

await pictureHelper.takePicture(
false,
Expand Down Expand Up @@ -78,7 +78,7 @@ test('take picture saving to media library permission denied', async () => {
const onCancel = jest.fn().mockResolvedValue(undefined)
const onSuccess = jest.fn()

const pictureHelper = new PictureHelper(fileStore, permissionHelper)
const pictureHelper = new PictureHelper(fileStore, permissionHelper, 0.35)

await pictureHelper.takePicture(
true,
Expand Down Expand Up @@ -133,7 +133,7 @@ test('take picture without saving to media library cancelled', async () => {
const onCancel = jest.fn().mockResolvedValue(undefined)
const onSuccess = jest.fn()

const pictureHelper = new PictureHelper(fileStore, permissionHelper)
const pictureHelper = new PictureHelper(fileStore, permissionHelper, 0.35)

await pictureHelper.takePicture(
false,
Expand All @@ -149,7 +149,7 @@ test('take picture without saving to media library cancelled', async () => {
expect(ImagePicker.launchCameraAsync).toHaveBeenCalledTimes(1)
expect(ImagePicker.launchCameraAsync).toBeCalledWith({
allowsEditing: true,
quality: 0.7,
quality: 0.35,
mediaTypes: ImagePicker.MediaTypeOptions.Images,
exif: false,
base64: false,
Expand Down Expand Up @@ -196,7 +196,7 @@ test('take picture without saving to media library none selected', async () => {
const onCancel = jest.fn().mockResolvedValue(undefined)
const onSuccess = jest.fn()

const pictureHelper = new PictureHelper(fileStore, permissionHelper)
const pictureHelper = new PictureHelper(fileStore, permissionHelper, 0.35)

await pictureHelper.takePicture(
false,
Expand All @@ -212,7 +212,7 @@ test('take picture without saving to media library none selected', async () => {
expect(ImagePicker.launchCameraAsync).toHaveBeenCalledTimes(1)
expect(ImagePicker.launchCameraAsync).toBeCalledWith({
allowsEditing: true,
quality: 0.7,
quality: 0.35,
mediaTypes: ImagePicker.MediaTypeOptions.Images,
exif: false,
base64: false,
Expand Down Expand Up @@ -258,7 +258,7 @@ test('take picture saving to media library cancelled', async () => {
const onCancel = jest.fn().mockResolvedValue(undefined)
const onSuccess = jest.fn()

const pictureHelper = new PictureHelper(fileStore, permissionHelper)
const pictureHelper = new PictureHelper(fileStore, permissionHelper, 0.35)

await pictureHelper.takePicture(
true,
Expand All @@ -274,7 +274,7 @@ test('take picture saving to media library cancelled', async () => {
expect(ImagePicker.launchCameraAsync).toHaveBeenCalledTimes(1)
expect(ImagePicker.launchCameraAsync).toBeCalledWith({
allowsEditing: true,
quality: 0.7,
quality: 0.35,
mediaTypes: ImagePicker.MediaTypeOptions.Images,
exif: false,
base64: false,
Expand Down Expand Up @@ -321,7 +321,7 @@ test('take picture saving to media library none selected', async () => {
const onCancel = jest.fn().mockResolvedValue(undefined)
const onSuccess = jest.fn()

const pictureHelper = new PictureHelper(fileStore, permissionHelper)
const pictureHelper = new PictureHelper(fileStore, permissionHelper, 0.35)

await pictureHelper.takePicture(
true,
Expand All @@ -337,7 +337,7 @@ test('take picture saving to media library none selected', async () => {
expect(ImagePicker.launchCameraAsync).toHaveBeenCalledTimes(1)
expect(ImagePicker.launchCameraAsync).toBeCalledWith({
allowsEditing: true,
quality: 0.7,
quality: 0.35,
mediaTypes: ImagePicker.MediaTypeOptions.Images,
exif: false,
base64: false,
Expand Down Expand Up @@ -384,7 +384,7 @@ test('take picture without saving to media library successful', async () => {
const onCancel = jest.fn()
const onSuccess = jest.fn().mockResolvedValue(undefined)

const pictureHelper = new PictureHelper(fileStore, permissionHelper)
const pictureHelper = new PictureHelper(fileStore, permissionHelper, 0.35)

await pictureHelper.takePicture(
false,
Expand All @@ -403,7 +403,7 @@ test('take picture without saving to media library successful', async () => {
expect(ImagePicker.launchCameraAsync).toHaveBeenCalledTimes(1)
expect(ImagePicker.launchCameraAsync).toBeCalledWith({
allowsEditing: true,
quality: 0.7,
quality: 0.35,
mediaTypes: ImagePicker.MediaTypeOptions.Images,
exif: false,
base64: false,
Expand Down Expand Up @@ -460,7 +460,7 @@ test('take picture saving to media library successful', async () => {
const onCancel = jest.fn()
const onSuccess = jest.fn().mockResolvedValue(undefined)

const pictureHelper = new PictureHelper(fileStore, permissionHelper)
const pictureHelper = new PictureHelper(fileStore, permissionHelper, 0.35)

await pictureHelper.takePicture(
true,
Expand All @@ -479,7 +479,7 @@ test('take picture saving to media library successful', async () => {
expect(ImagePicker.launchCameraAsync).toHaveBeenCalledTimes(1)
expect(ImagePicker.launchCameraAsync).toBeCalledWith({
allowsEditing: true,
quality: 0.7,
quality: 0.35,
mediaTypes: ImagePicker.MediaTypeOptions.Images,
exif: false,
base64: false,
Expand Down Expand Up @@ -527,7 +527,7 @@ test('select one picture from media library permission denied', async () => {
const onCancel = jest.fn().mockResolvedValue(undefined)
const onSuccess = jest.fn()

const pictureHelper = new PictureHelper(fileStore, permissionHelper)
const pictureHelper = new PictureHelper(fileStore, permissionHelper, 0.35)

await pictureHelper.selectOnePictureFromMediaLibrary(
onPermissionDenied,
Expand Down Expand Up @@ -581,7 +581,7 @@ test('select one picture from media library cancelled', async () => {
const onCancel = jest.fn()
const onSuccess = jest.fn().mockResolvedValue(undefined)

const pictureHelper = new PictureHelper(fileStore, permissionHelper)
const pictureHelper = new PictureHelper(fileStore, permissionHelper, 0.35)

await pictureHelper.selectOnePictureFromMediaLibrary(
onPermissionDenied,
Expand All @@ -597,7 +597,7 @@ test('select one picture from media library cancelled', async () => {
expect(ImagePicker.launchImageLibraryAsync).toHaveBeenCalledTimes(1)
expect(ImagePicker.launchImageLibraryAsync).toBeCalledWith({
allowsEditing: true,
quality: 0.7,
quality: 0.35,
mediaTypes: ImagePicker.MediaTypeOptions.Images,
exif: false,
base64: false,
Expand Down Expand Up @@ -644,7 +644,7 @@ test('select one picture from media library no assets', async () => {
const onCancel = jest.fn()
const onSuccess = jest.fn().mockResolvedValue(undefined)

const pictureHelper = new PictureHelper(fileStore, permissionHelper)
const pictureHelper = new PictureHelper(fileStore, permissionHelper, 0.35)

await pictureHelper.selectOnePictureFromMediaLibrary(
onPermissionDenied,
Expand All @@ -660,7 +660,7 @@ test('select one picture from media library no assets', async () => {
expect(ImagePicker.launchImageLibraryAsync).toHaveBeenCalledTimes(1)
expect(ImagePicker.launchImageLibraryAsync).toBeCalledWith({
allowsEditing: true,
quality: 0.7,
quality: 0.35,
mediaTypes: ImagePicker.MediaTypeOptions.Images,
exif: false,
base64: false,
Expand Down Expand Up @@ -707,7 +707,7 @@ test('select one picture from media library successful', async () => {
const onCancel = jest.fn()
const onSuccess = jest.fn().mockResolvedValue(undefined)

const pictureHelper = new PictureHelper(fileStore, permissionHelper)
const pictureHelper = new PictureHelper(fileStore, permissionHelper, 0.35)

await pictureHelper.selectOnePictureFromMediaLibrary(
onPermissionDenied,
Expand All @@ -726,7 +726,7 @@ test('select one picture from media library successful', async () => {
expect(ImagePicker.launchImageLibraryAsync).toHaveBeenCalledTimes(1)
expect(ImagePicker.launchImageLibraryAsync).toBeCalledWith({
allowsEditing: true,
quality: 0.7,
quality: 0.35,
mediaTypes: ImagePicker.MediaTypeOptions.Images,
exif: false,
base64: false,
Expand Down Expand Up @@ -769,7 +769,7 @@ test('select multiple pictures from media library permission denied', async () =
const onCancel = jest.fn().mockResolvedValue(undefined)
const onSuccess = jest.fn()

const pictureHelper = new PictureHelper(fileStore, permissionHelper)
const pictureHelper = new PictureHelper(fileStore, permissionHelper, 0.35)

await pictureHelper.selectMultiplePicturesFromMediaLibrary(
onPermissionDenied,
Expand Down Expand Up @@ -823,7 +823,7 @@ test('select multiple pictures from media library cancelled', async () => {
const onCancel = jest.fn()
const onSuccess = jest.fn().mockResolvedValue(undefined)

const pictureHelper = new PictureHelper(fileStore, permissionHelper)
const pictureHelper = new PictureHelper(fileStore, permissionHelper, 0.35)

await pictureHelper.selectMultiplePicturesFromMediaLibrary(
onPermissionDenied,
Expand All @@ -839,7 +839,7 @@ test('select multiple pictures from media library cancelled', async () => {
expect(ImagePicker.launchImageLibraryAsync).toHaveBeenCalledTimes(1)
expect(ImagePicker.launchImageLibraryAsync).toBeCalledWith({
allowsEditing: true,
quality: 0.7,
quality: 0.35,
mediaTypes: ImagePicker.MediaTypeOptions.Images,
exif: false,
base64: false,
Expand Down Expand Up @@ -900,7 +900,7 @@ test('select multiple pictures from media library successful', async () => {
const onCancel = jest.fn()
const onSuccess = jest.fn().mockResolvedValue(undefined)

const pictureHelper = new PictureHelper(fileStore, permissionHelper)
const pictureHelper = new PictureHelper(fileStore, permissionHelper, 0.35)

await pictureHelper.selectMultiplePicturesFromMediaLibrary(
onPermissionDenied,
Expand All @@ -921,7 +921,7 @@ test('select multiple pictures from media library successful', async () => {
expect(ImagePicker.launchImageLibraryAsync).toHaveBeenCalledTimes(1)
expect(ImagePicker.launchImageLibraryAsync).toBeCalledWith({
allowsEditing: true,
quality: 0.7,
quality: 0.35,
mediaTypes: ImagePicker.MediaTypeOptions.Images,
exif: false,
base64: false,
Expand Down

0 comments on commit 6d6f2d1

Please sign in to comment.