Skip to content
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

[iOS] - Change AboutHomeHandler to use a proper background colour format (uplift to 1.77.x) #27872

Merged
merged 1 commit into from
Feb 28, 2025
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
1 change: 1 addition & 0 deletions ios/brave-ios/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ var braveTarget: PackageDescription.Target = .target(
],
resources: [
.copy("Assets/About/Licenses.html"),
.copy("Assets/About/AboutHome.html"),
.copy("Assets/__firefox__.js"),
.copy("Assets/AllFramesAtDocumentEnd.js"),
.copy("Assets/AllFramesAtDocumentEndSandboxed.js"),
Expand Down
27 changes: 27 additions & 0 deletions ios/brave-ios/Sources/Brave/Assets/About/AboutHome.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>About Home</title>
<style>
body {
transition: background-color 0.1s, color 0.1s;
}

.theme {
color: black;
background-color: #LIGHT_MODE_COLOUR;
}

@media (prefers-color-scheme: dark) {
.theme {
color: white;
background-color: #DARK_MODE_COLOUR;
}
}
</style>
</head>
<body class="theme">
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@ public class AboutHomeHandler: InternalSchemeResponse {
public func response(forRequest request: URLRequest) async -> (URLResponse, Data)? {
guard let url = request.url else { return nil }
let response = InternalSchemeHandler.response(forUrl: url)
let bg = UIColor.braveBackground.toHexString()

let lightModeColour = UIColor(braveSystemName: .containerBackground).resolvedColor(
with: .init(userInterfaceStyle: .light)
).toHexString()
let darkModeColour = UIColor(braveSystemName: .containerBackground).resolvedColor(
with: .init(userInterfaceStyle: .dark)
).toHexString()

// Blank page with a color matching the background of the panels which is displayed for a split-second until the panel shows.
let html = """
<!DOCTYPE html>
<html>
<body style='background-color:\(bg)'></body>
</html>
"""
guard let asset = Bundle.module.url(forResource: "AboutHome", withExtension: "html"),
var html = await AsyncFileManager.default.utf8Contents(at: asset)
else {
return nil
}

html = html.replacingOccurrences(of: "LIGHT_MODE_COLOUR", with: lightModeColour)
.replacingOccurrences(of: "DARK_MODE_COLOUR", with: darkModeColour)

let data = Data(html.utf8)
return (response, data)
}
Expand Down
Loading