Skip to content

Commit

Permalink
hook up browser setting to detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
jcosentino11 committed Sep 2, 2024
1 parent d58b9e1 commit 59a0871
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions app/detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Feather } from '@expo/vector-icons';
import FontAwesome from '@expo/vector-icons/FontAwesome';
import Header from '@/components/Header';
import { LoginContext } from '@/components/LoginProvider';
import { SettingsContext } from '@/components/SettingsProvider';

const darkReaderScript = `
(function() {
Expand All @@ -30,6 +31,7 @@ export default function HackerNewsPageDetail() {
// TODO load favorite based on login
const [isFavorited, setIsFavorited] = useState(false);

const settingsContext = useContext(SettingsContext);
const webViewRef = useRef(null);

const searchParamAsString: ((param: string | string[]) => string | undefined) =
Expand Down Expand Up @@ -71,6 +73,36 @@ export default function HackerNewsPageDetail() {

const injectedJavaScript = isDarkMode ? darkReaderScript : '';

const renderContent = () => {
if (settingsContext.selectedBrowser == 'In App') {
const urlStr = searchParamAsString(url);
if (urlStr) {
return (
<View style={styles.webViewContainer}>
<WebView
ref={webViewRef}
source={{ uri: urlStr }}
style={styles.webview}
injectedJavaScript={injectedJavaScript}
onMessage={() => {}}
mediaPlaybackRequiresUserAction={true}
allowsInlineMediaPlayback={true}
allowsFullscreenVideo={false}
javaScriptCanOpenWindowsAutomatically={false}
/>
</View>
);
}
}
if (settingsContext.selectedBrowser == 'Default') {
// TODO
return (
null
);
}
return (null);
};

return (
<SafeAreaView style={[styles.container, { backgroundColor: backgroundColor }]}>
<StatusBar barStyle={isDarkMode ? "light-content" : "dark-content"} />
Expand All @@ -85,21 +117,7 @@ export default function HackerNewsPageDetail() {
title: searchParamAsString(title),
}}
/>
<View style={styles.webViewContainer}>
{ searchParamAsString(url) &&
<WebView
ref={webViewRef}
source={{ uri: url }}
style={styles.webview}
injectedJavaScript={injectedJavaScript}
onMessage={() => {}}
mediaPlaybackRequiresUserAction={true}
allowsInlineMediaPlayback={true}
allowsFullscreenVideo={false}
javaScriptCanOpenWindowsAutomatically={false}
/>
}
</View>
{renderContent()}
<View style={styles.footer}>
<TouchableOpacity onPress={toggleFavorite} style={styles.footerButton}>
{isFavorited ?
Expand Down

0 comments on commit 59a0871

Please sign in to comment.