akinncar / react-native-mask-text

🎭 A React Native and Expo library to mask text and inputs
MIT License
415 stars 39 forks source link

Add currency options to masked components #4

Closed akinncar closed 3 years ago

akinncar commented 3 years ago

We need to have a mask that can add mask currency values on MaskedTextInput and MaskedTextcomponents, I taught in an example like that:

If the component have isCurrency === true, should use currency mask logic

import { StyleSheet } from "react-native";
import { MaskedTextInput } from "react-native-mask-text";

//...

<MaskedTextInput
  isCurrency
  currencyOptions={{
    prefix: "R$", // optional string
    decimal: ".", // optional string to separate decimal (default ",")
    cents: "," // optional string to separate cents (default ".")
  }}
  onChangeText={(text, rawText) => {
    console.log(text);
    console.log(rawText);
  }}
  style={styles.input}
/>;

//...

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

Expected Behaivor (Nubank Mobile App):

ezgif com-gif-maker

<MaskedText /> component should have same behaivor.

akinncar commented 3 years ago

I just started to work on this issue, and the current proposal is:

<MaskedTextInput
  type="currency"
  options={{
    prefix: "R$",
    decimalSeparator: ',',
    groupSeparator: '.',
    precision: 2,
  }}
  onChangeText={(text, rawText) => {
    setMaskedValue(text);
    setUnmaskedValue(rawText);
  }}
  style={styles.input}
  keyboardType="numeric"
/>
github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 0.2.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: