feat(mobile): add reader inline style rendering option

- Implement dynamic inline style rendering for WebView content
- Create new atom for managing reader inline style preference
- Update EntryContentWebView to support toggling inline style rendering
- Modify HTML renderer to conditionally apply inline styles

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei
2025-02-10 16:39:37 +08:00
parent 70e1de5a27
commit 160eb14258
4 changed files with 22 additions and 8 deletions
@@ -36,17 +36,26 @@ export const setWebViewEntry = (entry: EntryModel) => {
)
}
const setReaderRenderInlineStyle = (value: boolean) => {
SharedWebViewModule.evaluateJavaScript(`setReaderRenderInlineStyle(${value})`)
}
export function EntryContentWebView(props: EntryContentWebViewProps) {
const [contentHeight, setContentHeight] = React.useState(0)
const codeThemeLight = useUISettingKey("codeHighlightThemeLight")
const codeThemeDark = useUISettingKey("codeHighlightThemeDark")
const readerRenderInlineStyle = useUISettingKey("readerRenderInlineStyle")
const { entry } = props
useEffect(() => {
setCodeTheme(codeThemeLight, codeThemeDark)
}, [codeThemeLight, codeThemeDark])
useEffect(() => {
setReaderRenderInlineStyle(readerRenderInlineStyle)
}, [readerRenderInlineStyle])
const [mode, setMode] = React.useState<"normal" | "debug">("normal")
React.useEffect(() => {
setWebViewEntry(entry)
@@ -6,3 +6,4 @@ export const entryAtom = atom<EntryModel | null>(null)
export const codeThemeLightAtom = atom<string | null>(null)
export const codeThemeDarkAtom = atom<string | null>(null)
export const readerRenderInlineStyleAtom = atom<boolean>(false)
+11 -3
View File
@@ -1,6 +1,11 @@
import { createStore, Provider, useAtomValue } from "jotai"
import { codeThemeDarkAtom, codeThemeLightAtom, entryAtom } from "../atoms"
import {
codeThemeDarkAtom,
codeThemeLightAtom,
entryAtom,
readerRenderInlineStyleAtom,
} from "../atoms"
import type { EntryModel } from "../types"
import { HTML } from "./HTML"
@@ -15,6 +20,9 @@ Object.assign(window, {
store.set(codeThemeLightAtom, light)
store.set(codeThemeDarkAtom, dark)
},
setReaderRenderInlineStyle(value: boolean) {
store.set(readerRenderInlineStyleAtom, value)
},
reset() {
store.set(entryAtom, null)
bridge.measure()
@@ -23,10 +31,10 @@ Object.assign(window, {
export const App = () => {
const entry = useAtomValue(entryAtom, { store })
const readerRenderInlineStyle = useAtomValue(readerRenderInlineStyleAtom, { store })
return (
<Provider store={store}>
<HTML children={entry?.content} />
<HTML children={entry?.content} renderInlineStyle={readerRenderInlineStyle} />
</Provider>
)
}
@@ -12,11 +12,7 @@ import { ShikiHighLighter } from "./components/shiki"
const Style: Components["style"] = ({ node, ...props }) => {
if (typeof props.children === "string") {
return createElement(
MemoedDangerousHTMLStyle,
null,
props.children.replaceAll(/html|body/g, "#shadow-html"),
)
return createElement(MemoedDangerousHTMLStyle, null, props.children)
}
return null
}