Try to make dark-mode working with widgets (IOS-152)
plot twist: it doesn't :/
This commit is contained in:
parent
2c1ae0dc61
commit
e87b06efe4
|
@ -8,11 +8,12 @@ struct HashtagWidgetView: View {
|
||||||
var entry: HashtagWidgetProvider.Entry
|
var entry: HashtagWidgetProvider.Entry
|
||||||
|
|
||||||
@Environment(\.widgetFamily) var family
|
@Environment(\.widgetFamily) var family
|
||||||
|
@Environment(\.colorScheme) var colorScheme
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
switch family {
|
switch family {
|
||||||
case .systemMedium, .systemLarge:
|
case .systemMedium, .systemLarge:
|
||||||
viewForMediumWidget()
|
viewForMediumWidget(colorScheme: colorScheme)
|
||||||
case .accessoryRectangular:
|
case .accessoryRectangular:
|
||||||
viewForRectangularAccessory()
|
viewForRectangularAccessory()
|
||||||
default:
|
default:
|
||||||
|
@ -20,7 +21,7 @@ struct HashtagWidgetView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func viewForMediumWidget() -> some View {
|
private func viewForMediumWidget(colorScheme: ColorScheme) -> some View {
|
||||||
VStack(alignment: .leading, spacing: 0) {
|
VStack(alignment: .leading, spacing: 0) {
|
||||||
HStack {
|
HStack {
|
||||||
Text(entry.hashtag.accountName)
|
Text(entry.hashtag.accountName)
|
||||||
|
@ -37,7 +38,7 @@ struct HashtagWidgetView: View {
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
}
|
}
|
||||||
|
|
||||||
Text(statusHTML: entry.hashtag.content)
|
Text(statusHTML: entry.hashtag.content, colorScheme: colorScheme)
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
HStack(alignment: .center, spacing: 16) {
|
HStack(alignment: .center, spacing: 16) {
|
||||||
|
@ -81,7 +82,6 @@ struct HashtagWidgetView: View {
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
}
|
}
|
||||||
Text(statusHTML: entry.hashtag.content, fontSize: 11, fontWeight: 510)
|
Text(statusHTML: entry.hashtag.content, fontSize: 11, fontWeight: 510)
|
||||||
.foregroundColor(.primary)
|
|
||||||
.lineLimit(3)
|
.lineLimit(3)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,11 @@ struct HashtagWidgetView: View {
|
||||||
|
|
||||||
/// Inspired by: https://swiftuirecipes.com/blog/swiftui-text-with-html-via-nsattributedstring
|
/// Inspired by: https://swiftuirecipes.com/blog/swiftui-text-with-html-via-nsattributedstring
|
||||||
extension Text {
|
extension Text {
|
||||||
init(statusHTML htmlString: String, fontSize: Int = 16, fontWeight: Int = 400) {
|
init(statusHTML htmlString: String, fontSize: Int = 16, fontWeight: Int = 400, colorScheme: ColorScheme = .light) {
|
||||||
|
|
||||||
|
let textColor = (colorScheme == .light) ? "#000000" : "#FFFFFF"
|
||||||
|
let accentColor = (colorScheme == .light) ? "#563ACC" : "#858AFA"
|
||||||
|
|
||||||
let fullHTML = """
|
let fullHTML = """
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html>
|
<html>
|
||||||
|
@ -100,15 +104,11 @@ extension Text {
|
||||||
font-size: \(fontSize)px;
|
font-size: \(fontSize)px;
|
||||||
font-weight: \(fontWeight);
|
font-weight: \(fontWeight);
|
||||||
line-height: 133%;
|
line-height: 133%;
|
||||||
|
color: \(textColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
color: #563ACC;
|
color: \(accentColor);
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
a {
|
|
||||||
color: ##858AFA
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in New Issue