@salve-software/react-native-nitro-input-mask 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +37 -17
  2. package/android/src/main/java/com/nitroinputmask/NitroInputMaskServiceModule.kt +4 -3
  3. package/ios/NitroInputMaskServiceModule.swift +3 -3
  4. package/lib/commonjs/classes/NitroInputMaskService/NitroInputMaskService.class.js +18 -9
  5. package/lib/commonjs/classes/NitroInputMaskService/NitroInputMaskService.class.js.map +1 -1
  6. package/lib/commonjs/components/NitroInputMask/index.js +20 -4
  7. package/lib/commonjs/components/NitroInputMask/index.js.map +1 -1
  8. package/lib/commonjs/types/MaskResult.js +2 -0
  9. package/lib/commonjs/types/MaskResult.js.map +1 -0
  10. package/lib/module/classes/NitroInputMaskService/NitroInputMaskService.class.js +18 -9
  11. package/lib/module/classes/NitroInputMaskService/NitroInputMaskService.class.js.map +1 -1
  12. package/lib/module/components/NitroInputMask/index.js +22 -6
  13. package/lib/module/components/NitroInputMask/index.js.map +1 -1
  14. package/lib/module/types/MaskResult.js +2 -0
  15. package/lib/module/types/MaskResult.js.map +1 -0
  16. package/lib/typescript/src/classes/NitroInputMaskService/NitroInputMaskService.class.d.ts +13 -9
  17. package/lib/typescript/src/classes/NitroInputMaskService/NitroInputMaskService.class.d.ts.map +1 -1
  18. package/lib/typescript/src/components/NitroInputMask/index.d.ts.map +1 -1
  19. package/lib/typescript/src/components/NitroInputMask/types/NitroInputMaskProps.d.ts +19 -2
  20. package/lib/typescript/src/components/NitroInputMask/types/NitroInputMaskProps.d.ts.map +1 -1
  21. package/lib/typescript/src/specs/nitro-input-mask-service.nitro.d.ts +5 -1
  22. package/lib/typescript/src/specs/nitro-input-mask-service.nitro.d.ts.map +1 -1
  23. package/lib/typescript/src/types/MaskResult.d.ts +13 -0
  24. package/lib/typescript/src/types/MaskResult.d.ts.map +1 -0
  25. package/lib/typescript/src/types/index.d.ts +1 -0
  26. package/lib/typescript/src/types/index.d.ts.map +1 -1
  27. package/nitrogen/generated/android/c++/JHybridNitroInputMaskServiceSpec.cpp +7 -3
  28. package/nitrogen/generated/android/c++/JHybridNitroInputMaskServiceSpec.hpp +1 -1
  29. package/nitrogen/generated/android/c++/JMaskResult.hpp +61 -0
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinputmask/HybridNitroInputMaskServiceSpec.kt +1 -1
  31. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinputmask/MaskResult.kt +56 -0
  32. package/nitrogen/generated/ios/NitroInputMask-Swift-Cxx-Bridge.hpp +9 -6
  33. package/nitrogen/generated/ios/NitroInputMask-Swift-Cxx-Umbrella.hpp +3 -0
  34. package/nitrogen/generated/ios/c++/HybridNitroInputMaskServiceSpecSwift.hpp +4 -1
  35. package/nitrogen/generated/ios/swift/HybridNitroInputMaskServiceSpec.swift +1 -1
  36. package/nitrogen/generated/ios/swift/HybridNitroInputMaskServiceSpec_cxx.swift +4 -4
  37. package/nitrogen/generated/ios/swift/MaskResult.swift +34 -0
  38. package/nitrogen/generated/shared/c++/HybridNitroInputMaskServiceSpec.hpp +4 -1
  39. package/nitrogen/generated/shared/c++/MaskResult.hpp +87 -0
  40. package/package.json +3 -2
  41. package/src/classes/NitroInputMaskService/NitroInputMaskService.class.ts +18 -10
  42. package/src/components/NitroInputMask/index.tsx +29 -11
  43. package/src/components/NitroInputMask/types/NitroInputMaskProps.ts +19 -2
  44. package/src/specs/nitro-input-mask-service.nitro.ts +9 -1
  45. package/src/types/MaskResult.ts +12 -0
  46. package/src/types/index.ts +1 -0
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/types/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,qBAAqB,CAAC;AACzC,mBAAmB,cAAc,CAAC;AAClC,mBAAmB,oBAAoB,CAAC;AACxC,mBAAmB,yBAAyB,CAAC;AAC7C,mBAAmB,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/types/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,qBAAqB,CAAC;AACzC,mBAAmB,cAAc,CAAC;AAClC,mBAAmB,cAAc,CAAC;AAClC,mBAAmB,oBAAoB,CAAC;AACxC,mBAAmB,yBAAyB,CAAC;AAC7C,mBAAmB,uBAAuB,CAAC"}
@@ -7,9 +7,13 @@
7
7
 
8
8
  #include "JHybridNitroInputMaskServiceSpec.hpp"
9
9
 
10
+ // Forward declaration of `MaskResult` to properly resolve imports.
11
+ namespace margelo::nitro::nitroinputmask { struct MaskResult; }
10
12
  // Forward declaration of `NitroMaskOptions` to properly resolve imports.
11
13
  namespace margelo::nitro::nitroinputmask { struct NitroMaskOptions; }
12
14
 
15
+ #include "MaskResult.hpp"
16
+ #include "JMaskResult.hpp"
13
17
  #include <string>
14
18
  #include "NitroMaskOptions.hpp"
15
19
  #include "JNitroMaskOptions.hpp"
@@ -48,10 +52,10 @@ namespace margelo::nitro::nitroinputmask {
48
52
 
49
53
 
50
54
  // Methods
51
- std::string JHybridNitroInputMaskServiceSpec::applyMask(const std::string& value, const std::string& maskType, const NitroMaskOptions& options) {
52
- static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JString>(jni::alias_ref<jni::JString> /* value */, jni::alias_ref<jni::JString> /* maskType */, jni::alias_ref<JNitroMaskOptions> /* options */)>("applyMask");
55
+ MaskResult JHybridNitroInputMaskServiceSpec::applyMask(const std::string& value, const std::string& maskType, const NitroMaskOptions& options) {
56
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JMaskResult>(jni::alias_ref<jni::JString> /* value */, jni::alias_ref<jni::JString> /* maskType */, jni::alias_ref<JNitroMaskOptions> /* options */)>("applyMask");
53
57
  auto __result = method(_javaPart, jni::make_jstring(value), jni::make_jstring(maskType), JNitroMaskOptions::fromCpp(options));
54
- return __result->toStdString();
58
+ return __result->toCpp();
55
59
  }
56
60
 
57
61
  } // namespace margelo::nitro::nitroinputmask
@@ -54,7 +54,7 @@ namespace margelo::nitro::nitroinputmask {
54
54
 
55
55
  public:
56
56
  // Methods
57
- std::string applyMask(const std::string& value, const std::string& maskType, const NitroMaskOptions& options) override;
57
+ MaskResult applyMask(const std::string& value, const std::string& maskType, const NitroMaskOptions& options) override;
58
58
 
59
59
  private:
60
60
  jni::global_ref<JHybridNitroInputMaskServiceSpec::JavaPart> _javaPart;
@@ -0,0 +1,61 @@
1
+ ///
2
+ /// JMaskResult.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include "MaskResult.hpp"
12
+
13
+ #include <string>
14
+
15
+ namespace margelo::nitro::nitroinputmask {
16
+
17
+ using namespace facebook;
18
+
19
+ /**
20
+ * The C++ JNI bridge between the C++ struct "MaskResult" and the the Kotlin data class "MaskResult".
21
+ */
22
+ struct JMaskResult final: public jni::JavaClass<JMaskResult> {
23
+ public:
24
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitroinputmask/MaskResult;";
25
+
26
+ public:
27
+ /**
28
+ * Convert this Java/Kotlin-based struct to the C++ struct MaskResult by copying all values to C++.
29
+ */
30
+ [[maybe_unused]]
31
+ [[nodiscard]]
32
+ MaskResult toCpp() const {
33
+ static const auto clazz = javaClassStatic();
34
+ static const auto fieldMasked = clazz->getField<jni::JString>("masked");
35
+ jni::local_ref<jni::JString> masked = this->getFieldValue(fieldMasked);
36
+ static const auto fieldRaw = clazz->getField<jni::JString>("raw");
37
+ jni::local_ref<jni::JString> raw = this->getFieldValue(fieldRaw);
38
+ return MaskResult(
39
+ masked->toStdString(),
40
+ raw->toStdString()
41
+ );
42
+ }
43
+
44
+ public:
45
+ /**
46
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
47
+ */
48
+ [[maybe_unused]]
49
+ static jni::local_ref<JMaskResult::javaobject> fromCpp(const MaskResult& value) {
50
+ using JSignature = JMaskResult(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>);
51
+ static const auto clazz = javaClassStatic();
52
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
53
+ return create(
54
+ clazz,
55
+ jni::make_jstring(value.masked),
56
+ jni::make_jstring(value.raw)
57
+ );
58
+ }
59
+ };
60
+
61
+ } // namespace margelo::nitro::nitroinputmask
@@ -30,7 +30,7 @@ abstract class HybridNitroInputMaskServiceSpec: HybridObject() {
30
30
  // Methods
31
31
  @DoNotStrip
32
32
  @Keep
33
- abstract fun applyMask(value: String, maskType: String, options: NitroMaskOptions): String
33
+ abstract fun applyMask(value: String, maskType: String, options: NitroMaskOptions): MaskResult
34
34
 
35
35
  // Default implementation of `HybridObject.toString()`
36
36
  override fun toString(): String {
@@ -0,0 +1,56 @@
1
+ ///
2
+ /// MaskResult.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.nitroinputmask
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+ import java.util.Objects
13
+
14
+
15
+ /**
16
+ * Represents the JavaScript object/struct "MaskResult".
17
+ */
18
+ @DoNotStrip
19
+ @Keep
20
+ data class MaskResult(
21
+ @DoNotStrip
22
+ @Keep
23
+ val masked: String,
24
+ @DoNotStrip
25
+ @Keep
26
+ val raw: String
27
+ ) {
28
+ /* primary constructor */
29
+
30
+ override fun equals(other: Any?): Boolean {
31
+ if (this === other) return true
32
+ if (other !is MaskResult) return false
33
+ return Objects.deepEquals(this.masked, other.masked)
34
+ && Objects.deepEquals(this.raw, other.raw)
35
+ }
36
+
37
+ override fun hashCode(): Int {
38
+ return arrayOf(
39
+ masked,
40
+ raw
41
+ ).contentDeepHashCode()
42
+ }
43
+
44
+ companion object {
45
+ /**
46
+ * Constructor called from C++
47
+ */
48
+ @DoNotStrip
49
+ @Keep
50
+ @Suppress("unused")
51
+ @JvmStatic
52
+ private fun fromCpp(masked: String, raw: String): MaskResult {
53
+ return MaskResult(masked, raw)
54
+ }
55
+ }
56
+ }
@@ -12,6 +12,8 @@
12
12
  namespace margelo::nitro::nitroinputmask { class HybridNitroInputMaskServiceSpec; }
13
13
  // Forward declaration of `HybridNitroInputMaskSpec` to properly resolve imports.
14
14
  namespace margelo::nitro::nitroinputmask { class HybridNitroInputMaskSpec; }
15
+ // Forward declaration of `MaskResult` to properly resolve imports.
16
+ namespace margelo::nitro::nitroinputmask { struct MaskResult; }
15
17
 
16
18
  // Forward declarations of Swift defined types
17
19
  // Forward declaration of `HybridNitroInputMaskServiceSpec_cxx` to properly resolve imports.
@@ -22,6 +24,7 @@ namespace NitroInputMask { class HybridNitroInputMaskSpec_cxx; }
22
24
  // Include C++ defined types
23
25
  #include "HybridNitroInputMaskServiceSpec.hpp"
24
26
  #include "HybridNitroInputMaskSpec.hpp"
27
+ #include "MaskResult.hpp"
25
28
  #include <NitroModules/Result.hpp>
26
29
  #include <exception>
27
30
  #include <memory>
@@ -91,13 +94,13 @@ namespace margelo::nitro::nitroinputmask::bridge::swift {
91
94
  using std__weak_ptr_HybridNitroInputMaskServiceSpec_ = std::weak_ptr<HybridNitroInputMaskServiceSpec>;
92
95
  inline std__weak_ptr_HybridNitroInputMaskServiceSpec_ weakify_std__shared_ptr_HybridNitroInputMaskServiceSpec_(const std::shared_ptr<HybridNitroInputMaskServiceSpec>& strong) noexcept { return strong; }
93
96
 
94
- // pragma MARK: Result<std::string>
95
- using Result_std__string_ = Result<std::string>;
96
- inline Result_std__string_ create_Result_std__string_(const std::string& value) noexcept {
97
- return Result<std::string>::withValue(value);
97
+ // pragma MARK: Result<MaskResult>
98
+ using Result_MaskResult_ = Result<MaskResult>;
99
+ inline Result_MaskResult_ create_Result_MaskResult_(const MaskResult& value) noexcept {
100
+ return Result<MaskResult>::withValue(value);
98
101
  }
99
- inline Result_std__string_ create_Result_std__string_(const std::exception_ptr& error) noexcept {
100
- return Result<std::string>::withError(error);
102
+ inline Result_MaskResult_ create_Result_MaskResult_(const std::exception_ptr& error) noexcept {
103
+ return Result<MaskResult>::withError(error);
101
104
  }
102
105
 
103
106
  // pragma MARK: std::shared_ptr<HybridNitroInputMaskSpec>
@@ -12,12 +12,15 @@
12
12
  namespace margelo::nitro::nitroinputmask { class HybridNitroInputMaskServiceSpec; }
13
13
  // Forward declaration of `HybridNitroInputMaskSpec` to properly resolve imports.
14
14
  namespace margelo::nitro::nitroinputmask { class HybridNitroInputMaskSpec; }
15
+ // Forward declaration of `MaskResult` to properly resolve imports.
16
+ namespace margelo::nitro::nitroinputmask { struct MaskResult; }
15
17
  // Forward declaration of `NitroMaskOptions` to properly resolve imports.
16
18
  namespace margelo::nitro::nitroinputmask { struct NitroMaskOptions; }
17
19
 
18
20
  // Include C++ defined types
19
21
  #include "HybridNitroInputMaskServiceSpec.hpp"
20
22
  #include "HybridNitroInputMaskSpec.hpp"
23
+ #include "MaskResult.hpp"
21
24
  #include "NitroMaskOptions.hpp"
22
25
  #include <NitroModules/Result.hpp>
23
26
  #include <exception>
@@ -12,9 +12,12 @@
12
12
  // Forward declaration of `HybridNitroInputMaskServiceSpec_cxx` to properly resolve imports.
13
13
  namespace NitroInputMask { class HybridNitroInputMaskServiceSpec_cxx; }
14
14
 
15
+ // Forward declaration of `MaskResult` to properly resolve imports.
16
+ namespace margelo::nitro::nitroinputmask { struct MaskResult; }
15
17
  // Forward declaration of `NitroMaskOptions` to properly resolve imports.
16
18
  namespace margelo::nitro::nitroinputmask { struct NitroMaskOptions; }
17
19
 
20
+ #include "MaskResult.hpp"
18
21
  #include <string>
19
22
  #include "NitroMaskOptions.hpp"
20
23
  #include <optional>
@@ -69,7 +72,7 @@ namespace margelo::nitro::nitroinputmask {
69
72
 
70
73
  public:
71
74
  // Methods
72
- inline std::string applyMask(const std::string& value, const std::string& maskType, const NitroMaskOptions& options) override {
75
+ inline MaskResult applyMask(const std::string& value, const std::string& maskType, const NitroMaskOptions& options) override {
73
76
  auto __result = _swiftPart.applyMask(value, maskType, std::forward<decltype(options)>(options));
74
77
  if (__result.hasError()) [[unlikely]] {
75
78
  std::rethrow_exception(__result.error());
@@ -13,7 +13,7 @@ public protocol HybridNitroInputMaskServiceSpec_protocol: HybridObject {
13
13
 
14
14
 
15
15
  // Methods
16
- func applyMask(value: String, maskType: String, options: NitroMaskOptions) throws -> String
16
+ func applyMask(value: String, maskType: String, options: NitroMaskOptions) throws -> MaskResult
17
17
  }
18
18
 
19
19
  public extension HybridNitroInputMaskServiceSpec_protocol {
@@ -125,14 +125,14 @@ open class HybridNitroInputMaskServiceSpec_cxx {
125
125
 
126
126
  // Methods
127
127
  @inline(__always)
128
- public final func applyMask(value: std.string, maskType: std.string, options: NitroMaskOptions) -> bridge.Result_std__string_ {
128
+ public final func applyMask(value: std.string, maskType: std.string, options: NitroMaskOptions) -> bridge.Result_MaskResult_ {
129
129
  do {
130
130
  let __result = try self.__implementation.applyMask(value: String(value), maskType: String(maskType), options: options)
131
- let __resultCpp = std.string(__result)
132
- return bridge.create_Result_std__string_(__resultCpp)
131
+ let __resultCpp = __result
132
+ return bridge.create_Result_MaskResult_(__resultCpp)
133
133
  } catch (let __error) {
134
134
  let __exceptionPtr = __error.toCpp()
135
- return bridge.create_Result_std__string_(__exceptionPtr)
135
+ return bridge.create_Result_MaskResult_(__exceptionPtr)
136
136
  }
137
137
  }
138
138
  }
@@ -0,0 +1,34 @@
1
+ ///
2
+ /// MaskResult.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /**
11
+ * Represents an instance of `MaskResult`, backed by a C++ struct.
12
+ */
13
+ public typealias MaskResult = margelo.nitro.nitroinputmask.MaskResult
14
+
15
+ public extension MaskResult {
16
+ private typealias bridge = margelo.nitro.nitroinputmask.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `MaskResult`.
20
+ */
21
+ init(masked: String, raw: String) {
22
+ self.init(std.string(masked), std.string(raw))
23
+ }
24
+
25
+ @inline(__always)
26
+ var masked: String {
27
+ return String(self.__masked)
28
+ }
29
+
30
+ @inline(__always)
31
+ var raw: String {
32
+ return String(self.__raw)
33
+ }
34
+ }
@@ -13,9 +13,12 @@
13
13
  #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
14
  #endif
15
15
 
16
+ // Forward declaration of `MaskResult` to properly resolve imports.
17
+ namespace margelo::nitro::nitroinputmask { struct MaskResult; }
16
18
  // Forward declaration of `NitroMaskOptions` to properly resolve imports.
17
19
  namespace margelo::nitro::nitroinputmask { struct NitroMaskOptions; }
18
20
 
21
+ #include "MaskResult.hpp"
19
22
  #include <string>
20
23
  #include "NitroMaskOptions.hpp"
21
24
 
@@ -50,7 +53,7 @@ namespace margelo::nitro::nitroinputmask {
50
53
 
51
54
  public:
52
55
  // Methods
53
- virtual std::string applyMask(const std::string& value, const std::string& maskType, const NitroMaskOptions& options) = 0;
56
+ virtual MaskResult applyMask(const std::string& value, const std::string& maskType, const NitroMaskOptions& options) = 0;
54
57
 
55
58
  protected:
56
59
  // Hybrid Setup
@@ -0,0 +1,87 @@
1
+ ///
2
+ /// MaskResult.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+
32
+
33
+ #include <string>
34
+
35
+ namespace margelo::nitro::nitroinputmask {
36
+
37
+ /**
38
+ * A struct which can be represented as a JavaScript object (MaskResult).
39
+ */
40
+ struct MaskResult final {
41
+ public:
42
+ std::string masked SWIFT_PRIVATE;
43
+ std::string raw SWIFT_PRIVATE;
44
+
45
+ public:
46
+ MaskResult() = default;
47
+ explicit MaskResult(std::string masked, std::string raw): masked(masked), raw(raw) {}
48
+
49
+ public:
50
+ friend bool operator==(const MaskResult& lhs, const MaskResult& rhs) = default;
51
+ };
52
+
53
+ } // namespace margelo::nitro::nitroinputmask
54
+
55
+ namespace margelo::nitro {
56
+
57
+ // C++ MaskResult <> JS MaskResult (object)
58
+ template <>
59
+ struct JSIConverter<margelo::nitro::nitroinputmask::MaskResult> final {
60
+ static inline margelo::nitro::nitroinputmask::MaskResult fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
61
+ jsi::Object obj = arg.asObject(runtime);
62
+ return margelo::nitro::nitroinputmask::MaskResult(
63
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "masked"))),
64
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "raw")))
65
+ );
66
+ }
67
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitroinputmask::MaskResult& arg) {
68
+ jsi::Object obj(runtime);
69
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "masked"), JSIConverter<std::string>::toJSI(runtime, arg.masked));
70
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "raw"), JSIConverter<std::string>::toJSI(runtime, arg.raw));
71
+ return obj;
72
+ }
73
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
74
+ if (!value.isObject()) {
75
+ return false;
76
+ }
77
+ jsi::Object obj = value.getObject(runtime);
78
+ if (!nitro::isPlainObject(runtime, obj)) {
79
+ return false;
80
+ }
81
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "masked")))) return false;
82
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "raw")))) return false;
83
+ return true;
84
+ }
85
+ };
86
+
87
+ } // namespace margelo::nitro
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salve-software/react-native-nitro-input-mask",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "High-performance native input masks for React Native built with Nitro Modules. Phone, currency, CPF, credit card and custom masks with zero JS flicker.",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "module": "./lib/module/index.js",
@@ -63,7 +63,8 @@
63
63
  "homepage": "https://github.com/Salve-Software/react-native-nitro-input-mask#readme",
64
64
  "publishConfig": {
65
65
  "access": "public",
66
- "registry": "https://registry.npmjs.org/"
66
+ "registry": "https://registry.npmjs.org/",
67
+ "provenance": true
67
68
  },
68
69
  "devDependencies": {
69
70
  "@jamesacarr/eslint-formatter-github-actions": "^0.2.0",
@@ -1,4 +1,5 @@
1
1
  import type { IApplyMaskProps } from './types';
2
+ import type { MaskResult } from '../../types';
2
3
  import { getNitroServiceModule } from '../../nitro-module';
3
4
 
4
5
  /**
@@ -8,23 +9,25 @@ import { getNitroServiceModule } from '../../nitro-module';
8
9
  * plain function call — no component or ref required.
9
10
  *
10
11
  * @example
11
- * const masked = NitroInputMaskService.applyMask({
12
+ * const { masked, raw } = NitroInputMaskService.applyMask({
12
13
  * value: '12345678901',
13
14
  * maskOptions: { mask: '999.999.999-99' },
14
15
  * })
15
- * // '123.456.789-01'
16
+ * // masked: '123.456.789-01'
17
+ * // raw: '12345678901'
16
18
  *
17
19
  * @example
18
- * const masked = NitroInputMaskService.applyMask({
20
+ * const { masked, raw } = NitroInputMaskService.applyMask({
19
21
  * value: '123456',
20
22
  * maskType: 'money',
21
23
  * maskOptions: { unit: 'R$ ', precision: 2 },
22
24
  * })
23
- * // 'R$ 1.234,56'
25
+ * // masked: 'R$ 1.234,56'
26
+ * // raw: '123456' (digit-only string for money masks)
24
27
  */
25
28
  export class NitroInputMaskService {
26
29
  /**
27
- * Applies a mask to a string and returns the masked result.
30
+ * Applies a mask to a string and returns both the masked and raw values.
28
31
  *
29
32
  * For `custom` masks, tokens are:
30
33
  * - `9` — digit (0–9)
@@ -36,18 +39,19 @@ export class NitroInputMaskService {
36
39
  * @param props.value - The raw string to mask.
37
40
  * @param props.maskType - The mask type: `'custom'` (default), `'money'`, `'datetime'`, `'credit-card'`.
38
41
  * @param props.maskOptions - Options specific to the chosen mask type.
39
- * @returns The masked string.
42
+ * @returns `{ masked, raw }` — the formatted string and the unformatted input.
43
+ * For money masks, `raw` is a digit-only string.
40
44
  *
41
45
  * @throws If `value` exceeds 1000 characters or `custom` mask exceeds 200 characters.
42
46
  *
43
47
  * @example
44
- * NitroInputMaskService.applyMask({
48
+ * const { masked } = NitroInputMaskService.applyMask({
45
49
  * value: '11987654321',
46
50
  * maskOptions: { mask: '(99) 99999-9999' },
47
51
  * })
48
- * // '(11) 98765-4321'
52
+ * // masked: '(11) 98765-4321'
49
53
  */
50
- static applyMask = (props: IApplyMaskProps): string => {
54
+ static applyMask = (props: IApplyMaskProps): MaskResult => {
51
55
  const { value, maskType, maskOptions } = props as IApplyMaskProps & {
52
56
  maskType?: string;
53
57
  maskOptions?: Record<string, unknown>;
@@ -57,9 +61,13 @@ export class NitroInputMaskService {
57
61
  const resolvedMaskType = maskType ?? 'custom';
58
62
  const resolvedOptions = maskOptions ?? {};
59
63
 
64
+ if (resolvedValue.length > 1000) {
65
+ throw new Error('NitroInputMaskService: value exceeds maximum allowed length');
66
+ }
67
+
60
68
  if (resolvedMaskType === 'custom') {
61
69
  const mask = String((resolvedOptions as { mask?: string }).mask ?? '');
62
- if (!mask) return resolvedValue;
70
+ if (!mask) return { masked: resolvedValue, raw: resolvedValue };
63
71
  if (resolvedValue.length > 1000 || mask.length > 200) {
64
72
  throw new Error('NitroInputMaskService: value or mask exceeds maximum allowed length');
65
73
  }
@@ -1,38 +1,56 @@
1
1
  import type { NitroInputMaskProps } from './types';
2
- import React, { useEffect, useId } from 'react';
2
+ import type { NitroMaskOptions } from '../../specs/nitro-input-mask.nitro';
3
+ import React, { useCallback, useEffect, useId, useMemo, useRef } from 'react';
3
4
  import { TextInput } from 'react-native';
4
- import { nitroModule } from '../../nitro-module';
5
+ import { nitroModule, getNitroServiceModule } from '../../nitro-module';
5
6
 
6
7
  export const NitroInputMask = (props: NitroInputMaskProps) => {
7
- const { maskType, maskOptions, value, ...rest } = props as NitroInputMaskProps & {
8
- maskType?: string;
9
- maskOptions?: Record<string, unknown>;
10
- };
8
+ const { maskType, maskOptions, onChangeText, value, ...rest } = props;
11
9
 
12
- const resolvedMaskType = maskType ?? 'custom';
13
10
  const reactId = useId();
11
+
12
+ const resolvedMaskType = maskType ?? 'custom';
13
+ const resolvedOptions = (maskOptions ?? {}) as Record<string, unknown>;
14
14
  const id = `nitro-input-mask-${reactId}`;
15
+ const maskOptionsJson = JSON.stringify(resolvedOptions);
15
16
 
16
- const maskOptionsJson = JSON.stringify(maskOptions ?? {});
17
+ const stableOptions: NitroMaskOptions = useMemo(() => JSON.parse(maskOptionsJson), [maskOptionsJson]);
18
+ const valueFromUserInput = useRef(false);
17
19
 
18
20
  useEffect(() => {
19
- nitroModule.attach(id, resolvedMaskType, maskOptions ?? {});
21
+ nitroModule.attach(id, resolvedMaskType, stableOptions);
20
22
  if (value != null) nitroModule.setValue(id, String(value));
21
23
  return () => nitroModule.detach(id);
22
24
  }, []);
23
25
 
24
26
  useEffect(() => {
25
- nitroModule.updateMask(id, resolvedMaskType, maskOptions ?? {});
27
+ nitroModule.updateMask(id, resolvedMaskType, stableOptions);
26
28
  }, [resolvedMaskType, maskOptionsJson]);
27
29
 
28
30
  useEffect(() => {
29
31
  if (value == null) return;
32
+
33
+ if (valueFromUserInput.current) {
34
+ valueFromUserInput.current = false;
35
+ return;
36
+ }
37
+
30
38
  nitroModule.setValue(id, String(value));
31
39
  }, [value]);
32
40
 
41
+ const handleChangeText = useCallback((text: string) => {
42
+ valueFromUserInput.current = true;
43
+
44
+ if (onChangeText) {
45
+ const result = getNitroServiceModule().applyMask(text, resolvedMaskType, stableOptions);
46
+ onChangeText(result);
47
+ }
48
+ }, [onChangeText, resolvedMaskType, stableOptions]);
49
+
33
50
  return (
34
- <TextInput
51
+ <TextInput
35
52
  {...rest}
53
+ onChangeText={handleChangeText}
36
54
  nativeID={id}
37
55
  />
38
56
  )
@@ -1,4 +1,21 @@
1
1
  import type { TextInputProps } from 'react-native';
2
- import type { MaskConfig } from '../../../types';
2
+ import type { MaskConfig, MaskResult } from '../../../types';
3
3
 
4
- export type NitroInputMaskProps = TextInputProps & MaskConfig;
4
+ export type NitroInputMaskProps = Omit<TextInputProps, 'onChangeText'> & MaskConfig & {
5
+ /**
6
+ * Called on every edit with both the masked display value and the raw
7
+ * unformatted value, giving consumers a single callback for both.
8
+ *
9
+ * For money masks, `raw` is a digit-only string.
10
+ *
11
+ * @example
12
+ * <NitroInputMask
13
+ * maskOptions={{ mask: '(999) 999-9999' }}
14
+ * onChangeText={({ masked, raw }) => {
15
+ * setDisplay(masked)
16
+ * setDigits(raw)
17
+ * }}
18
+ * />
19
+ */
20
+ onChangeText?: (result: MaskResult) => void
21
+ }
@@ -1,6 +1,14 @@
1
1
  import type { HybridObject } from 'react-native-nitro-modules'
2
2
  import type { NitroMaskOptions } from './nitro-input-mask.nitro'
3
3
 
4
+ // Declared inline to ensure Nitro codegen can resolve the type without
5
+ // cross-file imports, which some versions of nitrogen reject.
6
+ // Keep in sync with src/types/MaskResult.ts.
7
+ export interface MaskResult {
8
+ masked: string
9
+ raw: string
10
+ }
11
+
4
12
  export interface NitroInputMaskService extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
5
- applyMask(value: string, maskType: string, options: NitroMaskOptions): string
13
+ applyMask(value: string, maskType: string, options: NitroMaskOptions): MaskResult
6
14
  }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The result returned by `NitroInputMaskService.applyMask()` and
3
+ * delivered to `<NitroInputMask onChangeText />`.
4
+ *
5
+ * - `masked` — the formatted string as displayed to the user (e.g. `"(555) 123-4567"`)
6
+ * - `raw` — the unformatted input stripped of mask literals.
7
+ * For money masks this is a digit-only string (e.g. `"123456"`).
8
+ */
9
+ export type MaskResult = {
10
+ masked: string
11
+ raw: string
12
+ }
@@ -1,5 +1,6 @@
1
1
  export type * from './CustomMaskOptions';
2
2
  export type * from './MaskConfig';
3
+ export type * from './MaskResult';
3
4
  export type * from './MoneyMaskOptions';
4
5
  export type * from './CreditCardMaskOptions';
5
6
  export type * from './DatetimeMaskOptions';