Skip to content

Commit

Permalink
fix: style
Browse files Browse the repository at this point in the history
  • Loading branch information
hyoban committed Aug 16, 2024
1 parent 07ccc66 commit 99e14fc
Showing 1 changed file with 31 additions and 34 deletions.
65 changes: 31 additions & 34 deletions components/feed-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@ export function FeedContent({ html }: { html: string }) {
const [height, setHeight] = useState<DimensionValue>('auto')
const { theme } = useStyles()

if (!html) {
return <ActivityIndicator />
if (!html || height === 'auto') {
return <ActivityIndicator style={{ marginVertical: 10 }} />
}

return (
<>
{height === 'auto' && <ActivityIndicator />}
<WebView
scrollEnabled={false}
style={{
height,
display: height ? 'flex' : 'none',
}}
originWhitelist={['*']}
injectedJavaScript={`
<WebView
scrollEnabled={false}
style={{
height,
display: height ? 'flex' : 'none',
}}
originWhitelist={['*']}
injectedJavaScript={`
// prevent links from opening in the webview
document.addEventListener('click', function(e) {
if (e.target.tagName === 'A') {
Expand All @@ -44,25 +42,25 @@ export function FeedContent({ html }: { html: string }) {
}
}, 1000)
`}
onMessage={(e) => {
let message: any = e.nativeEvent.data
try {
message = JSON.parse(message)
}
catch {
return
}
if ('object' == typeof message && message.external_url_open) {
openExternalUrl(message.external_url_open)
.catch(console.error)
}
else if ('object' == typeof message && message.height) {
setHeight(message.height)
}
}}
source={{
baseUrl: '',
html: `
onMessage={(e) => {
let message: any = e.nativeEvent.data
try {
message = JSON.parse(message)
}
catch {
return
}
if ('object' == typeof message && message.external_url_open) {
openExternalUrl(message.external_url_open)
.catch(console.error)
}
else if ('object' == typeof message && message.height) {
setHeight(message.height)
}
}}
source={{
baseUrl: '',
html: `
<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -81,8 +79,7 @@ export function FeedContent({ html }: { html: string }) {
</body>
</html>
`,
}}
/>
</>
}}
/>
)
}

0 comments on commit 99e14fc

Please sign in to comment.