onmyway133 / EasyTheme

👕👚 Theme management in Swift
https://onmyway133.com
Other
242 stars 19 forks source link

A way to restore a previously selected theme. #3

Open multinerd opened 7 years ago

multinerd commented 7 years ago

Lets say a user selects a dark theme. When the user exits the app and relaunches, the theme resets to whatever is in code.

Would be nice if the user's preference was persistence without the need for further implementations. I believe Themeable does this and would make a great feature.

onmyway133 commented 7 years ago

@multinerd Hi, thanks for your suggestion. It is as easy as persisting the theme name to UserDefaults. I can do that 👍

onmyway133 commented 7 years ago

@multinerd actually I would prefer to use Swift 4 Codable to persist theme, so this will persistence will come together with next version. Hope you understand

multinerd commented 7 years ago

Sounds good to me. No rush, I have a work around where I save a bool and set theme based on that.

onmyway133 commented 6 years ago

@multinerd I just updated https://github.com/hyperoslo/Cache to Swift 4 using Codable. It works great. But I don't know if Codable is helpful for Themes, as we have UIImage, UIColor, UIFont, ... It is doable, but saving the whole thing to disk seems heavy. Also, in some apps, the Theme is parsed from json, so it might not be as hardcoded.

One the 2nd thought, I think I just save the name of the current Theme, and give a chance for user to reconfigure Theme based on that name at app launch.

What do you think ?

multinerd commented 6 years ago

I've completely forgot about the ability to load from JSON. For the most part, I've been using your second approach.

I've added a string property called name to the Theme protocol so that every object that conforms to Theme has a name. That gets saved to userdefaults and and on app launch, we parse that value and set the theme.

When i opened this ticket, i was hoping it would be as simple as saving the name and setting it based on some sort of reflection. You would know better than I if that's possible, I'm still a newb coder.