react-native-async-storage / async-storage

An asynchronous, persistent, key-value storage system for React Native.
https://react-native-async-storage.github.io/async-storage/
MIT License
4.61k stars 458 forks source link

[windows] Add ReactPropertyBag option for DB path initialization #1087

Closed rozele closed 2 days ago

rozele commented 2 months ago

Summary

WinAppSDK apps do not support the current methods for setting / retrieving the DB path for the default storage in @react-native-async-storage/async-storage. Specifically, winrt::CoreApplication::Properties() causes a crashes on WinAppSDK.

To work around this, this change adds a specific namespaced key (ReactNativeAsyncStorage.Path) to the ReactPropertyBag for apps to register the overridden DB path for WinAppSDK apps (or apps that otherwise cannot use winrt::CoreApplication::Properties()).

Test Plan

Compiled with WinAppSDK build of react-native-windows, set ReactNativeAsyncStorage.Path on the ReactPropertyBag for InstanceSettings when initializing the react-native-windows ReactHost, and confirmed the sqlite DB is written to the correct location.

acoates-ms commented 2 months ago

One thing I'd consider is exposing a function to set the Property rather than relying on magic strings.

ReactNativeAsyncStorage::SetDatabasePath(propertyBag, path)

Ideally that would be exposed in the idl file as a public method. -- I dont know how strict the current API is about ensuring that all public APIs are part of the idl interface.

rozele commented 2 months ago

Looks like something happened to the line endings, creating a huge diff. Will need to redo this commit.

github-actions[bot] commented 1 week ago

This PR has been marked as stale due to inactivity. Please address any comments within 7 days or it will be closed.