Skip to content
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

[Android] Error "Value for value cannot be cast from String to Double" on send message #1129

Closed
paolospag opened this issue Feb 10, 2019 · 10 comments

Comments

@paolospag
Copy link

paolospag commented Feb 10, 2019

Hello there,
I developed an app that works fine on iOS and now I want to compile the Android version, but I came across a strange error (see the attachment).

screenshot_2019-01-28-15-49-31

I would like to understand if it is a problem I can solve simply by updating the version of react-native-gifted-chat or the react-native core.

Steps to Reproduce / Code Snippets

  • package.json
"dependencies": {
    "react": "16.6.3",
    "react-native": "0.57.8",
    ...
    "react-native-firebase": "5.2.1",
    "react-native-gifted-chat": "0.5.0",
    ...
}
  • Chat.js
import React, { Component } from 'react';
import { GiftedChat, Send, Bubble } from 'react-native-gifted-chat';
...

export default class ChatScreen extends Component {
  state = {
    messages: []
  }
  chatRoomRef = null;
  unsubscribe = null;
  _chatRoomListener = (querySnapshot) => {
    const messages = querySnapshot.docs.map(doc => 
      createGiftedChatItem(doc.id, doc.data()) // --> a custom function to create message object
    );
    this.setState(prevState => ({
      ...prevState,
      messages
    }));
  }
  componentDidMount = () => {
    const { navigation } = this.props;
    // My custom Firebase methods
    this.chatRoomRef = database.chatRoomMessagesByPath(REF_TO_FIRESTORE_PATH);
    this.unsubscribe = this.chatRoomRef.orderBy('createdAt', 'desc').onSnapshot(this._chatRoomListener);
  }
  componentWillUnmount = () => {
    if (this.unsubscribe) {
      this.unsubscribe();
    }
  }
  sendMessageHandler = (messages = []) => {
    messages.forEach(message => {
      let lastMessage = createChatMessageItem(message); // --> a custom function to create message object
      this.chatRoomRef.add(lastMessage).then(() => 
        database.chatRoomByPath(path).update({lastMessage})
      ).then(() => {
        // --> other omitted methods here
      });
    });
  }
  render() {
    const { messages } = this.state;
    return (
      <GiftedChat
        user={{_id: XXXXXXXX}}
        locale="en"
        dateFormat="LL"
        timeFormat="LT"
        messages={messages}
        renderAvatar={null}
        renderSend={props => (
          <Send {...props} containerStyle={styles.sendBtn}>
            <MaterialIcon name="send" size={24} color={THEME_PRIMARY_COLOR} />
          </Send>
        )}
        renderBubble={props => (
          <Bubble 
            {...props} 
            wrapperStyle={{
              right: {backgroundColor: THEME_OWNER_CHAT_BUBBLE, padding: 12, borderRadius: 8}, 
              left: {backgroundColor: THEME_GUEST_CHAT_BUBBLE, padding: 12, borderRadius: 8}
            }}
            textStyle={{
              right: {color: THEME_GRAY_COLOR},
              left: {color: THEME_GRAY_COLOR}
            }}
            textProps={{
              style: {color: THEME_TEXT_COLOR}
            }}
          />
        )}
        onSend={message => this.sendMessageHandler(message)}
      />
    )
  }
}

Expected Results

I don't understand why on iOS everything works fine, while on Android the chat message is correctly saved on Firestore, but this error is shown.

Additional Information

  • React version: 16.6.3
  • React Native version: 0.57.8
  • react-native-gifted-chat version: 0.5.0
  • Platform(s): Android
@xcarpentier
Copy link
Collaborator

Did you try with v0.7.2?

@paolospag
Copy link
Author

paolospag commented Feb 11, 2019

Hi @xcarpentier
I have not tried it yet, but I will do it in the next days.

In the meantime, I looked for similar issues and I found this:
facebook/react-native#23219

Do you think they can be related?

@xcarpentier
Copy link
Collaborator

xcarpentier commented Feb 11, 2019

Yes, I already experienced this weird transformation thing on android.
If it is, there is no reason to keep this issue. Could you please close it?
I mean if you try to make a style transformation on your side.

Thanks

@paolospag
Copy link
Author

No, I don't make any transformation and I can't really explain why it happens.
I'm quite confused... I will try to update from 0.5.0 to 0.7.2 and I will let you know.

@xcarpentier
Copy link
Collaborator

Apparently, this is an animation issue. Do you have any animation?

@paolospag
Copy link
Author

I understood it is an animation issue, but I don't have any animation on this screen, but in other screens sure.

I do not think that animations in other screens can cause this error...

@xcarpentier
Copy link
Collaborator

xcarpentier commented Feb 12, 2019

If the other screen with animation is on a navigation stack or tab and comes before the chat it's still in memory (still mounted).

@paolospag
Copy link
Author

paolospag commented Feb 12, 2019

Oh, I'm sorry for the waste of time...
I found the problem, it's related to the style applied to send button:

sendBtn: {
  ...
  transform: [{rotate: '-30deg'}]
}

but I don't understand why can not I apply a transformation to the send button?
Is there a workaround?

@xcarpentier
Copy link
Collaborator

no worries

@rajeevrocker7
Copy link

rajeevrocker7 commented Jul 30, 2019

For 'TextInput' in style try after removing backgroundColor, color, if passed.

textInputStyle: {
...
backgroundColor: '#FFFFF', // remove this
color: 'black' . //remove this
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants