Automattic / Gravatar-SDK-iOS

Gravatar SDK is a Swift library that allows you to integrate Gravatar features into your own iOS applications.
https://gravatar.com
Mozilla Public License 2.0
36 stars 1 forks source link

Fix the issue about `@Environment` var being accessed from outside a View #340

Closed pinarol closed 1 month ago

pinarol commented 1 month ago

Closes #

Description

Fixes the issue:

Accessing Environment's value outside of being installed on a View. This will always read the default value and will not update.

So we shouldn't use @Environment var inside a non-View struct. We need to find a way to listen to color scheme changes and then re-render AvatarPickerProfileView so it updates its colors. I am not sure if this is the best solution so let's discuss other ideas if you have any.

Testing Steps

Check AvatarPickerProfileView previews "Empty", "Empty & Loading" in both light & dark appearance. Observe: Colors are adapting.

Run the SwiftUI demo app and open the avatar picker. Observe: The above warning has disappeared. ☝️

pinarol commented 1 month ago

Yeah I have the same feeling. 👍