about summary refs log tree commit diff
path: root/src/lib/media/picker.e2e.tsx
blob: 9805c346421aa851100889f210a65980f3cdc95a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import {RootStoreModel} from 'state/index'
import {Image as RNImage} from 'react-native-image-crop-picker'
import RNFS from 'react-native-fs'
import {CropperOptions} from './types'
import {compressIfNeeded} from './manip'

let _imageCounter = 0
async function getFile() {
  const files = await RNFS.readDir(
    RNFS.LibraryDirectoryPath.split('/')
      .slice(0, -5)
      .concat(['Media', 'DCIM', '100APPLE'])
      .join('/'),
  )
  const file = files[_imageCounter++ % files.length]
  return await compressIfNeeded({
    path: file.path,
    mime: 'image/jpeg',
    size: file.size,
    width: 4288,
    height: 2848,
  })
}

export async function openPicker(_store: RootStoreModel): Promise<RNImage[]> {
  return [await getFile()]
}

export async function openCamera(_store: RootStoreModel): Promise<RNImage> {
  return await getFile()
}

export async function openCropper(
  _store: RootStoreModel,
  opts: CropperOptions,
): Promise<RNImage> {
  return {
    path: opts.path,
    mime: 'image/jpeg',
    size: 123,
    width: 4288,
    height: 2848,
  }
}