import { useCallback, useState } from "react"
import {
View,
Text,
ScrollView,
TouchableOpacity,
Switch,
StyleSheet,
useColorScheme,
Linking,
Alert,
} from "react-native"
import { Ionicons } from "@expo/vector-icons"
import { useAuth } from "../../src/stores/auth"
import { useSettings } from "../../src/stores/settings"
import {
categories,
categoryMeta,
setup as setupNotifications,
granted as notificationsGranted,
} from "../../src/lib/notifications"
import type { Category } from "../../src/lib/notifications"
function SettingRow({
icon,
label,
description,
isDark,
right,
onPress,
}: {
icon: keyof typeof Ionicons.glyphMap
label: string
description?: string
isDark: boolean
right?: React.ReactNode
onPress?: () => void
}) {
const content = (
{label}
{description && {description}}
{right}
)
if (onPress) {
return {content}
}
return content
}
function SettingSection({ title, children, isDark }: { title: string; children: React.ReactNode; isDark: boolean }) {
return (
{title}
{children}
)
}
export default function SettingsScreen() {
const colorScheme = useColorScheme()
const isDark = colorScheme === "dark"
const { settings, hasBiometrics, updateSettings, lock } = useAuth()
const { notifications, setNotification } = useSettings()
const [osGranted, setOsGranted] = useState(null)
// Check OS permission state on first toggle attempt
const handleToggle = useCallback(
async (category: Category, enabled: boolean) => {
if (enabled) {
const ok = await setupNotifications()
setOsGranted(ok)
if (!ok) {
Alert.alert(
"Notifications Disabled",
"Enable notifications for OpenCode in your device settings to receive alerts.",
)
return
}
}
setNotification(category, enabled)
},
[setNotification],
)
// Lazy-check OS permission for status display
if (osGranted === null) {
notificationsGranted().then(setOsGranted)
}
return (
updateSettings({ requireBiometric: value })}
disabled={!hasBiometrics}
trackColor={{ false: "#767577", true: "#22c55e" }}
/>
}
/>
updateSettings({ requireBiometricForMessages: value })}
disabled={!hasBiometrics || !settings.requireBiometric}
trackColor={{ false: "#767577", true: "#22c55e" }}
/>
}
/>
{settings.requireBiometric && (
}
/>
)}
{categories.map((category) => {
const meta = categoryMeta[category]
return (
handleToggle(category, value)}
trackColor={{ false: "#767577", true: "#22c55e" }}
/>
}
/>
)
})}
{osGranted === false && (
Notifications are disabled at the system level. Enable them in Settings to receive alerts.
)}
Linking.openURL("https://github.com/anomalyco/opencode")}
right={}
/>
Linking.openURL("https://opencode.ai/docs")}
right={}
/>
OpenCode Mobile
Connect to your AI coding assistant from anywhere
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#f5f5f5",
},
containerDark: {
backgroundColor: "#0a0a0a",
},
content: {
paddingBottom: 32,
},
section: {
marginTop: 24,
},
sectionTitle: {
fontSize: 13,
fontWeight: "600",
color: "#666666",
marginLeft: 16,
marginBottom: 8,
textTransform: "uppercase",
},
sectionTitleDark: {
color: "#888888",
},
sectionContent: {
backgroundColor: "#ffffff",
borderTopWidth: 1,
borderBottomWidth: 1,
borderColor: "#e5e5e5",
},
sectionContentDark: {
backgroundColor: "#1a1a1a",
borderColor: "#2a2a2a",
},
settingRow: {
flexDirection: "row",
alignItems: "center",
paddingVertical: 12,
paddingHorizontal: 16,
borderBottomWidth: 1,
borderBottomColor: "#e5e5e5",
},
settingRowDark: {
borderBottomColor: "#2a2a2a",
},
settingIcon: {
width: 36,
height: 36,
borderRadius: 8,
backgroundColor: "#f5f5f5",
justifyContent: "center",
alignItems: "center",
marginRight: 12,
},
settingIconDark: {
backgroundColor: "#2a2a2a",
},
settingContent: {
flex: 1,
},
settingLabel: {
fontSize: 16,
color: "#0a0a0a",
},
textDark: {
color: "#ffffff",
},
settingDescription: {
fontSize: 13,
color: "#666666",
marginTop: 2,
},
metaDark: {
color: "#888888",
},
footer: {
alignItems: "center",
padding: 32,
},
footerText: {
fontSize: 13,
color: "#999999",
textAlign: "center",
},
})