Solution for ENG-3935.
This diff introduces a wrapper for React Native alerts, which synchronizes currently selected theme in the app with alert style. Right now userInterfaceStyle is only supported on iOS.
Light theme alert:
Dark theme alert:
Differential D8586
[native] Use currently selected theme for alerts. • patryk on Jul 20 2023, 6:03 AM. Authored by Tags None Referenced Files
Details Solution for ENG-3935. This diff introduces a wrapper for React Native alerts, which synchronizes currently selected theme in the app with alert style. Right now userInterfaceStyle is only supported on iOS. Light theme alert: Dark theme alert:
Diff Detail
Event Timeline
Comment Actions [deleted] My bad, turns out if you don't reload the app manually those changes don't take effect for some reason
Comment Actions I don't like the solution with hardcoding argument positions, but I tried to figure out a clearly better way, and couldn't find one. There are many that are about equally bad in my opinion. But I would prefer if @tomek or someone else could take look as well. Comment Actions Is there a diff where we start using this instead of the default Alert?
Agree that this isn't ideal. Wondering how type-safe this solution is. Also, not sure if accessing state directly won't cause any issues (e.g. if we store Alert.alert in a variable, would it update after state change?). How about creating a custom hook, e.g. useAlert() that returns { alert, prompt } that have the same signatures as the original ones, but have userInterfaceStyle hardcoded? In this hook we can useSelector so that the functions get updated after state change.
Comment Actions
Creating a custom hook is not a viable option. Consider dev-menu.js as an example. There are instances where we use Alert outside of a React component.
I've tried storing Alert.alert in a variable and didn't notice any problems. We could potentially use a method like store.subscribe to update the variable when the state changes. However, after reviewing the example in the documentation, it seems this might not be necessary -- we would still use the store.getState() method. Also using store.subscribe would be inefficient, because we would update the variable even when we don't use alert. I'm going to refactor the code: rather than focusing on creating the "generic code", we should focus on being type-safe (e.g. when alert arguments change, flow should throw an error).
|