kuatsu / react-native-cloud-storage

☁️ Save to & read from iCloud and Google Drive using React Native
https://react-native-cloud-storage.oss.kuatsu.de/docs/intro
MIT License
128 stars 9 forks source link

Understanding where react-native-cloud-storage fits into my ecosystem #37

Closed AdamGerthel closed 4 days ago

AdamGerthel commented 6 days ago

I'm currently looking at replacing RealmDB (due to its upcoming deprecation) in our React Native-based games. Our games don't really need a database (no querying needs really), just an offline first storage solution for JSON data.

Currently, we only support iOS and Android, and only offline, but it's likely that we'll make an effort to create an Electron app in order to be able to port our games to desktop in order to release on Steam - in which case we'll need web support as well.

In short: I currently only need local offline first support for storing data in iOS+Android, but I want to be able to implement web support as well as some kind of cloud sync in the future, so I'm trying to find a solution that I don't have to replace entirely when that time comes.

Now - to my questions!

What I'm wondering first is, does react-native-cloud-storage provide any kind of filesystem access on the local device, or is it purely used to read/write to the cloud services? I.e. am I expected to use something like expo-filesystem for offline first support, and sync files to the cloud in the background?

Second - the readme mentions web support - but what exactly does that mean, considering there's no file system available in the browser?

PS. Your library is looking really nice! 👏

mfkrause commented 6 days ago

What I'm wondering first is, does react-native-cloud-storage provide any kind of filesystem access on the local device, or is it purely used to read/write to the cloud services? I.e. am I expected to use something like expo-filesystem for offline first support, and sync files to the cloud in the background?

Yes, react-native-cloud-storage is only used for cloud storage access. To read and write from the local filesystem, you'd need to use a different solution. The library is designed based on the principle of separation of concerns. This means that we focus on cloud storage only. Other than not being able to read from the local filesystem, this also means that you need to gather an authentication token for Google Drive from some other place (i.e. @react-native-google-signin/google-signin). Focusing on cloud storage access only, we can better guarantee long-term maintainability.

For iCloud, files that are currently synced to the device can theoretically also be read when offline. However, you do not have granular configuration access as to which files are synced for how long, that's up to the OS. Therefore, you need to expect that a file needs to be loaded from the cloud first and the user needs to be connected to the Internet when working with the library. For Google Drive, you need to load the files from the cloud every time you want to access them anyway, since Google Drive is implemented using their REST API.

Second - the readme mentions web support - but what exactly does that mean, considering there's no file system available in the browser?

Web support is given via the Google Drive implementation (again, since this one's implemented through the REST API, any platform can deal with this). Previously in react-native-cloud-storage v1, using iCloud on iOS and Google Drive on all other platforms (including Android and Web) was the non-overridable default. In v2, we made this a little more modular, which currently allows you to use Google Drive on all platforms including iOS. In the future, we might expand upon this with more cloud providers, albeit their are no concrete plans yet.