Battery shows lightning bolt and nothing else.
curiousurick opened this issue · comments
Hey! I have a project where I'd like to inject a battery into a widget I'm making for personal use. However, when add the battery, all that is rendered is a lightning bolt.
I created a copy of BatteryDemo because it's not public and I am directly adding that to my view. If I set the battery state to .full or .charging, I see a lightning bolt and when I set to .unplugged, the bolt disappears. When I adjust the width, it adjusts as if it's displaying a whole battery, meaning I see a lot of room around the bolt. It seems the battery is invisible, matching the background color, or something.
Oh, I think some system assets may not be available in widget extensions
Yeah, I also found some things not working in widgets in the past. I didn’t test this library on widgets, though. There are three reasons I could imagine it not working:
- State does not really work in widgets, so the battery is always at default 0%.
- Some SFSymbols not available (I doubt that)
- Some of the image manipulations used by SFSymbolStyle (e.g. masking, color inversion) are disabled in widgets to save power
Could you send a screenshot? That might help me to figure out what part doesn’t work. Maybe I can work around it then.
I suspect that the part not working in WidgetKit is the View.mask(_:)
modifier. The bolt is the only item in SFSymbolStyle
that is not masked in some way. I put together another style called SFSymbolWideStyle
, which does not use of .mask
at all and thus should work even in widgets. You can try it out by setting the Package version to this commit: a800142.
Of course it looks a little different:
Unfortunately I couldn't test it myself because Widgets didn't show up when I installed a test app on my device. Probably a Xcode beta issue.