react-native-advanced-input-mask: Not working on iOS?

Hey there, I’m having trouble getting this library to work on iOS. I can type values into the input field but the mask never applies, and neither do I ever see anything logged in the onChangeText function.

I’ve created a very basic Snack here to test this with. When I use “Web”, the mask seems to work and apply correctly, but when I connect it to my device through Expo Go, I can just freely type in any value and no mask ever applies.

https://snack.expo.dev/qYb3gKHm4O3XtjGvCcNvU

I also added this to my project with the following snippet of code:

<MaskedTextInput
  mask="[099].[99]"
  style={[styles.input]}
  value={value}
  keyboardType="numeric"
  onFocus={() => console.log("MaskedTextInput Focused!")}
  onChangeText={(formatted, extracted) => {
    console.log("formatted ->", formatted);
    console.log("extracted ->", extracted);
  }}
/>

I found that the onFocus console.log runs every time, however I never see the onChangeText function log anything ever.

Is there something I’m missing?

Appreciate any help, thank you!

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (9 by maintainers)

Most upvoted comments

@Dominic-Preap You can use this code to avoid multiline text input usage:


import React, { useState } from "react";
import { Pressable, StyleSheet, Text, View } from "react-native";
import { MaskedTextInput } from "react-native-advanced-input-mask";

export default function App() {
  const [value, setValue] = useState({ extracted: "10", formatted: "$10" });

  return (
    <View style={styles.container}>
      <Text>Testing</Text>
      <View style={styles.inputContainer}>
        <MaskedTextInput
          allowedKeys="0123456789,."
          autocomplete={false}
          keyboardType="numeric"
          mask="$[09999]{.}[09]"
          onChangeText={(formatted, extracted) => {
            setValue({
              formatted,
              extracted,
            });
          }}
          placeholder="$5"
          placeholderTextColor="blue" // Adjust your own placeholder color
          value={value.formatted} // Use formatted value from onChangeText instead
          style={styles.textInput}
        />
      </View>
      <View style={{ flexDirection: "row", gap: 12 }}>
        {[10, 20, 30, 40, 50].map((x) => (
          <Pressable
            key={x}
            onPress={() =>
              setValue({
                extracted: x.toString(),
                formatted: `$${x}`,
              })
            }
            style={{
              borderRadius: 99,
              alignItems: "center",
              width: 40,
              padding: 8,
              backgroundColor:
                x.toString() === value.extracted ? "#73D4FF" : "#DFF1FE",
            }}
          >
            <Text>{x}</Text>
          </Pressable>
        ))}
      </View>

      <Text>Value should update as above: {value.extracted}</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "white",
    alignItems: "center",
    gap: 24,
    justifyContent: "center",
  },
  inputContainer: {
    alignItems: "center",
    width: 120,
    borderColor: "black",
    borderWidth: 1,
  },
  textInput: {
    color: "black", // Need to define for Android
    fontWeight: "bold",
    padding: 12,
    textAlign: "center",
  },
});


Hello @jamesofficer

Expo Go is a sandbox environment which doesn’t actually build native code. Could you try to use development builds instead, because this library contains native code.