patterns #79
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { type PropsWithChildren, useState } from "react";
|
import React, { type PropsWithChildren } from "react";
|
||||||
import { Pressable, StyleSheet, View } from "react-native";
|
import { Pressable, StyleSheet, View } from "react-native";
|
||||||
import { SafeAreaView } from "react-native-safe-area-context";
|
import { SafeAreaView } from "react-native-safe-area-context";
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
import { Ionicons } from "@expo/vector-icons";
|
||||||
|
|
@ -12,10 +12,10 @@ interface DetailPageShellProps extends PropsWithChildren {
|
||||||
title: string;
|
title: string;
|
||||||
subtitle?: string;
|
subtitle?: string;
|
||||||
onBack?: () => void;
|
onBack?: () => void;
|
||||||
|
rightAction?: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function DetailPageShell({ children, onBack }: DetailPageShellProps) {
|
export function DetailPageShell({ children, onBack, rightAction }: DetailPageShellProps) {
|
||||||
const [isFavorite, setIsFavorite] = useState(false);
|
|
||||||
const { moduleCode } = useLocalSearchParams<{ moduleCode?: string }>();
|
const { moduleCode } = useLocalSearchParams<{ moduleCode?: string }>();
|
||||||
const currentModuleCode = typeof moduleCode === "string" ? moduleCode : "";
|
const currentModuleCode = typeof moduleCode === "string" ? moduleCode : "";
|
||||||
const moduleDisplay = useModuleDisplayName(currentModuleCode);
|
const moduleDisplay = useModuleDisplayName(currentModuleCode);
|
||||||
|
|
@ -34,21 +34,12 @@ export function DetailPageShell({ children, onBack }: DetailPageShellProps) {
|
||||||
</Pressable>
|
</Pressable>
|
||||||
) : null;
|
) : null;
|
||||||
|
|
||||||
const favoriteAction = (
|
const headerActions = searchAction || rightAction ? (
|
||||||
<Pressable
|
<View style={styles.actions}>
|
||||||
accessibilityRole="button"
|
{searchAction}
|
||||||
accessibilityLabel={isFavorite ? "Remove from favorites" : "Add to favorites"}
|
{rightAction}
|
||||||
hitSlop={10}
|
</View>
|
||||||
onPress={() => setIsFavorite((value) => !value)}
|
) : undefined;
|
||||||
style={({ pressed }) => [styles.iconButton, pressed && styles.pressed]}
|
|
||||||
>
|
|
||||||
<Ionicons
|
|
||||||
name={isFavorite ? "heart" : "heart-outline"}
|
|
||||||
size={22}
|
|
||||||
color={isFavorite ? Colors.error : Colors.textPrimary}
|
|
||||||
/>
|
|
||||||
</Pressable>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView style={styles.screen} edges={["top", "left", "right"]}>
|
<SafeAreaView style={styles.screen} edges={["top", "left", "right"]}>
|
||||||
|
|
@ -64,12 +55,7 @@ export function DetailPageShell({ children, onBack }: DetailPageShellProps) {
|
||||||
currentModuleCode ? `Open ${moduleDisplay.name} home` : moduleDisplay.name
|
currentModuleCode ? `Open ${moduleDisplay.name} home` : moduleDisplay.name
|
||||||
}
|
}
|
||||||
fallbackRoute={moduleDisplay.homeRoute}
|
fallbackRoute={moduleDisplay.homeRoute}
|
||||||
right={
|
right={headerActions}
|
||||||
<View style={styles.actions}>
|
|
||||||
{searchAction}
|
|
||||||
{favoriteAction}
|
|
||||||
</View>
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
<View style={styles.body}>{children}</View>
|
<View style={styles.body}>{children}</View>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue