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.

onPress prop not working for Android

See original GitHub issue

Issue Description

onPress prop not working for Android. Press a message bubble and attached function does not run.

Steps to Reproduce / Code Snippets

            <GiftedChat
              messages={this.formatMessagesFromRedux()}
              onSend={messages => this.onSend(messages)}
              onLongPress={(context, message) =>
                this.onLongPressMsg(context, message)
              }
              onPress={(context, message) => {
                Alert.alert('Bubble pressed');
              }}
              user={{name: this.props.myNameText, _id: this.props.myUserId}}
              renderBubble={this.renderBubble}
              showUserAvatar={true}
              renderAvatar={props => {
                const avatarProps = props.currentMessage;
                if (avatarProps.user.avatar) {
                  return (
                    <Avatar
                      rounded
                      source={{uri: avatarProps.user.avatar}}
                      size="large"
                    />
                  );
                }
                return null;
              }}
            />

Expected Results

Alert is triggered

Additional Information

  • Nodejs version: 10.16
  • React version: 16.13.1
  • React Native version: 0.63.3
  • react-native-gifted-chat version: 0.16.3
  • Platform(s) (iOS, Android, or both?): Android (havent checked ios)
  • TypeScript version: n/a

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:18

github_iconTop GitHub Comments

4reactions
Yogesh-Dubey-Ayesavicommented, Dec 28, 2021

Well i have solved this issue it took me almost an hour guys but we did it ’ so the solution is quite simple

  1. go to GiftedChat.d.ts at ‘‘node_modules\react-native-gifted-chat\lib\GiftedChat.d.ts’’ ### add onPress event
image
  1. Now at the same file under declaration of giftedChat at line no. 114 under static default props add the onPress event image

  2. Now under static prop types below add the onPress EVENT image

Now we are ended with this file now open the bubble.js file at “node_modules\react-native-gifted-chat\lib\Bubble.js”

  1.     this.onPress = () => {
         const { currentMessage } = this.props;
         if (this.props.onPress) {
             this.props.onPress(this.context, this.props.currentMessage);
         }
         else if (currentMessage && currentMessage.text) {
             const { optionTitles } = this.props;
             const options = optionTitles && optionTitles.length > 0
                 ? optionTitles.slice(0, 2)
                 : DEFAULT_OPTION_TITLES;
             const cancelButtonIndex = options.length - 1;
             this.context.actionSheet().showActionSheetWithOptions({
                 options,
                 cancelButtonIndex,
             }, (buttonIndex) => {
                 switch (buttonIndex) {
                     case 0:
                         Clipboard.setString(currentMessage.text);
                         break;
                     default:
                         break;
                 }
             });
         }
         
     };
    
  2. Add the above code in the constructor at bubble.js below this.onLongPre… like this way image

  3. then add in touchable without feedback like this way

  4. onPress= {this.onPress} image

  5. Then under Bubble.defuault Props add

  6.   onPress: null,
    
  7. this way image

  8. Then under Bubble.PropTypes add onPress

  9.    onPress: PropTypes.func,
    
  10. this way image

Now guys lets move to another file Bubble.d.ts at ‘‘node_modules\react-native-gifted-chat\lib\Bubble.d.ts’’

  1. Add onPress underStatic defualt props

  2.      onPress: null;
    
  3. this way image

  4. now under static PropTypes add

  5.     onPress: PropTypes.Requireable<(...args: any[]) => any>;
    
  6. this way image

  7. Now add

  8.   onPress: () => void
    
  9. this way image

  10. Also not forget to add onPress under exporting interface

  11. onPress?(context?: any, message?: any): void;
    
  12. this way image

Now lets move to another file Bubble.js.flow this is the last file in which we have to list a change in order to fix this issue

  1. add the

  2.    onPress?: (context?: any, message?: any) => void,
    
  3. this way

image
1reaction
Johan-dutoitcommented, Apr 29, 2022

It might be an issue with 16.3, try install the latest beta.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native: Text onPress not working on android
Your code seems perfectly right and works for me... Try reloading or reinstalling the app 2-3 times.. It should work.
Read more >
Handling Touches - React Native
Pressing the button will call the "onPress" function, ... If you like, you can specify a "color" prop to change the color of...
Read more >
React Native: View onPress does not work - iTecNote
I'm facing a weird problem. In my react native app, if I set onPress event to View it is not triggered but if...
Read more >
React Native touchable vs. pressable components
npm start # --- or --- yarn start npx react-native run-android # --- or ... The style prop is not available for Button...
Read more >
react-native-popover-view - npm
A well-tested, adaptable, lightweight <Popover> component for react-native with no dependencies. Tested and working on iOS and Android. May work ...
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