react-native-gifted-chat: onPress prop not working for Android
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
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18
Commits related to this issue
- Merge pull request #2196 from FaridSafi/fix/GH-2008 fix(types): include bubble on press — committed to FaridSafi/react-native-gifted-chat by Johan-dutoit 2 years ago
Well i have solved this issue it took me almost an hour guys but we did it ’ so the solution is quite simple
Now at the same file under declaration of giftedChat at line no. 114 under static default props add the onPress event
Now under static prop types below add the onPress EVENT
Now we are ended with this file now open the bubble.js file at “node_modules\react-native-gifted-chat\lib\Bubble.js”
Add the above code in the constructor at bubble.js below this.onLongPre… like this way
then add in touchable without feedback like this way
onPress= {this.onPress}
Then under Bubble.defuault Props add
this way
Then under Bubble.PropTypes add onPress
this way
Now guys lets move to another file Bubble.d.ts at ‘‘node_modules\react-native-gifted-chat\lib\Bubble.d.ts’’
Add onPress underStatic defualt props
this way
now under static PropTypes add
this way
Now add
this way
Also not forget to add onPress under exporting interface
this way
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
add the
this way
It might be an issue with 16.3, try install the latest beta.
No its not that either. Wish the authour would fix this…guess hes given up supporting the library. Does anyone know another similar library thats still being supported?
I have a fix for this.
If you have something like what I have below, then it will work
The modification adds:
touchableProps={{ disabled: true }}
which will disable the<TouchableWithoutFeedback>...</TouchableWithoutFeedback>
and so your nested<TouchableOpacity>
will work. Hope this helps!So, upon further investigation to this, I have found the issue.
If you look inside the file
react-native-gifted-chat/lib/Bubble.js
in the source code - focusing on lines 275 to 287.Because the call to render the bubble content sits inside
<TouchableWithoutFeedback />
, it seems to prevent<TouchableOpacity onPress={(): void => doSomething()} />
from working.When I commented this out,
<TouchableOpacity />
was working as it should in Android again.