Skip to content

Conversation

@graycreate
Copy link
Member

Summary

  • Fix Toast shadow being too dark
  • Fix Toast not clearing issue when appearing consecutively
  • Add automatic dark mode support for V2EX pages in InAppBrowser

Changes

Toast Improvements

  • Reduce shadow opacity from 0.3 to 0.12 for a softer, less aggressive appearance
  • Add version property to track toast updates
  • Reset dismiss timer when new toast content arrives (even if isPresented stays true)

InAppBrowser Dark Mode

  • Inject dark mode CSS for V2EX and v2er.app pages when app is in dark mode
  • Auto-detect app's appearance setting (dark/light/system)
  • Comprehensive styling: boxes, cells, headers, links, code blocks, inputs

Test plan

  • Show multiple toasts in quick succession - verify each one appears and dismisses correctly
  • Verify toast shadow is lighter/softer
  • Enable dark mode in app settings
  • Open a V2EX link in InAppBrowser - verify dark theme is applied
  • Switch to light mode - verify V2EX pages show light theme

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings December 29, 2025 00:18
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the Toast component's visual design and consecutive display handling, while also adding automatic dark mode CSS injection for V2EX pages in the InAppBrowser.

Key Changes:

  • Toast shadow made lighter (opacity 0.3 → 0.12) with improved positioning for a softer appearance
  • Added version tracking to properly reset toast timers when consecutive toasts appear with the same isPresented state
  • Implemented dark mode CSS injection for V2EX and v2er.app domains when the app is in dark mode

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
V2er/View/Widget/Toast.swift Added version property to track toast updates and trigger timer resets; updated shadow for softer appearance
V2er/State/DataFlow/Actions/GlobalActions.swift Increment toast version on each ShowToastAction to ensure onChange handlers detect new toasts
V2er/View/Login/LoginPage.swift Pass toast version to the toast view modifier to enable timer reset functionality
V2er/General/RootView.swift Pass toast version to the toast view modifier to enable timer reset functionality
V2er/View/InAppBrowserView.swift Added dark mode detection and CSS injection for V2EX pages in the InAppBrowser

background-color: #444 !important;
}
"""
let js = "var style = document.createElement('style'); style.innerHTML = `\(darkModeCSS)`; document.head.appendChild(style);"
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CSS string is embedded in a JavaScript template literal using string interpolation. While the current hardcoded CSS is safe, this pattern is fragile—if the CSS string ever contains backticks (`) or template literal expressions (${...}), it could break the JavaScript or create an injection vulnerability. Consider using proper escaping or a safer injection method, such as replacing backticks with escaped backticks in the CSS string before interpolation.

Suggested change
let js = "var style = document.createElement('style'); style.innerHTML = `\(darkModeCSS)`; document.head.appendChild(style);"
let safeDarkModeCSS = darkModeCSS
.replacingOccurrences(of: "\\", with: "\\\\")
.replacingOccurrences(of: "`", with: "\\`")
.replacingOccurrences(of: "${", with: "\\${")
let js = "var style = document.createElement('style'); style.innerHTML = `\(safeDarkModeCSS)`; document.head.appendChild(style);"

Copilot uses AI. Check for mistakes.
background-color: #444 !important;
}
"""
let js = "var style = document.createElement('style'); style.innerHTML = `\(darkModeCSS)`; document.head.appendChild(style);"
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dark mode CSS is injected on every page load completion without checking if it was already injected. This could result in duplicate style tags if a page reloads or navigates within the same webView. Consider checking if the styles are already present or using a unique ID on the style tag to prevent duplicates.

Suggested change
let js = "var style = document.createElement('style'); style.innerHTML = `\(darkModeCSS)`; document.head.appendChild(style);"
let js = """
if (!document.getElementById('v2er-dark-mode-style')) {
var style = document.createElement('style');
style.id = 'v2er-dark-mode-style';
style.innerHTML = `\(darkModeCSS)`;
document.head.appendChild(style);
}
"""

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

Code Coverage Report ❌

Current coverage: 30.24%

Toast improvements:
- Reduce shadow opacity from 0.3 to 0.12 for softer appearance
- Add version tracking to fix consecutive toast not clearing issue
- Reset dismiss timer when new toast content arrives

InAppBrowser improvements:
- Add dark mode CSS injection for V2EX pages when app is in dark mode
- Auto-detect app's appearance setting and apply matching theme
- Comprehensive styling: boxes, cells, tags, links, code blocks, buttons, etc.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@graycreate graycreate force-pushed the bugfix/toast-and-browser-improvements branch from 364282c to de25d0b Compare December 29, 2025 00:35
@github-actions github-actions bot added size/M and removed size/M labels Dec 29, 2025
@github-actions
Copy link

Code Coverage Report ❌

Current coverage: 31.01%

@graycreate graycreate merged commit 6f78e0f into main Dec 29, 2025
6 checks passed
@graycreate graycreate deleted the bugfix/toast-and-browser-improvements branch December 29, 2025 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants