Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 29606

React-native onPress() event doesn't work in Android

$
0
0

I am experiencing a very weird behaviour in my android emulator when using react-navigation v5 in my react native application, which makes me think is a bug.

In every secondary screen (see UserProfileScreen below), in many react native-elements like TouchableOpacity Button or TextInput the onPress event doesn't work. It only works in the main screen of the navigator. (See HomeScreen below)

Here is an example of how I create my stack navigator:

import {createStackNavigator} from '@react-navigation/stack';

// some imports here

const HomeStackNavigator = createStackNavigator();
export const HomeNavigator = () => {
   return (
       <HomeStackNavigator.Navigator>
         <HomeStackNavigator.Screen name="HomeScreen" component={HomeScreen}/>
         <HomeStackNavigator.Screen name="UserProfileScreen" component={UserProfileScreen}/>
         <HomeStackNavigator.Screen name="UserSettingsScreen" component={UserSettingsScreen}/>
       </HomeStackNavigator.Navigator>   
    )
};

As a PoC I have the same code in the main and secondary screen:

<TouchableOpacity     
   onPress={() => Alert.alert("You pressed me!")} >     
   <Text> touch me</Text> 
</TouchableOpacity>

and I see the alert only in the main screen (HomeScreen).

If I make UserProfileScreen as the fist screen in my stack navigator above then it works (the onPress event) fine on this screen but not in the HomeScreen. So it seems that the onPress event is triggered only in the main screen!. On IOS it works fine in all screens. Any idea ? Let me know if you need some more code snippets.


Viewing all articles
Browse latest Browse all 29606

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>