Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

onPress Event is not firing in expo react-native

I’m following the youtube tutorial react native full course (2:32:54) but when i code along the onPress event isnot firining for me, i asked in ai and search other stackoverflow post nothing working for me.my code is exactly same as instructor’s. only diffrence i’m running in iOS simulator.can anyone help me on this?

import { Ionicons } from "@expo/vector-icons";
import React from "react";
import { Image, TouchableOpacity, View } from "react-native";

export default function Introduction({ business }) {
  return (
    <View>
      <View
        style={{
          position: "absolute",
          zIndex: 10,
          display: "flex",
          flexDirection: "row",
          justifyContent: "space-between",
          width: "100%",
          padding: 20,
        }}
      >
        <TouchableOpacity onPress={() => console.log("Pressed")}>
          <Ionicons name="arrow-back-circle" size={40} color="white" />
        </TouchableOpacity>
        <TouchableOpacity onPress={() => console.log("Pressed")}>
          <Ionicons name="heart-outline" size={40} color="white" />
        </TouchableOpacity>
      </View>
      <Image
        source={{ uri: business?.imageUrl }}
        style={{
          width: "100%",
          height: 340,
        }}
      />
    </View>
  );
}


>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Looks like the status bar from your phone is getting the way as your buttons are positioned at the top of your screen. You can hide it using StatusBar component to make your buttons work as expected:

...
import { Image, TouchableOpacity, View, StatusBar } from "react-native";

export default function Introduction({ business }) {
  return (
    <View>
      <StatusBar hidden={true} />

      ...
    </View>
  );
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading