190 lines
6.1 KiB
TypeScript
190 lines
6.1 KiB
TypeScript
import React from "react";
|
|
import { Pressable, StyleSheet, Text, View } from "react-native";
|
|
import { Ionicons } from "@expo/vector-icons";
|
|
import { moderateScale, verticalScale } from "react-native-size-matters";
|
|
|
|
import { Colors } from "@/theme";
|
|
import { asNumber, asString } from "../helpers/value";
|
|
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
|
import type {
|
|
CollectionItemRendererProps,
|
|
CollectionRendererProps,
|
|
} from "../../types/renderer.types";
|
|
|
|
export function EightPrinciplesCollectionRenderer(
|
|
props: CollectionRendererProps,
|
|
) {
|
|
const sortedItems = React.useMemo(() => {
|
|
return [...props.items].sort((a, b) => {
|
|
const orderA = asNumber(a.attributes.sort_order) ?? 999;
|
|
const orderB = asNumber(b.attributes.sort_order) ?? 999;
|
|
return orderA - orderB;
|
|
});
|
|
}, [props.items]);
|
|
|
|
const header = (
|
|
<View style={styles.overviewContainer}>
|
|
<View style={styles.overviewCard}>
|
|
<View style={styles.overviewHeader}>
|
|
<Ionicons name="information-circle" size={20} color={Colors.primary} />
|
|
<Text style={styles.overviewTitle}>Overview</Text>
|
|
</View>
|
|
<Text style={styles.overviewText}>
|
|
The eight principles include exterior, interior, cold, heat, deficiency, excess, yin and yang. Syndrome differentiation (pattern identification) of the eight principles is an essential paradigm in the Chinese medicine system.
|
|
</Text>
|
|
<Text style={styles.overviewParagraph}>
|
|
Pattern identification of the eight principles aims to tell about the disease location, the pathogenic nature and the strength between antipathogenic qi and pathogenic factors, thus generalizing the condition into eight categories.
|
|
</Text>
|
|
<Text style={styles.overviewParagraph}>
|
|
The eight principles can be divided into four pairs: interior/exterior for the depth of pathogens; cold/heat for the disease nature; deficiency/excess for the strength between antipathogenic qi and pathogenic factors; and yin/yang for the preponderance of yin and yang. However, yin and yang can also generalize the other six principles: exterior, heat and excess are ascribed to yang, and interior, cold and deficiency to yin.
|
|
</Text>
|
|
<Text style={styles.overviewParagraph}>
|
|
Two or more principles may occur concurrently, such as an exterior cold syndrome and an interior deficiency cold syndrome. A combined deficiency and excess may also be present. The principles may transform into each other as well, such as cold transforming into heat, or the exterior entering the interior. Additionally, a true cold may sometimes manifest as a false heat or vice versa.
|
|
</Text>
|
|
</View>
|
|
<Text style={styles.sectionHeading}>Eight Principles</Text>
|
|
</View>
|
|
);
|
|
|
|
return <CollectionScaffold {...props} items={sortedItems} header={header} />;
|
|
}
|
|
|
|
export function EightPrinciplesCardRenderer({
|
|
item,
|
|
onPress,
|
|
}: CollectionItemRendererProps) {
|
|
const a = item.attributes;
|
|
|
|
const title =
|
|
asString(a.name) ||
|
|
asString(a.title) ||
|
|
item.title;
|
|
|
|
const description =
|
|
asString(a.description) ||
|
|
asString(a.overview) ||
|
|
asString(a.classification) ||
|
|
item.summary;
|
|
|
|
const sortOrder = asNumber(a.sort_order);
|
|
const principleNumber =
|
|
typeof sortOrder === "number" && sortOrder > 0
|
|
? sortOrder
|
|
: typeof sortOrder === "number"
|
|
? sortOrder + 1
|
|
: undefined;
|
|
|
|
return (
|
|
<Pressable
|
|
accessibilityRole="button"
|
|
accessibilityLabel={title}
|
|
onPress={onPress}
|
|
style={({ pressed }) => [styles.row, pressed && styles.pressed]}
|
|
>
|
|
<View style={styles.iconBox}>
|
|
{principleNumber !== undefined ? (
|
|
<Text style={styles.principleNumber}>{principleNumber}</Text>
|
|
) : (
|
|
<Ionicons name="git-network-outline" size={20} color={Colors.primaryDark} />
|
|
)}
|
|
</View>
|
|
|
|
<View style={styles.content}>
|
|
<Text numberOfLines={2} style={styles.title}>
|
|
{title}
|
|
</Text>
|
|
|
|
{description ? (
|
|
<Text numberOfLines={3} style={styles.subtitle}>
|
|
{description}
|
|
</Text>
|
|
) : null}
|
|
</View>
|
|
|
|
<Ionicons name="chevron-forward" size={19} color="#94A3B8" />
|
|
</Pressable>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
overviewContainer: {
|
|
marginBottom: verticalScale(14),
|
|
},
|
|
overviewCard: {
|
|
backgroundColor: "#FFFFFF",
|
|
borderRadius: moderateScale(16),
|
|
borderWidth: 1,
|
|
borderColor: "#E2EAE5",
|
|
padding: moderateScale(16),
|
|
marginBottom: verticalScale(14),
|
|
},
|
|
overviewHeader: {
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
marginBottom: verticalScale(8),
|
|
gap: moderateScale(8),
|
|
},
|
|
overviewTitle: {
|
|
fontSize: moderateScale(16),
|
|
fontWeight: "700",
|
|
color: Colors.textPrimary,
|
|
},
|
|
overviewText: {
|
|
fontSize: moderateScale(13),
|
|
lineHeight: verticalScale(19),
|
|
color: Colors.textSecondary,
|
|
},
|
|
overviewParagraph: {
|
|
fontSize: moderateScale(13),
|
|
lineHeight: verticalScale(19),
|
|
color: Colors.textSecondary,
|
|
marginTop: verticalScale(10),
|
|
},
|
|
sectionHeading: {
|
|
fontSize: moderateScale(15),
|
|
fontWeight: "700",
|
|
color: Colors.textPrimary,
|
|
marginBottom: verticalScale(4),
|
|
marginLeft: moderateScale(4),
|
|
},
|
|
row: {
|
|
minHeight: verticalScale(72),
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
paddingHorizontal: moderateScale(14),
|
|
paddingVertical: verticalScale(13),
|
|
gap: moderateScale(11),
|
|
},
|
|
pressed: {
|
|
opacity: 0.72,
|
|
},
|
|
iconBox: {
|
|
width: moderateScale(40),
|
|
height: moderateScale(40),
|
|
borderRadius: moderateScale(20),
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
backgroundColor: "#E8F5E9",
|
|
},
|
|
principleNumber: {
|
|
fontSize: moderateScale(16),
|
|
fontWeight: "800",
|
|
color: Colors.primaryDark,
|
|
},
|
|
content: {
|
|
flex: 1,
|
|
gap: verticalScale(3),
|
|
},
|
|
title: {
|
|
fontSize: moderateScale(16),
|
|
lineHeight: moderateScale(22),
|
|
fontWeight: "700",
|
|
color: Colors.textPrimary,
|
|
},
|
|
subtitle: {
|
|
fontSize: moderateScale(12.5),
|
|
lineHeight: moderateScale(18),
|
|
color: Colors.textSecondary,
|
|
},
|
|
});
|