index.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import React, { FC, useState } from 'react';
  2. import { Image, Text, TouchableOpacity } from 'react-native';
  3. import * as ImagePicker from 'expo-image-picker';
  4. import * as FileSystem from 'expo-file-system';
  5. import AddIcon from '../../../assets/icons/add.svg';
  6. import { styles } from './styles';
  7. //TODO: simple refactor + download photo
  8. export const AvatarPicker: FC = () => {
  9. const [image, setImage] = useState('');
  10. const pickImage = async () => {
  11. // No permissions request is necessary for launching the image library
  12. let result = await ImagePicker.launchImageLibraryAsync({
  13. mediaTypes: ImagePicker.MediaTypeOptions.Images,
  14. allowsEditing: true,
  15. aspect: [4, 3],
  16. quality: 1
  17. });
  18. console.log(result);
  19. if (!result.canceled) {
  20. setImage(result.assets[0].uri);
  21. // const uploadResult = await FileSystem.uploadAsync(
  22. // 'https://nomadmania.eu/webapi/user/join2',
  23. // result.assets[0].uri,
  24. // {
  25. // httpMethod: 'POST',
  26. // uploadType: FileSystem.FileSystemUploadType.MULTIPART,
  27. // fieldName: 'demo_image',
  28. // headers: {
  29. // nmusername: 'test',
  30. // nmemail: 'test@gmail.com',
  31. // nmpassword: 'testpass123',
  32. // nmfirstname: 'Name',
  33. // nmlastname: 'Lastname',
  34. // nmdateofbirth: `${new Date()}`,
  35. // nmhomebase: 'testid10'
  36. // }
  37. // }
  38. // );
  39. //
  40. // console.log(JSON.stringify(uploadResult));
  41. }
  42. };
  43. return (
  44. <TouchableOpacity style={styles.avatarWrapper} onPress={pickImage}>
  45. {!image && (
  46. <>
  47. <AddIcon />
  48. <Text style={styles.textAvatar}>Upload Photo</Text>
  49. </>
  50. )}
  51. {image && (
  52. <Image source={{ uri: image }} style={{ width: 100, height: 100, borderRadius: 100 / 2 }} />
  53. )}
  54. </TouchableOpacity>
  55. );
  56. };