Closed josephyanks closed 6 days ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
rnmmkv | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Jan 19, 2024 5:45pm |
@ammarahm-ed wondering what steps we can take to get this merged, otherwise we're going to probably have to patch our version locally.
Let me know if there's anything I can do to move this forward.
@josephyanks how to use that on iOS?
@josephyanks how to use that on iOS?
These are bindings specifically for android. For iOS (will verify at a later point) it seems like there isn't the need for an equivalent layer (due to no JNI bindings required) and I believe that you can just use the C++ MMKV libraries directly.
@josephyanks will give it another try...
@sidferreira hey. I don't know if you figured out the iOS part yet, but here's the example how you could do it. Just a little disclaimer, if you're using RN-MMKV from the box, this solution should work fine. But if not, you'll have to figure our all things related to path and mapID to initialize it properly.
Here's how could you access your RN MMKV storage from Swift:
import MMKV
func getStorage() -> MMKV? {
let paths = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)
guard let first = paths.first else { return nil }
let path = (first as NSString).appendingPathComponent("mmkv")
MMKV.initialize(rootDir: path as String)
return MMKV.init(mmapID: "default")
}
let storage = getStorage()
let keys: [Any] = storage?.allKeys()
let stringKeys: [String] = storage?.allKeys().compactMap { $0 as? String }
// example of accessing values of different kinds
let myString: String? = storage?.string(forKey: "my_key_string")
let myBool: Bool? = storage?.bool(forKey: "my_key_bool")
let myDouble: Double? = storage?.double(forKey: "my_key_double")
@AntonGolikov do you have a similar snippet for Android? I hard a hard time making it work...
@sidferreira
You should pull the latest changes (I had to fix a build issue), but the code from the PR description up top should work.
@sidferreira
You should pull the latest changes (I had to fix a build issue), but the code from the PR description up top should work.
oh, this works only within this PR?
@sidferreira You should pull the latest changes (I had to fix a build issue), but the code from the PR description up top should work.
oh, this works only within this PR?
From @AntonGolikov's post:
if you're using RN-MMKV from the box, this solution should work fine.
Pinging @ammarahm-ed to see if there's something we can do to get this merged in.
Thanks for these much needed changes. Looks good!
Adds
getAllKeys
anddecodeString
,decodeDouble
, andencode
methods for Int, Double, and String to android to allow reading more values from android native code.Relates to #217
If you want to access MMKV before RN is initialized from the android native code, you will need to call load earlier.
Example of new method usage: