-
-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MultiProcess mode on Android #611
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, thanks for your PR man!
Left some comments
src/MMKV.ts
Outdated
* _Notice_: On iOS, this will automatically be set to MMKVMode.MultiProcess if you set an AppGroup in the plist configuration. | ||
* More information on AppGroups [here](https://github.com/mrousavy/react-native-mmkv/tree/master#app-groups) | ||
*/ | ||
mode?: MMKVMode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please use TypeScript unions instead of enums here?
So instead of mode?: MMKVMode
it would be mode?: 'single-process' | 'multi-process'
README.md
Outdated
@@ -124,6 +125,8 @@ The following values can be configured: | |||
* `id`: The MMKV instance's ID. If you want to use multiple instances, use different IDs. For example, you can separate the global app's storage and a logged-in user's storage. (required if `path` or `encryptionKey` fields are specified, otherwise defaults to: `'mmkv.default'`) | |||
* `path`: The MMKV instance's root path. By default, MMKV stores file inside `$(Documents)/mmkv/`. You can customize MMKV's root directory on MMKV initialization (documentation: [iOS](https://github.com/Tencent/MMKV/wiki/iOS_advance#customize-location) / [Android](https://github.com/Tencent/MMKV/wiki/android_advance#customize-location)) | |||
* `encryptionKey`: The MMKV instance's encryption/decryption key. By default, MMKV stores all key-values in plain text on file, relying on iOS's/Android's sandbox to make sure the file is encrypted. Should you worry about information leaking, you can choose to encrypt MMKV. (documentation: [iOS](https://github.com/Tencent/MMKV/wiki/iOS_advance#encryption) / [Android](https://github.com/Tencent/MMKV/wiki/android_advance#encryption)) | |||
* `mode`: *Android Only*: The MMKV mode. It is set to SingleProcess by default. You can set its value to MultiProcess to support simultaneous read-write access between processus at the cost of performance. This is useful when you want to share data between your react-native app and native extensions such as widgets. _Notice_: On iOS, this will automatically be set to MMKVMode.MultiProcess if you set an AppGroup in the plist configuration (more information on AppGroups [here](https://github.com/mrousavy/react-native-mmkv/tree/master#app-groups)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to also use this prop for iOS? I hate having "android only" or "ios only" props... Maybe we can just reconfigure the instance on iOS when this prop is passed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could however add support for single-process mode with AppGroups but I'm not sure why would anyone want to do that.
This PR adds MultiProcess mode support on Android. iOS already supports this mode using AppGroups.
On android, widgets run in a different processus and this needs to be enabled to share data between native widgets and the main react-native app.