ZingTruyen.Xyz

AIコードで世界を癒す

7

MarkPIcassoMPA


ホリスティック健康スナップ (Holistic Health Snap)ストーリー家族は暖かく、衛生や料理のスキルも向上しました。しかし、子どもがトイレの後に白くて動くような便を出し、あなたは恐怖を感じます。医者はいません。しかし、スマホにある「Holistic Health Snap」アプリを使えば、写真を撮るだけで問題を特定し、解決策を提示してくれます。この場合、子どもには寄生虫(ワーム)があり、アプリは安全な対応策を教えてくれます。React Native コード(写真撮影・解析・ホリスティック対応)import React, { useState, useEffect } from 'react';
import { View, Text, Button, Image, FlatList, TextInput, StyleSheet, TouchableOpacity } from 'react-native';
import { launchCamera } from 'react-native-image-picker';
import AsyncStorage from '@react-native-async-storage/async-storage';


// カテゴリーとホリスティック対応
const CATEGORIES = [
{ name: "皮膚", remedies: ["やさしく石鹸で洗う", "アロエジェルを塗る", "かかない"] },
{ name: "虫刺され", remedies: ["水で洗浄", "蜂蜜またはアロエを塗る", "冷却パック使用"] },
{ name: "打撲", remedies: ["初期は冷却パック", "患部を高く", "48時間後に優しくマッサージ"] },
{ name: "寄生虫", remedies: ["衛生を保つ", "水は沸騰してから飲む", "食物繊維を多く摂る"] },
{ name: "その他", remedies: ["清潔を保つ", "変化を観察", "悪化したら医療機関へ"] },
];

export default function App() {
const [photoData, setPhotoData] = useState([]);
const [description, setDescription] = useState('');
const [selectedCategory, setSelectedCategory] = useState(CATEGORIES[0].name);
const [currentPhoto, setCurrentPhoto] = useState(null);

useEffect(() => { loadData(); }, []);

const loadData = async () => {
try {
const data = await AsyncStorage.getItem('photos');
if (data !== null) setPhotoData(JSON.parse(data));
} catch (error) { console.log(error); }
};

const saveData = async (newData) => {
try { await AsyncStorage.setItem('photos', JSON.stringify(newData)); }
catch (error) { console.log(error); }
};

const takePhoto = () => {
launchCamera({ mediaType: 'photo', quality: 0.5 }, response => {
if (response.assets && response.assets.length > 0) {
setCurrentPhoto(response.assets[0].uri);
}
});
};

const savePhoto = () => {
if (!currentPhoto) return;
const categoryObj = CATEGORIES.find(cat => cat.name === selectedCategory) || { remedies: [] };
const newEntry = {
uri: currentPhoto,
category: selectedCategory,
description,
remedies: categoryObj.remedies,
timestamp: new Date().toISOString()
};
const updatedData = [newEntry, ...photoData];
setPhotoData(updatedData);
saveData(updatedData);
setCurrentPhoto(null);
setDescription('');
};

return (
<View style={styles.container}>
<Text style={styles.header}>ホリスティック健康スナップ</Text>
<Button onPress={takePhoto} />
{currentPhoto && (
<View style={styles.preview}>
<Image source={{ uri: currentPhoto }} style={styles.image} />
<TextInput value={description} onChangeText={setDescription} style={styles.input} />
<View style={styles.categories}>
{CATEGORIES.map(cat => (
<TouchableOpacity
key={cat.name}
onPress={() => setSelectedCategory(cat.name)}
style={[styles.categoryButton, selectedCategory === cat.name && styles.selectedCategory]}
>
<Text>{cat.name}</Text>
</TouchableOpacity>
))}
</View>
<Button onPress={savePhoto} />
</View>
)}
<Text style={styles.subHeader}>保存された写真と対応策:</Text>
<FlatList
data={photoData}
keyExtractor={(item, index) => index.toString()}
renderItem={({ item }) => (
<View style={styles.item}>
<Image source={{ uri: item.uri }} style={styles.thumbnail} />
<View style={{ flex: 1, marginLeft: 10 }}>
<Text style={styles.itemText}>カテゴリー: {item.category}</Text>
<Text style={styles.itemText}>説明: {item.description || "N/A"}</Text>
<Text style={styles.itemText}>日付: {new Date(item.timestamp).toLocaleString()}</Text>
<Text style={styles.itemTextBold}>ホリスティック対応:</Text>
{item.remedies.map((remedy, i) => <Text key={i} style={styles.itemText}>• {remedy}</Text>)}
</View>
</View>
)}
/>
</View>
);
}

const styles = StyleSheet.create({
container: { flex: 1, padding: 20, backgroundColor: '#f5f5f5' },
header: { fontSize: 28, fontWeight: 'bold', marginBottom: 10 },
subHeader: { fontSize: 20, marginTop: 20, marginBottom: 10 },
preview: { marginVertical: 10 },
image: { width: '100%', height: 200, marginBottom: 10 },
input: { borderColor: '#ccc', borderWidth: 1, padding: 8, marginBottom: 10, borderRadius: 5 },
categories: { flexDirection: 'row', flexWrap: 'wrap', marginBottom: 10 },
categoryButton: { padding: 8, borderWidth: 1, borderColor: '#ccc', borderRadius: 5, marginRight: 5, marginBottom: 5 },
selectedCategory: { backgroundColor: '#a0e1e5' },
item: { flexDirection: 'row', marginBottom: 10, backgroundColor: '#fff', padding: 10, borderRadius: 5 },
thumbnail: { width: 80, height: 80, borderRadius: 5 },
itemText: { fontSize: 14 },
itemTextBold: { fontSize: 16, fontWeight: 'bold', marginTop: 5 }
});

依存関係インストール:

npm install @react-navigation/native @react-navigation/stack react-native-image-picker @react-native-async-storage/async-storage
npx pod-install ios # iOS用

Bạn đang đọc truyện trên: ZingTruyen.Xyz