react-native-mmkv 4.0.0-beta.1 → 4.0.0-beta.2

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 (219) hide show
  1. package/{react-native-mmkv.podspec → NitroMmkv.podspec} +17 -13
  2. package/README.md +1 -3
  3. package/android/CMakeLists.txt +31 -30
  4. package/android/build.gradle +64 -19
  5. package/android/fix-prefab.gradle +51 -0
  6. package/android/gradle.properties +5 -5
  7. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  8. package/android/src/main/java/com/margelo/nitro/mmkv/HybridMMKVPlatformContext.kt +19 -0
  9. package/android/src/main/java/com/margelo/nitro/mmkv/NitroMmkvPackage.java +33 -0
  10. package/ios/HybridMMKVPlatformContext.swift +32 -0
  11. package/lib/__tests__/hooks.test.d.ts +1 -0
  12. package/lib/__tests__/hooks.test.js +66 -0
  13. package/lib/addMemoryWarningListener/addMemoryWarningListener.d.ts +2 -0
  14. package/lib/addMemoryWarningListener/addMemoryWarningListener.js +25 -0
  15. package/lib/addMemoryWarningListener/addMemoryWarningListener.mock.d.ts +2 -0
  16. package/lib/addMemoryWarningListener/addMemoryWarningListener.mock.js +3 -0
  17. package/lib/addMemoryWarningListener/addMemoryWarningListener.web.d.ts +2 -0
  18. package/lib/addMemoryWarningListener/addMemoryWarningListener.web.js +3 -0
  19. package/lib/createMMKV/createMMKV.d.ts +3 -0
  20. package/lib/createMMKV/createMMKV.js +40 -0
  21. package/lib/createMMKV/createMMKV.mock.d.ts +5 -0
  22. package/lib/createMMKV/createMMKV.mock.js +53 -0
  23. package/lib/createMMKV/createMMKV.web.d.ts +3 -0
  24. package/lib/createMMKV/createMMKV.web.js +117 -0
  25. package/lib/createMMKV/getDefaultMMKVInstance.d.ts +2 -0
  26. package/lib/createMMKV/getDefaultMMKVInstance.js +8 -0
  27. package/lib/hooks/createMMKVHook.d.ts +2 -0
  28. package/lib/hooks/createMMKVHook.js +49 -0
  29. package/lib/hooks/useMMKV.d.ts +11 -0
  30. package/lib/hooks/useMMKV.js +23 -0
  31. package/lib/hooks/useMMKVBoolean.d.ts +11 -0
  32. package/lib/hooks/useMMKVBoolean.js +12 -0
  33. package/lib/hooks/useMMKVBuffer.d.ts +11 -0
  34. package/lib/hooks/useMMKVBuffer.js +12 -0
  35. package/lib/hooks/useMMKVKeys.d.ts +12 -0
  36. package/lib/hooks/useMMKVKeys.js +33 -0
  37. package/lib/hooks/useMMKVListener.d.ts +15 -0
  38. package/lib/hooks/useMMKVListener.js +26 -0
  39. package/lib/hooks/useMMKVNumber.d.ts +11 -0
  40. package/lib/hooks/useMMKVNumber.js +12 -0
  41. package/lib/hooks/useMMKVObject.d.ts +17 -0
  42. package/lib/hooks/useMMKVObject.js +38 -0
  43. package/lib/hooks/useMMKVString.d.ts +11 -0
  44. package/lib/hooks/useMMKVString.js +12 -0
  45. package/lib/index.d.ts +11 -0
  46. package/lib/index.js +11 -0
  47. package/lib/isTest.d.ts +1 -0
  48. package/lib/isTest.js +7 -0
  49. package/lib/specs/MMKV.nitro.d.ts +93 -0
  50. package/lib/specs/MMKV.nitro.js +1 -0
  51. package/lib/{typescript/src/NativeMmkv.d.ts → specs/MMKVFactory.nitro.d.ts} +22 -29
  52. package/lib/specs/MMKVFactory.nitro.js +1 -0
  53. package/lib/specs/MMKVPlatformContext.nitro.d.ts +15 -0
  54. package/lib/specs/MMKVPlatformContext.nitro.js +1 -0
  55. package/lib/{typescript/src → web}/createTextEncoder.d.ts +0 -1
  56. package/lib/web/createTextEncoder.js +17 -0
  57. package/nitro.json +27 -0
  58. package/nitrogen/generated/.gitattributes +1 -0
  59. package/nitrogen/generated/android/NitroMmkv+autolinking.cmake +80 -0
  60. package/nitrogen/generated/android/NitroMmkv+autolinking.gradle +27 -0
  61. package/nitrogen/generated/android/NitroMmkvOnLoad.cpp +55 -0
  62. package/nitrogen/generated/android/NitroMmkvOnLoad.hpp +25 -0
  63. package/nitrogen/generated/android/c++/JHybridMMKVPlatformContextSpec.cpp +51 -0
  64. package/nitrogen/generated/android/c++/JHybridMMKVPlatformContextSpec.hpp +65 -0
  65. package/nitrogen/generated/android/kotlin/com/margelo/nitro/mmkv/HybridMMKVPlatformContextSpec.kt +56 -0
  66. package/nitrogen/generated/android/kotlin/com/margelo/nitro/mmkv/NitroMmkvOnLoad.kt +35 -0
  67. package/nitrogen/generated/ios/NitroMmkv+autolinking.rb +60 -0
  68. package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Bridge.cpp +32 -0
  69. package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Bridge.hpp +52 -0
  70. package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Umbrella.hpp +44 -0
  71. package/nitrogen/generated/ios/NitroMmkvAutolinking.mm +43 -0
  72. package/nitrogen/generated/ios/NitroMmkvAutolinking.swift +25 -0
  73. package/nitrogen/generated/ios/c++/HybridMMKVPlatformContextSpecSwift.cpp +11 -0
  74. package/nitrogen/generated/ios/c++/HybridMMKVPlatformContextSpecSwift.hpp +81 -0
  75. package/nitrogen/generated/ios/swift/HybridMMKVPlatformContextSpec.swift +50 -0
  76. package/nitrogen/generated/ios/swift/HybridMMKVPlatformContextSpec_cxx.swift +135 -0
  77. package/nitrogen/generated/shared/c++/Configuration.hpp +86 -0
  78. package/nitrogen/generated/shared/c++/HybridMMKVFactorySpec.cpp +23 -0
  79. package/nitrogen/generated/shared/c++/HybridMMKVFactorySpec.hpp +69 -0
  80. package/nitrogen/generated/shared/c++/HybridMMKVPlatformContextSpec.cpp +22 -0
  81. package/nitrogen/generated/shared/c++/HybridMMKVPlatformContextSpec.hpp +63 -0
  82. package/nitrogen/generated/shared/c++/HybridMMKVSpec.cpp +34 -0
  83. package/nitrogen/generated/shared/c++/HybridMMKVSpec.hpp +83 -0
  84. package/nitrogen/generated/shared/c++/Listener.hpp +67 -0
  85. package/nitrogen/generated/shared/c++/Mode.hpp +76 -0
  86. package/package.json +71 -122
  87. package/react-native.config.js +2 -15
  88. package/src/__tests__/hooks.test.tsx +34 -34
  89. package/src/addMemoryWarningListener/addMemoryWarningListener.mock.ts +5 -0
  90. package/src/{MemoryWarningListener.ts → addMemoryWarningListener/addMemoryWarningListener.ts} +12 -12
  91. package/src/addMemoryWarningListener/addMemoryWarningListener.web.ts +5 -0
  92. package/src/createMMKV/createMMKV.mock.ts +56 -0
  93. package/src/createMMKV/createMMKV.ts +51 -0
  94. package/src/{createMMKV.web.ts → createMMKV/createMMKV.web.ts} +56 -46
  95. package/src/createMMKV/getDefaultMMKVInstance.ts +10 -0
  96. package/src/hooks/createMMKVHook.ts +66 -0
  97. package/src/hooks/useMMKV.ts +45 -0
  98. package/src/hooks/useMMKVBoolean.ts +15 -0
  99. package/src/hooks/useMMKVBuffer.ts +15 -0
  100. package/src/hooks/useMMKVKeys.ts +36 -0
  101. package/src/hooks/useMMKVListener.ts +33 -0
  102. package/src/hooks/useMMKVNumber.ts +15 -0
  103. package/src/hooks/useMMKVObject.ts +53 -0
  104. package/src/hooks/useMMKVString.ts +15 -0
  105. package/src/index.ts +15 -3
  106. package/src/{PlatformChecker.ts → isTest.ts} +2 -2
  107. package/src/specs/MMKV.nitro.ts +92 -0
  108. package/src/specs/MMKVFactory.nitro.ts +87 -0
  109. package/src/specs/MMKVPlatformContext.nitro.ts +14 -0
  110. package/src/{createTextEncoder.ts → web/createTextEncoder.ts} +7 -7
  111. package/android/src/main/cpp/AndroidLogger.cpp +0 -16
  112. package/android/src/main/java/com/mrousavy/mmkv/MmkvPackage.java +0 -44
  113. package/android/src/main/java/com/mrousavy/mmkv/MmkvPlatformContextModule.java +0 -26
  114. package/cpp/ManagedMMBuffer.h +0 -32
  115. package/cpp/MmkvHostObject.cpp +0 -360
  116. package/cpp/MmkvHostObject.h +0 -31
  117. package/cpp/MmkvLogger.h +0 -35
  118. package/cpp/MmkvTypes.h +0 -50
  119. package/cpp/NativeMmkvModule.cpp +0 -43
  120. package/cpp/NativeMmkvModule.h +0 -31
  121. package/ios/AppleLogger.mm +0 -16
  122. package/ios/MmkvOnLoad.mm +0 -25
  123. package/ios/MmkvPlatformContext.h +0 -19
  124. package/ios/MmkvPlatformContextModule.mm +0 -55
  125. package/lib/commonjs/MMKV.js +0 -124
  126. package/lib/commonjs/MMKV.js.map +0 -1
  127. package/lib/commonjs/MemoryWarningListener.js +0 -31
  128. package/lib/commonjs/MemoryWarningListener.js.map +0 -1
  129. package/lib/commonjs/MemoryWarningListener.web.js +0 -11
  130. package/lib/commonjs/MemoryWarningListener.web.js.map +0 -1
  131. package/lib/commonjs/ModuleNotFoundError.js +0 -75
  132. package/lib/commonjs/ModuleNotFoundError.js.map +0 -1
  133. package/lib/commonjs/NativeMmkv.js +0 -47
  134. package/lib/commonjs/NativeMmkv.js.map +0 -1
  135. package/lib/commonjs/NativeMmkvPlatformContext.js +0 -22
  136. package/lib/commonjs/NativeMmkvPlatformContext.js.map +0 -1
  137. package/lib/commonjs/PlatformChecker.js +0 -14
  138. package/lib/commonjs/PlatformChecker.js.map +0 -1
  139. package/lib/commonjs/Types.js +0 -26
  140. package/lib/commonjs/Types.js.map +0 -1
  141. package/lib/commonjs/createMMKV.js +0 -43
  142. package/lib/commonjs/createMMKV.js.map +0 -1
  143. package/lib/commonjs/createMMKV.mock.js +0 -43
  144. package/lib/commonjs/createMMKV.mock.js.map +0 -1
  145. package/lib/commonjs/createMMKV.web.js +0 -110
  146. package/lib/commonjs/createMMKV.web.js.map +0 -1
  147. package/lib/commonjs/createTextEncoder.js +0 -23
  148. package/lib/commonjs/createTextEncoder.js.map +0 -1
  149. package/lib/commonjs/hooks.js +0 -198
  150. package/lib/commonjs/hooks.js.map +0 -1
  151. package/lib/commonjs/index.js +0 -40
  152. package/lib/commonjs/index.js.map +0 -1
  153. package/lib/commonjs/package.json +0 -1
  154. package/lib/module/MMKV.js +0 -119
  155. package/lib/module/MMKV.js.map +0 -1
  156. package/lib/module/MemoryWarningListener.js +0 -27
  157. package/lib/module/MemoryWarningListener.js.map +0 -1
  158. package/lib/module/MemoryWarningListener.web.js +0 -6
  159. package/lib/module/MemoryWarningListener.web.js.map +0 -1
  160. package/lib/module/ModuleNotFoundError.js +0 -70
  161. package/lib/module/ModuleNotFoundError.js.map +0 -1
  162. package/lib/module/NativeMmkv.js +0 -45
  163. package/lib/module/NativeMmkv.js.map +0 -1
  164. package/lib/module/NativeMmkvPlatformContext.js +0 -18
  165. package/lib/module/NativeMmkvPlatformContext.js.map +0 -1
  166. package/lib/module/PlatformChecker.js +0 -10
  167. package/lib/module/PlatformChecker.js.map +0 -1
  168. package/lib/module/Types.js +0 -25
  169. package/lib/module/Types.js.map +0 -1
  170. package/lib/module/createMMKV.js +0 -38
  171. package/lib/module/createMMKV.js.map +0 -1
  172. package/lib/module/createMMKV.mock.js +0 -38
  173. package/lib/module/createMMKV.mock.js.map +0 -1
  174. package/lib/module/createMMKV.web.js +0 -105
  175. package/lib/module/createMMKV.web.js.map +0 -1
  176. package/lib/module/createTextEncoder.js +0 -19
  177. package/lib/module/createTextEncoder.js.map +0 -1
  178. package/lib/module/hooks.js +0 -189
  179. package/lib/module/hooks.js.map +0 -1
  180. package/lib/module/index.js +0 -6
  181. package/lib/module/index.js.map +0 -1
  182. package/lib/module/package.json +0 -1
  183. package/lib/typescript/src/MMKV.d.ts +0 -34
  184. package/lib/typescript/src/MMKV.d.ts.map +0 -1
  185. package/lib/typescript/src/MemoryWarningListener.d.ts +0 -3
  186. package/lib/typescript/src/MemoryWarningListener.d.ts.map +0 -1
  187. package/lib/typescript/src/MemoryWarningListener.web.d.ts +0 -3
  188. package/lib/typescript/src/MemoryWarningListener.web.d.ts.map +0 -1
  189. package/lib/typescript/src/ModuleNotFoundError.d.ts +0 -7
  190. package/lib/typescript/src/ModuleNotFoundError.d.ts.map +0 -1
  191. package/lib/typescript/src/NativeMmkv.d.ts.map +0 -1
  192. package/lib/typescript/src/NativeMmkvPlatformContext.d.ts +0 -20
  193. package/lib/typescript/src/NativeMmkvPlatformContext.d.ts.map +0 -1
  194. package/lib/typescript/src/PlatformChecker.d.ts +0 -2
  195. package/lib/typescript/src/PlatformChecker.d.ts.map +0 -1
  196. package/lib/typescript/src/Types.d.ts +0 -172
  197. package/lib/typescript/src/Types.d.ts.map +0 -1
  198. package/lib/typescript/src/__tests__/hooks.test.d.ts +0 -2
  199. package/lib/typescript/src/__tests__/hooks.test.d.ts.map +0 -1
  200. package/lib/typescript/src/createMMKV.d.ts +0 -3
  201. package/lib/typescript/src/createMMKV.d.ts.map +0 -1
  202. package/lib/typescript/src/createMMKV.mock.d.ts +0 -3
  203. package/lib/typescript/src/createMMKV.mock.d.ts.map +0 -1
  204. package/lib/typescript/src/createMMKV.web.d.ts +0 -3
  205. package/lib/typescript/src/createMMKV.web.d.ts.map +0 -1
  206. package/lib/typescript/src/createTextEncoder.d.ts.map +0 -1
  207. package/lib/typescript/src/hooks.d.ts +0 -86
  208. package/lib/typescript/src/hooks.d.ts.map +0 -1
  209. package/lib/typescript/src/index.d.ts +0 -4
  210. package/lib/typescript/src/index.d.ts.map +0 -1
  211. package/src/MMKV.ts +0 -142
  212. package/src/MemoryWarningListener.web.ts +0 -5
  213. package/src/ModuleNotFoundError.ts +0 -95
  214. package/src/NativeMmkv.ts +0 -118
  215. package/src/NativeMmkvPlatformContext.ts +0 -38
  216. package/src/Types.ts +0 -178
  217. package/src/createMMKV.mock.ts +0 -38
  218. package/src/createMMKV.ts +0 -42
  219. package/src/hooks.ts +0 -247
@@ -1,23 +1,11 @@
1
- import type { TurboModule } from 'react-native';
2
- import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
3
- /**
4
- * IMPORTANT: These types are also in the Types.ts file.
5
- * Due to how react-native-codegen works these are required here as the spec types can not be separated from spec.
6
- * We also need the types separate to allow bypassing importing turbo module registry in web
7
- */
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+ import type { MMKV } from './MMKV.nitro';
8
3
  /**
9
4
  * Configures the mode of the MMKV instance.
5
+ * - `single-process`: The MMKV instance is only used from a single process (this app).
6
+ * - `multi-process`: The MMKV instance may be used from multiple processes, such as app clips, share extensions or background services.
10
7
  */
11
- export declare enum Mode {
12
- /**
13
- * The MMKV instance is only used from a single process (this app).
14
- */
15
- SINGLE_PROCESS = 0,
16
- /**
17
- * The MMKV instance may be used from multiple processes, such as app clips, share extensions or background services.
18
- */
19
- MULTI_PROCESS = 1
20
- }
8
+ export type Mode = 'single-process' | 'multi-process';
21
9
  /**
22
10
  * Used for configuration of a single MMKV instance.
23
11
  */
@@ -64,28 +52,33 @@ export interface Configuration {
64
52
  encryptionKey?: string;
65
53
  /**
66
54
  * Configure the processing mode for MMKV.
67
- * - `SINGLE_PROCESS`: The MMKV instance is only used from a single process (this app).
68
- * - `MULTI_PROCESS`: The MMKV instance may be used from multiple processes, such as app clips, share extensions or background services.
69
55
  *
70
- * @default SINGLE_PROCESS
56
+ * @default 'single-process'
71
57
  */
72
58
  mode?: Mode;
73
59
  /**
74
60
  * If `true`, the MMKV instance can only read from the storage, but not write to it.
61
+ * This is more efficient if you do not need to write to it.
62
+ * @default false
75
63
  */
76
64
  readOnly?: boolean;
77
65
  }
78
- export interface Spec extends TurboModule {
66
+ export interface MMKVFactory extends HybridObject<{
67
+ ios: 'c++';
68
+ android: 'c++';
69
+ }> {
79
70
  /**
80
- * Initialize MMKV with the given base storage directory.
81
- * This should be the documents directory by default.
71
+ * Create a new {@linkcode MMKV} instance with the given {@linkcode Configuration}
82
72
  */
83
- initialize(basePath: string): boolean;
73
+ createMMKV(configuration: Configuration): MMKV;
84
74
  /**
85
- * Create a new instance of MMKV.
86
- * The returned {@linkcode UnsafeObject} is a `jsi::HostObject`.
75
+ * Initialize the MMKV library with the given root path.
76
+ * This has to be called once, before using {@linkcode createMMKV}.
77
+ */
78
+ initializeMMKV(rootPath: string): void;
79
+ /**
80
+ * Get the default MMKV instance's ID.
81
+ * @default 'mmkv.default'
87
82
  */
88
- createMMKV(configuration: Configuration): UnsafeObject;
83
+ readonly defaultMMKVInstanceId: string;
89
84
  }
90
- export declare function getMMKVTurboModule(): Spec;
91
- //# sourceMappingURL=NativeMmkv.d.ts.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+ export interface MMKVPlatformContext extends HybridObject<{
3
+ ios: 'swift';
4
+ android: 'kotlin';
5
+ }> {
6
+ /**
7
+ * Get the MMKV base directory
8
+ */
9
+ getBaseDirectory(): string;
10
+ /**
11
+ * Get the MMKV AppGroup's directory.
12
+ * @platform iOS
13
+ */
14
+ getAppGroupDirectory(): string;
15
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1 @@
1
1
  export declare function createTextEncoder(): TextEncoder;
2
- //# sourceMappingURL=createTextEncoder.d.ts.map
@@ -0,0 +1,17 @@
1
+ export function createTextEncoder() {
2
+ const g = global ?? globalThis ?? window;
3
+ if (g.TextEncoder != null) {
4
+ return new g.TextEncoder();
5
+ }
6
+ else {
7
+ return {
8
+ encode: () => {
9
+ throw new Error('TextEncoder is not supported in this environment!');
10
+ },
11
+ encodeInto: () => {
12
+ throw new Error('TextEncoder is not supported in this environment!');
13
+ },
14
+ encoding: 'utf-8',
15
+ };
16
+ }
17
+ }
package/nitro.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "$schema": "https://nitro.margelo.com/nitro.schema.json",
3
+ "cxxNamespace": [
4
+ "mmkv"
5
+ ],
6
+ "ios": {
7
+ "iosModuleName": "NitroMmkv"
8
+ },
9
+ "android": {
10
+ "androidNamespace": [
11
+ "mmkv"
12
+ ],
13
+ "androidCxxLibName": "NitroMmkv"
14
+ },
15
+ "autolinking": {
16
+ "MMKVFactory": {
17
+ "cpp": "HybridMMKVFactory"
18
+ },
19
+ "MMKVPlatformContext": {
20
+ "swift": "HybridMMKVPlatformContext",
21
+ "kotlin": "HybridMMKVPlatformContext"
22
+ }
23
+ },
24
+ "ignorePaths": [
25
+ "**/node_modules"
26
+ ]
27
+ }
@@ -0,0 +1 @@
1
+ ** linguist-generated=true
@@ -0,0 +1,80 @@
1
+ #
2
+ # NitroMmkv+autolinking.cmake
3
+ # This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ # https://github.com/mrousavy/nitro
5
+ # Copyright © 2025 Marc Rousavy @ Margelo
6
+ #
7
+
8
+ # This is a CMake file that adds all files generated by Nitrogen
9
+ # to the current CMake project.
10
+ #
11
+ # To use it, add this to your CMakeLists.txt:
12
+ # ```cmake
13
+ # include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/NitroMmkv+autolinking.cmake)
14
+ # ```
15
+
16
+ # Add all headers that were generated by Nitrogen
17
+ include_directories(
18
+ "../nitrogen/generated/shared/c++"
19
+ "../nitrogen/generated/android/c++"
20
+ "../nitrogen/generated/android/"
21
+ )
22
+
23
+ # Add all .cpp sources that were generated by Nitrogen
24
+ target_sources(
25
+ # CMake project name (Android C++ library name)
26
+ NitroMmkv PRIVATE
27
+ # Autolinking Setup
28
+ ../nitrogen/generated/android/NitroMmkvOnLoad.cpp
29
+ # Shared Nitrogen C++ sources
30
+ ../nitrogen/generated/shared/c++/HybridMMKVSpec.cpp
31
+ ../nitrogen/generated/shared/c++/HybridMMKVFactorySpec.cpp
32
+ ../nitrogen/generated/shared/c++/HybridMMKVPlatformContextSpec.cpp
33
+ # Android-specific Nitrogen C++ sources
34
+ ../nitrogen/generated/android/c++/JHybridMMKVPlatformContextSpec.cpp
35
+ )
36
+
37
+ # Define a flag to check if we are building properly
38
+ add_definitions(-DBUILDING_NITROMMKV_WITH_GENERATED_CMAKE_PROJECT)
39
+
40
+ # From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake
41
+ # Used in node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
42
+ target_compile_definitions(
43
+ NitroMmkv PRIVATE
44
+ -DFOLLY_NO_CONFIG=1
45
+ -DFOLLY_HAVE_CLOCK_GETTIME=1
46
+ -DFOLLY_USE_LIBCPP=1
47
+ -DFOLLY_CFG_NO_COROUTINES=1
48
+ -DFOLLY_MOBILE=1
49
+ -DFOLLY_HAVE_RECVMMSG=1
50
+ -DFOLLY_HAVE_PTHREAD=1
51
+ # Once we target android-23 above, we can comment
52
+ # the following line. NDK uses GNU style stderror_r() after API 23.
53
+ -DFOLLY_HAVE_XSI_STRERROR_R=1
54
+ )
55
+
56
+ # Add all libraries required by the generated specs
57
+ find_package(fbjni REQUIRED) # <-- Used for communication between Java <-> C++
58
+ find_package(ReactAndroid REQUIRED) # <-- Used to set up React Native bindings (e.g. CallInvoker/TurboModule)
59
+ find_package(react-native-nitro-modules REQUIRED) # <-- Used to create all HybridObjects and use the Nitro core library
60
+
61
+ # Link all libraries together
62
+ target_link_libraries(
63
+ NitroMmkv
64
+ fbjni::fbjni # <-- Facebook C++ JNI helpers
65
+ ReactAndroid::jsi # <-- RN: JSI
66
+ react-native-nitro-modules::NitroModules # <-- NitroModules Core :)
67
+ )
68
+
69
+ # Link react-native (different prefab between RN 0.75 and RN 0.76)
70
+ if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
71
+ target_link_libraries(
72
+ NitroMmkv
73
+ ReactAndroid::reactnative # <-- RN: Native Modules umbrella prefab
74
+ )
75
+ else()
76
+ target_link_libraries(
77
+ NitroMmkv
78
+ ReactAndroid::react_nativemodule_core # <-- RN: TurboModules Core
79
+ )
80
+ endif()
@@ -0,0 +1,27 @@
1
+ ///
2
+ /// NitroMmkv+autolinking.gradle
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ /// This is a Gradle file that adds all files generated by Nitrogen
9
+ /// to the current Gradle project.
10
+ ///
11
+ /// To use it, add this to your build.gradle:
12
+ /// ```gradle
13
+ /// apply from: '../nitrogen/generated/android/NitroMmkv+autolinking.gradle'
14
+ /// ```
15
+
16
+ logger.warn("[NitroModules] 🔥 NitroMmkv is boosted by nitro!")
17
+
18
+ android {
19
+ sourceSets {
20
+ main {
21
+ java.srcDirs += [
22
+ // Nitrogen files
23
+ "${project.projectDir}/../nitrogen/generated/android/kotlin"
24
+ ]
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,55 @@
1
+ ///
2
+ /// NitroMmkvOnLoad.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #ifndef BUILDING_NITROMMKV_WITH_GENERATED_CMAKE_PROJECT
9
+ #error NitroMmkvOnLoad.cpp is not being built with the autogenerated CMakeLists.txt project. Is a different CMakeLists.txt building this?
10
+ #endif
11
+
12
+ #include "NitroMmkvOnLoad.hpp"
13
+
14
+ #include <jni.h>
15
+ #include <fbjni/fbjni.h>
16
+ #include <NitroModules/HybridObjectRegistry.hpp>
17
+
18
+ #include "JHybridMMKVPlatformContextSpec.hpp"
19
+ #include "HybridMMKVFactory.hpp"
20
+ #include <NitroModules/DefaultConstructableObject.hpp>
21
+
22
+ namespace margelo::nitro::mmkv {
23
+
24
+ int initialize(JavaVM* vm) {
25
+ using namespace margelo::nitro;
26
+ using namespace margelo::nitro::mmkv;
27
+ using namespace facebook;
28
+
29
+ return facebook::jni::initialize(vm, [] {
30
+ // Register native JNI methods
31
+ margelo::nitro::mmkv::JHybridMMKVPlatformContextSpec::registerNatives();
32
+
33
+ // Register Nitro Hybrid Objects
34
+ HybridObjectRegistry::registerHybridObjectConstructor(
35
+ "MMKVFactory",
36
+ []() -> std::shared_ptr<HybridObject> {
37
+ static_assert(std::is_default_constructible_v<HybridMMKVFactory>,
38
+ "The HybridObject \"HybridMMKVFactory\" is not default-constructible! "
39
+ "Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
40
+ return std::make_shared<HybridMMKVFactory>();
41
+ }
42
+ );
43
+ HybridObjectRegistry::registerHybridObjectConstructor(
44
+ "MMKVPlatformContext",
45
+ []() -> std::shared_ptr<HybridObject> {
46
+ static DefaultConstructableObject<JHybridMMKVPlatformContextSpec::javaobject> object("com/margelo/nitro/mmkv/HybridMMKVPlatformContext");
47
+ auto instance = object.create();
48
+ auto globalRef = jni::make_global(instance);
49
+ return globalRef->cthis()->shared();
50
+ }
51
+ );
52
+ });
53
+ }
54
+
55
+ } // namespace margelo::nitro::mmkv
@@ -0,0 +1,25 @@
1
+ ///
2
+ /// NitroMmkvOnLoad.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include <jni.h>
9
+ #include <NitroModules/NitroDefines.hpp>
10
+
11
+ namespace margelo::nitro::mmkv {
12
+
13
+ /**
14
+ * Initializes the native (C++) part of NitroMmkv, and autolinks all Hybrid Objects.
15
+ * Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`).
16
+ * Example:
17
+ * ```cpp (cpp-adapter.cpp)
18
+ * JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
19
+ * return margelo::nitro::mmkv::initialize(vm);
20
+ * }
21
+ * ```
22
+ */
23
+ int initialize(JavaVM* vm);
24
+
25
+ } // namespace margelo::nitro::mmkv
@@ -0,0 +1,51 @@
1
+ ///
2
+ /// JHybridMMKVPlatformContextSpec.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "JHybridMMKVPlatformContextSpec.hpp"
9
+
10
+
11
+
12
+ #include <string>
13
+
14
+ namespace margelo::nitro::mmkv {
15
+
16
+ jni::local_ref<JHybridMMKVPlatformContextSpec::jhybriddata> JHybridMMKVPlatformContextSpec::initHybrid(jni::alias_ref<jhybridobject> jThis) {
17
+ return makeCxxInstance(jThis);
18
+ }
19
+
20
+ void JHybridMMKVPlatformContextSpec::registerNatives() {
21
+ registerHybrid({
22
+ makeNativeMethod("initHybrid", JHybridMMKVPlatformContextSpec::initHybrid),
23
+ });
24
+ }
25
+
26
+ size_t JHybridMMKVPlatformContextSpec::getExternalMemorySize() noexcept {
27
+ static const auto method = javaClassStatic()->getMethod<jlong()>("getMemorySize");
28
+ return method(_javaPart);
29
+ }
30
+
31
+ void JHybridMMKVPlatformContextSpec::dispose() noexcept {
32
+ static const auto method = javaClassStatic()->getMethod<void()>("dispose");
33
+ method(_javaPart);
34
+ }
35
+
36
+ // Properties
37
+
38
+
39
+ // Methods
40
+ std::string JHybridMMKVPlatformContextSpec::getBaseDirectory() {
41
+ static const auto method = javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getBaseDirectory");
42
+ auto __result = method(_javaPart);
43
+ return __result->toStdString();
44
+ }
45
+ std::string JHybridMMKVPlatformContextSpec::getAppGroupDirectory() {
46
+ static const auto method = javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getAppGroupDirectory");
47
+ auto __result = method(_javaPart);
48
+ return __result->toStdString();
49
+ }
50
+
51
+ } // namespace margelo::nitro::mmkv
@@ -0,0 +1,65 @@
1
+ ///
2
+ /// HybridMMKVPlatformContextSpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <NitroModules/JHybridObject.hpp>
11
+ #include <fbjni/fbjni.h>
12
+ #include "HybridMMKVPlatformContextSpec.hpp"
13
+
14
+
15
+
16
+
17
+ namespace margelo::nitro::mmkv {
18
+
19
+ using namespace facebook;
20
+
21
+ class JHybridMMKVPlatformContextSpec: public jni::HybridClass<JHybridMMKVPlatformContextSpec, JHybridObject>,
22
+ public virtual HybridMMKVPlatformContextSpec {
23
+ public:
24
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/mmkv/HybridMMKVPlatformContextSpec;";
25
+ static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
26
+ static void registerNatives();
27
+
28
+ protected:
29
+ // C++ constructor (called from Java via `initHybrid()`)
30
+ explicit JHybridMMKVPlatformContextSpec(jni::alias_ref<jhybridobject> jThis) :
31
+ HybridObject(HybridMMKVPlatformContextSpec::TAG),
32
+ HybridBase(jThis),
33
+ _javaPart(jni::make_global(jThis)) {}
34
+
35
+ public:
36
+ ~JHybridMMKVPlatformContextSpec() override {
37
+ // Hermes GC can destroy JS objects on a non-JNI Thread.
38
+ jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
39
+ }
40
+
41
+ public:
42
+ size_t getExternalMemorySize() noexcept override;
43
+ void dispose() noexcept override;
44
+
45
+ public:
46
+ inline const jni::global_ref<JHybridMMKVPlatformContextSpec::javaobject>& getJavaPart() const noexcept {
47
+ return _javaPart;
48
+ }
49
+
50
+ public:
51
+ // Properties
52
+
53
+
54
+ public:
55
+ // Methods
56
+ std::string getBaseDirectory() override;
57
+ std::string getAppGroupDirectory() override;
58
+
59
+ private:
60
+ friend HybridBase;
61
+ using HybridBase::HybridBase;
62
+ jni::global_ref<JHybridMMKVPlatformContextSpec::javaobject> _javaPart;
63
+ };
64
+
65
+ } // namespace margelo::nitro::mmkv
@@ -0,0 +1,56 @@
1
+ ///
2
+ /// HybridMMKVPlatformContextSpec.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.mmkv
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.jni.HybridData
12
+ import com.facebook.proguard.annotations.DoNotStrip
13
+ import com.margelo.nitro.core.*
14
+
15
+ /**
16
+ * A Kotlin class representing the MMKVPlatformContext HybridObject.
17
+ * Implement this abstract class to create Kotlin-based instances of MMKVPlatformContext.
18
+ */
19
+ @DoNotStrip
20
+ @Keep
21
+ @Suppress(
22
+ "KotlinJniMissingFunction", "unused",
23
+ "RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet",
24
+ "LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName"
25
+ )
26
+ abstract class HybridMMKVPlatformContextSpec: HybridObject() {
27
+ @DoNotStrip
28
+ private var mHybridData: HybridData = initHybrid()
29
+
30
+ init {
31
+ super.updateNative(mHybridData)
32
+ }
33
+
34
+ override fun updateNative(hybridData: HybridData) {
35
+ mHybridData = hybridData
36
+ super.updateNative(hybridData)
37
+ }
38
+
39
+ // Properties
40
+
41
+
42
+ // Methods
43
+ @DoNotStrip
44
+ @Keep
45
+ abstract fun getBaseDirectory(): String
46
+
47
+ @DoNotStrip
48
+ @Keep
49
+ abstract fun getAppGroupDirectory(): String
50
+
51
+ private external fun initHybrid(): HybridData
52
+
53
+ companion object {
54
+ private const val TAG = "HybridMMKVPlatformContextSpec"
55
+ }
56
+ }
@@ -0,0 +1,35 @@
1
+ ///
2
+ /// NitroMmkvOnLoad.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.mmkv
9
+
10
+ import android.util.Log
11
+
12
+ internal class NitroMmkvOnLoad {
13
+ companion object {
14
+ private const val TAG = "NitroMmkvOnLoad"
15
+ private var didLoad = false
16
+ /**
17
+ * Initializes the native part of "NitroMmkv".
18
+ * This method is idempotent and can be called more than once.
19
+ */
20
+ @JvmStatic
21
+ fun initializeNative() {
22
+ if (didLoad) return
23
+ try {
24
+ Log.i(TAG, "Loading NitroMmkv C++ library...")
25
+ System.loadLibrary("NitroMmkv")
26
+ Log.i(TAG, "Successfully loaded NitroMmkv C++ library!")
27
+ didLoad = true
28
+ } catch (e: Error) {
29
+ Log.e(TAG, "Failed to load NitroMmkv C++ library! Is it properly installed and linked? " +
30
+ "Is the name correct? (see `CMakeLists.txt`, at `add_library(...)`)", e)
31
+ throw e
32
+ }
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,60 @@
1
+ #
2
+ # NitroMmkv+autolinking.rb
3
+ # This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ # https://github.com/mrousavy/nitro
5
+ # Copyright © 2025 Marc Rousavy @ Margelo
6
+ #
7
+
8
+ # This is a Ruby script that adds all files generated by Nitrogen
9
+ # to the given podspec.
10
+ #
11
+ # To use it, add this to your .podspec:
12
+ # ```ruby
13
+ # Pod::Spec.new do |spec|
14
+ # # ...
15
+ #
16
+ # # Add all files generated by Nitrogen
17
+ # load 'nitrogen/generated/ios/NitroMmkv+autolinking.rb'
18
+ # add_nitrogen_files(spec)
19
+ # end
20
+ # ```
21
+
22
+ def add_nitrogen_files(spec)
23
+ Pod::UI.puts "[NitroModules] 🔥 NitroMmkv is boosted by nitro!"
24
+
25
+ spec.dependency "NitroModules"
26
+
27
+ current_source_files = Array(spec.attributes_hash['source_files'])
28
+ spec.source_files = current_source_files + [
29
+ # Generated cross-platform specs
30
+ "nitrogen/generated/shared/**/*.{h,hpp,c,cpp,swift}",
31
+ # Generated bridges for the cross-platform specs
32
+ "nitrogen/generated/ios/**/*.{h,hpp,c,cpp,mm,swift}",
33
+ ]
34
+
35
+ current_public_header_files = Array(spec.attributes_hash['public_header_files'])
36
+ spec.public_header_files = current_public_header_files + [
37
+ # Generated specs
38
+ "nitrogen/generated/shared/**/*.{h,hpp}",
39
+ # Swift to C++ bridging helpers
40
+ "nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Bridge.hpp"
41
+ ]
42
+
43
+ current_private_header_files = Array(spec.attributes_hash['private_header_files'])
44
+ spec.private_header_files = current_private_header_files + [
45
+ # iOS specific specs
46
+ "nitrogen/generated/ios/c++/**/*.{h,hpp}",
47
+ # Views are framework-specific and should be private
48
+ "nitrogen/generated/shared/**/views/**/*"
49
+ ]
50
+
51
+ current_pod_target_xcconfig = spec.attributes_hash['pod_target_xcconfig'] || {}
52
+ spec.pod_target_xcconfig = current_pod_target_xcconfig.merge({
53
+ # Use C++ 20
54
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
55
+ # Enables C++ <-> Swift interop (by default it's only C)
56
+ "SWIFT_OBJC_INTEROP_MODE" => "objcxx",
57
+ # Enables stricter modular headers
58
+ "DEFINES_MODULE" => "YES",
59
+ })
60
+ end
@@ -0,0 +1,32 @@
1
+ ///
2
+ /// NitroMmkv-Swift-Cxx-Bridge.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "NitroMmkv-Swift-Cxx-Bridge.hpp"
9
+
10
+ // Include C++ implementation defined types
11
+ #include "HybridMMKVPlatformContextSpecSwift.hpp"
12
+ #include "NitroMmkv-Swift-Cxx-Umbrella.hpp"
13
+
14
+ namespace margelo::nitro::mmkv::bridge::swift {
15
+
16
+ // pragma MARK: std::shared_ptr<HybridMMKVPlatformContextSpec>
17
+ std::shared_ptr<HybridMMKVPlatformContextSpec> create_std__shared_ptr_HybridMMKVPlatformContextSpec_(void* _Nonnull swiftUnsafePointer) noexcept {
18
+ NitroMmkv::HybridMMKVPlatformContextSpec_cxx swiftPart = NitroMmkv::HybridMMKVPlatformContextSpec_cxx::fromUnsafe(swiftUnsafePointer);
19
+ return std::make_shared<margelo::nitro::mmkv::HybridMMKVPlatformContextSpecSwift>(swiftPart);
20
+ }
21
+ void* _Nonnull get_std__shared_ptr_HybridMMKVPlatformContextSpec_(std__shared_ptr_HybridMMKVPlatformContextSpec_ cppType) noexcept {
22
+ std::shared_ptr<margelo::nitro::mmkv::HybridMMKVPlatformContextSpecSwift> swiftWrapper = std::dynamic_pointer_cast<margelo::nitro::mmkv::HybridMMKVPlatformContextSpecSwift>(cppType);
23
+ #ifdef NITRO_DEBUG
24
+ if (swiftWrapper == nullptr) [[unlikely]] {
25
+ throw std::runtime_error("Class \"HybridMMKVPlatformContextSpec\" is not implemented in Swift!");
26
+ }
27
+ #endif
28
+ NitroMmkv::HybridMMKVPlatformContextSpec_cxx& swiftPart = swiftWrapper->getSwiftPart();
29
+ return swiftPart.toUnsafe();
30
+ }
31
+
32
+ } // namespace margelo::nitro::mmkv::bridge::swift