lucasferreira / react-native-flash-message

React Native flashbar and top notification alert utility
MIT License
1.42k stars 154 forks source link

onPress not triggered with TouchableWithoutFeedback - Pressable works #268

Open JeffreyVanelderenACA opened 1 year ago

JeffreyVanelderenACA commented 1 year ago

Hi,

Not sure if anyone else is having this issue but my onPress passed to showMessage config doesn't trigger.

I'm having this issue since I'm using this library and created this patch a while ago (since version 4.0.0 or even earlier I'm using this patch in my projects)

Current version: react-native-flash-message@0.4.2 , but should also work for some earlier versions as stated above

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-flash-message/src/FlashMessage.js b/node_modules/react-native-flash-message/src/FlashMessage.js
index 29891b6..8ff5c5c 100644
--- a/node_modules/react-native-flash-message/src/FlashMessage.js
+++ b/node_modules/react-native-flash-message/src/FlashMessage.js
@@ -1,5 +1,14 @@
 import React, { Component } from "react";
-import { StyleSheet, TouchableWithoutFeedback, Platform, StatusBar, Animated, Image, Text, View } from "react-native";
+import {
+  StyleSheet,
+  Platform,
+  StatusBar,
+  Animated,
+  Image,
+  Text,
+  View,
+  Pressable
+} from "react-native";
 import { isIphoneX, getStatusBarHeight } from "react-native-iphone-screen-helper";
 import PropTypes from "prop-types";

@@ -625,7 +634,7 @@ export default class FlashMessage extends Component {
     return (
       <Animated.View pointerEvents="box-none" style={[positionStyle(styles.root, position), animStyle]}>
         {!!message && (
-          <TouchableWithoutFeedback onPress={this.pressMessage} onLongPress={this.longPressMessage} accessible={false}>
+          <Pressable onPress={this.pressMessage} onLongPress={this.longPressMessage} accessible={false}>
             <MessageComponent
               position={position}
               floating={floating}
@@ -647,7 +656,7 @@ export default class FlashMessage extends Component {
               accessibilityLabel={accessibilityLabel}
               testID={testID}
             />
-          </TouchableWithoutFeedback>
+          </Pressable>
         )}
       </Animated.View>
     );

This issue body was partially generated by patch-package.