CaioQuirinoMedeiros / react-native-currency-input

A simple currency input component for both iOS and Android
https://www.npmjs.com/package/react-native-currency-input
MIT License
158 stars 25 forks source link

onFocus not working #22

Open mmfire118 opened 2 years ago

mmfire118 commented 2 years ago

onFocus does not work for CurrencyInput.

function test(props) {

  const [value, setValue] = React.useState(null);

  function focus() {
    console.log("FOCUSED")
  }

  function blur() {
    console.log("BLURRED")
  }

  return (
      <CurrencyInput
        value={value}
        onChangeValue={setValue}
        prefix=""
        delimiter=","
        separator="."
        precision={1}
        minValue={0}
        maxValue={100}
        suffix="%"
        onFocus={focus}
        onBlur={blur}
        {...props}
      />
  );
}

onBlur works and prints "BLURRED". "FOCUSED" is never printed. I am using onPressIn with the isFocused function to approximate onFocus, but it would be better if it just worked.

function test(props) {
  const testRef = useRef(null);

  const [value, setValue] = React.useState(null);

  function checkFocus() {
    setTimeout(function(){
      if (testRef.current.isFocused()) {
        console.log("FOCUSED")
      }
    },100);
  }

  function blur() {
    console.log("BLURRED")
  }

  return (
      <CurrencyInput
        value={value}
        onChangeValue={setValue}
        prefix=""
        delimiter=","
        separator="."
        precision={1}
        minValue={0}
        maxValue={100}
        suffix="%"
        ref={testRef}
        onPressIn={checkFocus}
        onBlur={blur}
        {...props}
      />
  );
}
mmfire118 commented 2 years ago

Any updates?

Awethentique commented 8 months ago

Similar for me, onFocus works but onBlur does not