-
Notifications
You must be signed in to change notification settings - Fork 349
Closed
Labels
Description
We are customising the AttachButton
as per doc and uploading new images using uploadNewImage
. This works fine. However, when the image is attached inside the message list, there is a weird grey view appearing bottom of the image.
Please note that when user goes back and come back to the chat screen again, the image is rendered fine. Only when the image is attached instantly in a message then the issue occurs. I believe this happens mainly when I am taking the picture in Potrait mode.
This is after I attach a photo from camera,
But the image renders fine when I come back to chat,
This is how my code looks,
// Custom attach button component
const CustomAttachButton = () => {
const {showActionSheetWithOptions} = useActionSheet();
const {uploadNewImage} = useMessageInputContext();
const compressAndUploadImage = async imageFile => {
try {
const compressedUri = await ImageCompressor.compress(imageFile.uri, {
compressionMethod: 'auto',
});
return uploadNewImage({
name: imageFile.fileName,
type: imageFile.type,
uri: compressedUri,
});
} catch (error) {
// Fallback to original image if compression fails
return uploadNewImage({
name: imageFile.fileName,
type: imageFile.type,
uri: imageFile.uri,
});
}
};
const pickImageFromGallery = async () => {
try {
const images = await launchImageLibrary({
selectionLimit: 1,
mediaType: 'photo',
});
if (images?.assets?.length > 0) {
const selectedImage = images.assets[0];
await compressAndUploadImage(selectedImage);
}
} catch (error) {
console.error('Error picking image from gallery:', error);
}
};
const pickImageFromCamera = async () => {
try {
if (Platform.OS === 'android') {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.CAMERA,
{
title: 'Camera Permission',
message: 'ShiftCare needs camera permission to take photos',
buttonNeutral: 'Ask Me Later',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
},
);
if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
console.log('Camera permission denied');
return;
}
}
const images = await launchCamera({
mediaType: 'photo',
});
if (images?.assets?.length > 0) {
const selectedImage = images.assets[0];
await compressAndUploadImage(selectedImage);
}
} catch (error) {
console.error('Error picking image from camera:', error);
}
};
const onPress = () => {
showActionSheetWithOptions(
{
cancelButtonIndex: 2,
destructiveButtonIndex: 2,
options: ['Photo Library', 'Camera', 'Cancel'],
},
buttonIndex => {
switch (buttonIndex) {
case 0:
pickImageFromGallery();
break;
case 1:
pickImageFromCamera();
break;
default:
break;
}
},
);
};
return <AttachButton handleOnPress={onPress} />;
};
// Chat component
return (
<SafeAreaView edges={['bottom']} className="flex-1">
<ActionSheetProvider>
<ChannelComponent
key={channel.cid}
supportedReactions={supportedReactions}
hasFilePicker={false}
MessageFooter={featureReadReceipts ? CustomMessageFooter : () => null}
CommandsButton={() => null}
AttachButton={CustomAttachButton}
channel={channel}>
<MessageList />
<MessageInput />
<BottomSpacing />
</ChannelComponent>
</ActionSheetProvider>
</SafeAreaView>
);