-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not working image full size modal #2567
Comments
|
same problem |
I had the same problem, and looked into the lightbox implementation and the code of how gifted chat uses it.
The width is the width of the screen from |
Can u point me where can I find this code ? |
@tvuquoc17a |
sup, guys
in short, such a thing happens, messages with pictures work fine, but when you click on the picture, a modal opens without the picture itself (just a black background). Although the chat message is displayed normally
import React, {
useCallback,
useEffect,
useLayoutEffect,
useMemo,
useRef,
useState,
} from "react";
import {
View,
Text,
StyleSheet,
TextInput,
TouchableOpacity,
FlatList,
Image,
I18nManager,
Platform,
Keyboard,
Dimensions,
} from "react-native";
import { useTranslation } from "react-i18next";
import { useAppSelector } from "../../redux/store/hooks";
import CustomBttn from "../../components/CustomButton";
import Plane from "../../assets/pictures/plane.svg";
import {
Bubble,
GiftedChat,
IMessage,
InputToolbar,
MessageImage,
} from "react-native-gifted-chat";
import {
collection,
addDoc,
orderBy,
query,
onSnapshot,
} from "firebase/firestore";
import { db, auth } from "../../../firebase";
import { add, set } from "lodash";
import FastImage from "react-native-fast-image";
import i18n from "../../services/i18n";
import PhotoPicker from "../../components/PhotoPicker";
import * as FileSystem from "expo-file-system";
import * as ImageManipulator from "expo-image-manipulator";
import { getImageType } from "../../utils/getPhotoType";
const ChatScreen = ({ navigation, route }: any) => {
const { chat } = route.params;
const user = useAppSelector((state) => state.user);
const [isPickerVisible, setIsPickerVisible] = useState(false);
const [fileUri, setFileUri] = useState('');
const fileBase64 = useRef('');
const anotherUser = chat.participants.find(
(member: { id: number }) => member.id !== user.id
);
const [messages, setMessages] = useState<IMessage[]>([]);
useLayoutEffect(() => {
const collectionRef = collection(db, "chats", chat.id, "messages");
const q = query(collectionRef, orderBy("createdAt", "desc"));
const unsubscribe = onSnapshot(q, (snapshot) => {
setMessages(
snapshot.docs.map((doc) => ({
_id: doc.id,
createdAt: doc.data().createdAt.toDate(),
image: doc.data().image,
text: doc.data().text,
user: doc.data().user,
}))
);
});
}, []);
const onSend = useCallback((messages: IMessage[] = []) => {
setMessages((previousMessages) =>
GiftedChat.append(previousMessages, messages)
);
const { _id, createdAt, text, user } = messages[0];
addDoc(collection(db, "chats", chat.id, "messages"), {
_id,
createdAt,
text,
user,
// video,
image: fileBase64.current ?
data:jpg;base64,${fileBase64.current}
: '',});
setFileUri('');
fileBase64.current = '';
Keyboard.dismiss();
}, []);
const selectFile = async (uri: string | null) => {
if (uri) {
try {
const manipulatedImage = await ImageManipulator.manipulateAsync(
uri,
[{ resize: { width: 200 } }],
{ compress: 0.1, format: ImageManipulator.SaveFormat.JPEG }
);
const base64String = await FileSystem.readAsStringAsync(
manipulatedImage.uri,
{
encoding: FileSystem.EncodingType.Base64,
}
);
};
return (
<GiftedChat
messages={messages}
onSend={(messages) => onSend(messages)}
user={{
_id: user.id,
}}
placeholder=""
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#FBFBFB",
},
sendButton: {
width: 35,
height: 35,
alignItems: "center",
justifyContent: "center",
borderRadius: 17.5,
backgroundColor: "#3498db",
marginRight: 5,
marginVertical: 4,
},
sendIcon: {
width: 20,
height: 20,
},
botMessage: {
backgroundColor: "#E8E8E8",
paddingVertical: 10,
margin: 10,
alignSelf: I18nManager.isRTL ? "flex-end" : "flex-start",
paddingHorizontal: 16,
borderTopRightRadius: 10,
borderTopLeftRadius: 10,
borderBottomLeftRadius: I18nManager.isRTL && Platform.OS === "ios" ? 10 : 0,
borderBottomRightRadius:
I18nManager.isRTL && Platform.OS === "ios" ? 0 : 10,
marginRight: 23,
},
userMessage: {
backgroundColor: "#F8F8F8",
paddingVertical: 10,
margin: 10,
alignSelf: I18nManager.isRTL ? "flex-start" : "flex-end",
paddingHorizontal: 16,
borderTopRightRadius: 10,
borderTopLeftRadius: 10,
borderBottomLeftRadius: I18nManager.isRTL && Platform.OS === "ios" ? 0 : 10,
borderBottomRightRadius:
I18nManager.isRTL && Platform.OS === "ios" ? 10 : 0,
marginLeft: 13,
},
botText: {
fontSize: 16,
fontWeight: "400",
color: "#262930",
fontFamily: "Varela Round",
},
userText: {
fontSize: 16,
fontWeight: "400",
color: "#000000",
fontFamily: "Varela Round",
},
});
export default ChatScreen;
The text was updated successfully, but these errors were encountered: