gpt4 book ai didi

reactjs - 如何只发送图片消息? (也无需发送文本)

转载 作者:行者123 更新时间:2023-12-04 15:41:45 25 4
gpt4 key购买 nike

我只想发送图片而不输入任何文字?我正在使用 react-native-image-picker,我目前可以发送带有文本的图像,但是如果我只想发送图像怎么办?我试过 alwaysShowSend 并尝试发送但没有任何反应,除非文本字段不为空文档对此非常模糊......

      <GiftedChat
messages={friendMsgs}
onSend={messages => this.onSend(messages, this.state.image)}
user={{
_id: user && user.id,
name: user && user.firstName,
avatar: user && user.profilemage
}}
text={this.state.text}
alwaysShowSend={
this.state.text ? true : false || this.state.image ? true : false
}
onInputTextChanged={text => this.setState({ text })}
renderLoading={() => <Loading />}
onLoadEarlier={this.loadMessages.bind(this, userParams)}
isLoadingEarlier={loading}
isAnimated
renderAvatarOnTop
loadEarlier={friendMsgs.length >= 20}
scrollToBottom
scrollToBottomComponent={() => (
<Ionic name='ios-arrow-round-down' size={30} color='#000' />
)}
extraData={this.state}
renderBubble={props => {
const color = props.currentMessage.read ? '#0084ff' : '#389bff';
return (
<Bubble
{...props}
wrapperStyle={{ right: { backgroundColor: color } }}
/>
);
}}
renderActions={() => (
<Feather
style={styles.uploadImage}
onPress={this.uploadImage}
name='image'
size={30}
color='#000'
/>
)}
/>


onSend(messages = [], image) {
const { socket, user, navigation } = this.props;
const { friendMsgs } = this.props.history;

const receiver = navigation.getParam('user');

if (socket && socket.readyState === 1) {
const msg = {
...messages[0],
image
};

const sendMsg = GiftedChat.append(friendMsgs, msg);

const data = {
senderId: user && user.id,
receiverType: 'user',
messageType: 'text',
receiverId: receiver.id,
read: false,
content: messages[0].text
};

this.props.sendMsg(data, sendMsg);
}
}

最佳答案

你能试试这个吗?

 const msg = {
createdAt: new Date(),
user: user && user.id,
image: image,
sent: true,
received: true,
}
...
const sendMsg = GiftedChat.append(friendMsgs, msg);
const data = {
senderId: user && user.id,
receiverType: 'user',
receiverId: receiver.id,
read: false,
};

this.props.sendMsg(data, sendMsg);
this.props.sendMsg({});

关于reactjs - 如何只发送图片消息? (也无需发送文本),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57611845/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com