question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to send an image message only ? (without sending a text as well)

See original GitHub issue

Issue Description

I simply want to send an image without typing any text ? I am using react-native-image-picker and i currently can send an image with a text , but what if i want to send an image only ? I tried alwaysShowSend and try to send but nothing happens unless the text field is not empty The docs are very vague on this …

Steps to Reproduce / Code Snippets

  <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);
    }
  }

Expected Results

[FILL THIS OUT]

Additional Information

  • React version: 16.8.3
  • React Native version: 0.59.9
  • react-native-gifted-chat version: 0.9.11
  • Platform(s) (iOS, Android, or both?): both

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

24reactions
charles-goodecommented, Aug 26, 2020

Ok true. Then this should work right?

renderSend={({onSend, text, sendButtonProps, ...props}) => <Send {...props} sendButtonProps={{...sendButtonProps, onPress: () => this.customOnPress(text, onSend)}} />}
alwaysShowSend={true}

where customOnPress replaces this in Send.tsx:

handleOnPress = () => {
    const { text, onSend } = this.props
    if (text && onSend) {
      onSend({ text: text.trim() } as Partial<TMessage>, true)
    }
  }

And maybe also include the disabled stuff from my previous post if that’s at all relevant.

1reaction
anwersolangicommented, Aug 26, 2020

Haven’t tested this but I think

renderSend={(props) => <Send {...props} disabled={this.customDisabled()} />}
alwaysShowSend={true}

Should work, where custom disabled is false when image is attached

The onSend function is not invoking if the text field is empty

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to send an image message only ? (without sending a text ...
You Need to make the custom send button, to do this: import { GiftedChat ...
Read more >
How to Send Messages That Automatically Disappear - WIRED
Head to your conversation list in the Instagram app, then open the thread that you want to send the disappearing message to (tap...
Read more >
Android: Send Picture in Email or Text Message - Technipages
Send Photo via Text Message. Open the “Messages” app. Select the + icon, then choose a recipient or open an existing message thread....
Read more >
Use message effects with iMessage on your iPhone, iPad and ...
Tap the Send button send message icon or tap Done to add a personal message. If you don't want to send the photo,...
Read more >
Top 7 Ways To Fix Sending Picture Messages On Android
Have you been trying to send a family picture via text message to your grandma who doesn't use a smartphone but to no...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found