aboutsummaryrefslogtreecommitdiff
path: root/src/components/camera/GalleryIcon.tsx
blob: bc8b1d41c74e959ca3baf00f06ebe263489da582 (plain)
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
45
46
47
48
49
50
51
52
53
54
55
import {useNavigation} from '@react-navigation/native';
import React from 'react';
import {Image, Text, TouchableOpacity, View} from 'react-native';
import {ScreenType} from '../../types';
import {navigateToImagePicker} from '../../utils/camera';
import {styles} from './styles';

interface GalleryIconProps {
  screenType: ScreenType;
  title: string;
  mostRecentPhotoUri: string;
}

/*
 * Displays the most recent photo in the user's gallery
 * On click, navigates to the image picker
 */
export const GalleryIcon: React.FC<GalleryIconProps> = ({
  screenType,
  title,
  mostRecentPhotoUri,
}) => {
  const navigation = useNavigation();
  return (
    <TouchableOpacity
      onPress={() =>
        navigateToImagePicker((pic) =>
          navigation.navigate('ZoomInCropper', {
            screenType,
            title,
            media: {
              filename: pic.filename,
              uri: pic.path,
              isVideo: false,
            },
          }),
        )
      }
      style={styles.saveButton}>
      {mostRecentPhotoUri !== '' ? (
        <Image
          source={{uri: mostRecentPhotoUri}}
          width={40}
          height={40}
          style={styles.galleryIcon}
        />
      ) : (
        <View style={styles.galleryIconEmpty} />
      )}
      <Text style={styles.saveButtonLabel}>Gallery</Text>
    </TouchableOpacity>
  );
};

export default GalleryIcon;