0

As titled, is this possible?

I know can disable the React Native textinput by setting

editable={false}

but i need to have the functionality for other keys like Enter and Backspace to work at the same time. But i don't think that will work because setting editable as false effectively makes the input blur all the time, therefore cannot make attributes like onKeyPress and onSubmitEditing works.

Is there a work around for this?

Fred A
  • 1,602
  • 1
  • 24
  • 41

1 Answers1

0

there is a trick that u can apply. you need to give it a constant value in the value attribute.

import React from "react";
import { SafeAreaView, StyleSheet, TextInput } from "react-native";

const UselessTextInput = () => {
  const [text, onChangeText] = React.useState("Useless Text");
  
  return (
    <SafeAreaView>
      <TextInput
        style={styles.input}
        onChangeText={onChangeText}
        value={""}
      />
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  input: {
    height: 40,
    margin: 12,
    borderWidth: 1,
    padding: 10,
  },
});

export default UselessTextInput;
Engr.Aftab Ufaq
  • 3,356
  • 3
  • 21
  • 47