Why doesn't react native register the user pressing a button?

214 Views Asked by At

I'm trying to use a touchablehighlight component and when I press it, nothing happens. So I changed it to a button and added a console log and still, react native won't register the press.

I'm using expo and I'm relatively new to react native.

Please tell me what I'm doing wrong

import React, { useState } from "react";
import {
    Button,
  Modal,
  StyleSheet,
  Text,
  TouchableHighlight,
  View,
} from "react-native";

const customPicker = (props) => {
  const [selectedNumber, setSelectedNumber] = useState(props.pickerValues[0]);
  const [pickerDisplayed, setPickerDisplayed] = useState(false);

  function changeSelectedNumber(value) {
    setSelectedNumber(value);
    setPickerDisplayed(false);
  }
  const touchableHighlightcomponent = props.pickerValues.map((value, index) => (
    <TouchableHighlight
      style={styles.th}
      onPress={() => changeSelectedNumber({ value })}
      key={index}
    >
      <Text>{value}</Text>
    </TouchableHighlight>
  ));



  return (
    <View>
      

      <Button onPress={() => console.log("pressed")} title="one"></Button>

      {/* <TouchableHighlight style={styles.input} onPress={() => this.console.log("pressed")}>
        <Text>{selectedNumber}</Text>
      </TouchableHighlight> */}

      <Modal visible={() => pickerDisplayed} transparent={true}>
        <View style={styles.picker}>
          <View style={styles.pickerItems}>
            <Text>Please select a value</Text>
            {touchableHighlightcomponent}
          </View>
        </View>
      </Modal>
    </View>
  );
};

1

There are 1 best solutions below

0
On

I have discovered the problem.

It's a bug with the iOS simulator, it doesn't register button pushes.

To fix: Simply restart the iOS simulator