Skip to content

Dark Mode support in HTMLTextView #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions Sources/ArcGISToolkit/Components/Popups/HTMLTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,34 @@ struct HTMLTextView: UIViewRepresentable {
word-wrap:break-word; font-family:-apple-system; font:-apple-system-subheadline;
}
body {
margin:10px; padding:0px;
margin: 10px;
padding:0px;
background: var(--body-bg);
color: var(--body-color);
}
img {
max-width: 100%;
}
a {
color: var(--link-color);
}
</style>
<style type="text/css" media="screen">
/* Light mode */
:root {
--body-bg: #FFFFFF00;
--body-color: #000000;
--link-color: #0164C8;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
:root {
--body-bg: #00000000;
--body-color: #FFFFFF;
--link-color: #1796FA;
}
}
</style>
</head>
<body>
Expand Down Expand Up @@ -82,8 +105,8 @@ struct HTMLTextView: UIViewRepresentable {
// regardless of light/dark mode. If the user wants to implement dark
// mode, within their HTML, the background of the HTML will be shown
// over this background.
uiView.backgroundColor = .white
uiView.scrollView.backgroundColor = .white
uiView.backgroundColor = .clear
uiView.scrollView.backgroundColor = .clear
uiView.scrollView.isScrollEnabled = false
uiView.loadHTMLString(displayHTML, baseURL: nil)
uiView.navigationDelegate = context.coordinator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,13 @@ struct TextPopupElementView: View {

var body: some View {
if !popupElement.text.isEmpty {
let roundedRect = RoundedRectangle(cornerRadius: 8)
ZStack {
HTMLTextView(html: popupElement.text, height: $webViewHeight)
.clipShape(roundedRect)
.frame(height: webViewHeight)
if webViewHeight == .zero {
// Show `ProgressView` until `HTMLTextView` has set the height.
ProgressView()
}
else {
roundedRect
.stroke(Color.black, lineWidth: 1)
}
}
Divider()
}
Expand Down