Open ajp8164 opened 10 months ago
@ajp8164 Thanks for your contribution but... the whole point of this lib is the formatNumber function, why would you want to use a customFormatter
? If someone needs a custom formatter, why not just use it with the standard TextInput?
It's a fair point. I've already turtled this lib into my stack and adding this small extension saves a lot of work having to extend other middleware libs. I may reconsider my implementation but this is cheaper and faster for sure. Better? idk. One use case is RTL entry for hh:mm:ss.
UPDATE - reviewing the implementation of this library and looking at some of the available masking libraries I believe this is the best library for my use cases (just sort of a nit that this library is named and focused on only currency). If this library was forked and renamed for more general formatting then I can see multiple built-in formatters plus a custom callback. The RTL input (TextWithCursor) is a nice feature. Using this patch I added a formatter as follows to handle entering sec, min, then hrs. With this formatter I get a mask input as well.
export const maskToHMS = (value: number) => {
return value.toString().padStart(6, '0').split(/(?=(?:..)*$)/).join(':');
};
Anyway, I like the library! Thanks!
This patch adds a new property called
customFormatter: (value: number) => string;
. If present it replaces the built-in formatter. The value input is the unformatted number value in the component. The output string is sent to theonChangeText()
callback. Properties that are used outside of the built-in formatter are still enforced (e.g. precision, maxValue, maxLength, ...)I can issue a PR if there is interest.