import React, { useEffect, useState } from 'react';
import { ActivityIndicator, StyleSheet, Text, useColorScheme, View } from 'react-native';
import { SvgXml } from 'react-native-svg';
import { learnihonColors } from '../assets/colors';
import DetailExamples from '../components/DetailExamples';
import DetailRadical from '../components/DetailRadical';
import { Kanji } from '../model/kanji';
const Detail = ({route}) => {
const kanji:Kanji = route.params.kanji;
const detailStyle = useColorScheme() == 'light' ? detailStyle_light : detailStyle_dark;
const [loadingImg, setLoadingImg] = useState(false);
const [iconXml, setIconXml] = useState('');
const [imgXml, setImgXml] = useState('');
const fetchXml = async () => {
const imgxml = await (await fetch(kanji.image)).text();
setImgXml(imgxml);
if (kanji.radical.position) {
const iconxml = await (await fetch(kanji.radical.position))?.text();
setIconXml(iconxml);
}
}
useEffect(() => {
console.log(kanji)
setLoadingImg(true);
fetchXml().then(_ => {
setLoadingImg(false);
});
}, []);
return (
{kanji.onyomi}
{kanji.kunyomi}
{loadingImg ?
(
):()}
{kanji.strokes + " strokes"}
{kanji.meaning}
{kanji.radical.position && kanji.radical.character &&
(<>
Radical
>)}
{kanji.examples &&
(<>
Examples
>)}
);
};
const detailStyle_light = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: learnihonColors.light_2,
height: "100%",
width: "100%"
},
pronounciation: {
alignItems: "center"
},
svg: {
color: "black"
},
title: {
fontWeight: "bold",
fontSize: 20,
},
text: {
color: "black"
},
tinyText: {
fontSize: 10,
color: "black"
},
meaningText: {
fontSize: 20,
color: learnihonColors.main,
fontWeight: "900",
textAlign: "center"
},
loader: {
justifyContent: 'center',
alignItems: 'center',
width: 100,
height: 100
}
})
const detailStyle_dark = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: learnihonColors.dark_2,
},
pronounciation: {
alignItems: "center"
},
svg: {
color: "white"
},
title: {
fontWeight: "bold",
fontSize: 20,
color: "white"
},
text: {
color: "white"
},
tinyText: {
fontSize: 10,
color: "white"
},
meaningText: {
fontSize: 20,
color: learnihonColors.main,
fontWeight: "900",
textAlign: "center"
},
loader: {
justifyContent: 'center',
alignItems: 'center',
width: 100,
height: 100
}
});
export default Detail;