Skip to content

Commit

Permalink
fix image picker not picking
Browse files Browse the repository at this point in the history
  • Loading branch information
MuhammedKpln committed Mar 1, 2022
1 parent 8f409ca commit 5e7db03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
27 changes: 13 additions & 14 deletions src/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,19 @@ function _Footer(props: IFooterProps) {
}, []);

const onPressImage = useCallback(async () => {
selectImage().then((r) =>
setImage((prev) => {
if (prev) {
prev.concat({
uri: r.uri,
base64: r.base64,
type: MediaType.Image,
});
}

return prev;
})
);
}, []);
selectImage().then((r) => {
const assets = {
type: MediaType.Image,
uri: r?.assets[0].uri ?? r.uri,
base64: r?.assets[0].base64 ?? r.base64,
};
if (image) {
setImage([...image, assets]);
} else {
setImage([assets]);
}
});
}, [image]);

return (
<View
Expand Down
4 changes: 1 addition & 3 deletions src/utils/imagePicker.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
let imagePicker: any;
let isExpo: boolean = false;

try {
imagePicker = require('expo-image-picker');
isExpo = true;
} catch {
try {
imagePicker = require('react-native-image-picker');
Expand All @@ -15,7 +13,7 @@ try {
}

export async function selectImage() {
if (isExpo) {
if (imagePicker?.launchImageLibraryAsync) {
return await imagePicker.launchImageLibraryAsync({
base64: true,
});
Expand Down

0 comments on commit 5e7db03

Please sign in to comment.