Adding component LearnihonPage with children props

master
Arthur VALIN 2 years ago
parent 3464d7daf6
commit 6af001cbe2

Binary file not shown.

@ -3,14 +3,9 @@
"", "",
"\\assets", "\\assets",
"\\components", "\\components",
"\\model",
"\\navigation", "\\navigation",
"\\pages", "\\pages"
"\\redux",
"\\redux\\actions",
"\\redux\\reducers",
"\\redux\\thunks"
], ],
"SelectedNode": "\\components\\KanjiPlaygroundList.tsx", "SelectedNode": "\\pages\\List.tsx",
"PreviewInSolutionExplorer": false "PreviewInSolutionExplorer": false
} }

Binary file not shown.

@ -4,10 +4,10 @@
"slug": "Learnihon", "slug": "Learnihon",
"version": "1.0.0", "version": "1.0.0",
"orientation": "portrait", "orientation": "portrait",
"icon": "./src/assets/icon.png", "icon": "./assets/icon.png",
"userInterfaceStyle": "automatic", "userInterfaceStyle": "automatic",
"splash": { "splash": {
"image": "./src/assets/splash.png", "image": "./assets/splash.png",
"resizeMode": "contain", "resizeMode": "contain",
"backgroundColor": "#ffffff" "backgroundColor": "#ffffff"
}, },
@ -22,12 +22,12 @@
}, },
"android": { "android": {
"adaptiveIcon": { "adaptiveIcon": {
"foregroundImage": "./src/assets/adaptive-icon.png", "foregroundImage": "./assets/icon.png",
"backgroundColor": "#FFFFFF", "backgroundColor": "#FFFFFF"
} }
}, },
"web": { "web": {
"favicon": "./src/assets/favicon.png" "favicon": "./assets/favicon.png"
} }
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 582 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 582 KiB

@ -11,11 +11,7 @@ import { KanjiMapper } from '../model/kanjiMapper';
import { Eye, EyeOff } from "react-native-feather"; import { Eye, EyeOff } from "react-native-feather";
import { learnihonColors } from '../assets/colors'; import { learnihonColors } from '../assets/colors';
type DrawingCanvaProps = { const DrawingCanva = () => {
backgroundImage: string;
}
const DrawingCanva = (props: DrawingCanvaProps) => {
const style = useColorScheme() == 'light' ? style_light : style_dark; const style = useColorScheme() == 'light' ? style_light : style_dark;

@ -27,21 +27,21 @@ const KanjiList = () => {
}; };
return ( return (
<View> <View style={kanjiListStyle.container}>
<GradeChipList onSelect={updateSelectedItems} /> <GradeChipList onSelect={updateSelectedItems} />
{selectedItems.length ? {selectedItems.length ?
(<SectionList (<SectionList
sections={selectedItems} sections={selectedItems}
windowSize={50} windowSize={50}
renderItem={ renderItem={
({ item }) => <KanjiListCell kanji={item} /> ({ item }) => <KanjiListCell kanji={item} />
} }
renderSectionHeader={({ section }) => ( renderSectionHeader={({ section }) => (
<Text style={kanjiListStyle.sectionHeader}>{section.title}</Text> <Text style={kanjiListStyle.sectionHeader}>{section.title}</Text>
)} )}
keyExtractor={item => `basicListEntry-${item.character}`}/>) keyExtractor={item => `basicListEntry-${item.character}`}/>
: ( ) : (
<View style={kanjiListStyle.container}> <View style={kanjiListStyle.container}>
<Text style={kanjiListStyle.text}>Select a grade</Text> <Text style={kanjiListStyle.text}>Select a grade</Text>
</View> </View>
@ -68,9 +68,7 @@ const kanjiListStyle_light = StyleSheet.create({
opacity: 0.5 opacity: 0.5
}, },
container: { container: {
flex: 1, flex: 1
justifyContent: 'center',
alignItems: 'center',
}, },
}) })
@ -92,9 +90,7 @@ const kanjiListStyle_dark = StyleSheet.create({
opacity: 0.5 opacity: 0.5
}, },
container: { container: {
flex: 1, flex: 1
justifyContent: 'center',
alignItems: 'center',
}, },
}) })

@ -6,7 +6,7 @@ export type KanjiGuess = {
} }
export const calcCorrectGuessesRatio = (guess: KanjiGuess): number => { export const calcCorrectGuessesRatio = (guess: KanjiGuess): number => {
return (guess.totalCorrectGuesses / guess.totalGuesses) * 100; return Math.round((guess.totalCorrectGuesses / guess.totalGuesses) * 100);
} }
export const getColorByRatio = (ratio: number): string => { export const getColorByRatio = (ratio: number): string => {

@ -76,13 +76,9 @@ const TabBar = () => {
const Tab = createBottomTabNavigator(); const Tab = createBottomTabNavigator();
return ( return (
<>
<Header/>
<Tab.Navigator <Tab.Navigator
screenOptions={tabOptions} screenOptions={tabOptions}
initialRouteName="Learn" initialRouteName="Learn">
>
<Tab.Screen <Tab.Screen
options={{ options={{
tabBarIcon: ({ color }) => ( tabBarIcon: ({ color }) => (
@ -90,9 +86,8 @@ const TabBar = () => {
) )
}} }}
name="List" name="List"
component={KanjiStackNavigator} component={KanjiStackNavigator}/>
/> <Tab.Screen
<Tab.Screen
options={{ options={{
tabBarIcon: ({ color }) => ( tabBarIcon: ({ color }) => (
<LearnIcon color={color} width={32} height={32} /> <LearnIcon color={color} width={32} height={32} />
@ -111,8 +106,7 @@ const TabBar = () => {
}} }}
name="Playground" name="Playground"
component={Playground} /> component={Playground} />
</Tab.Navigator> </Tab.Navigator>
</>
); );
} }

@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { StyleSheet, Text, useColorScheme, View } from 'react-native'; import { ActivityIndicator, StyleSheet, Text, useColorScheme, View } from 'react-native';
import { SvgXml } from 'react-native-svg'; import { SvgXml } from 'react-native-svg';
import { learnihonColors } from '../assets/colors'; import { learnihonColors } from '../assets/colors';
import DetailExamples from '../components/DetailExamples'; import DetailExamples from '../components/DetailExamples';
@ -11,6 +11,8 @@ const Detail = ({route}) => {
const kanji:Kanji = route.params.kanji; const kanji:Kanji = route.params.kanji;
const detailStyle = useColorScheme() == 'light' ? detailStyle_light : detailStyle_dark; const detailStyle = useColorScheme() == 'light' ? detailStyle_light : detailStyle_dark;
const [loadingImg, setLoadingImg] = useState(false);
const [iconXml, setIconXml] = useState('<svg></svg>'); const [iconXml, setIconXml] = useState('<svg></svg>');
const [imgXml, setImgXml] = useState('<svg></svg>'); const [imgXml, setImgXml] = useState('<svg></svg>');
@ -25,8 +27,10 @@ const Detail = ({route}) => {
useEffect(() => { useEffect(() => {
console.log(kanji) console.log(kanji)
setLoadingImg(true);
fetchXml(); fetchXml().then(_ => {
setLoadingImg(false);
});
}, []); }, []);
@ -36,11 +40,16 @@ const Detail = ({route}) => {
<Text style={detailStyle.text}>{kanji.onyomi}</Text> <Text style={detailStyle.text}>{kanji.onyomi}</Text>
<Text style={detailStyle.text}>{kanji.kunyomi}</Text> <Text style={detailStyle.text}>{kanji.kunyomi}</Text>
</View> </View>
<SvgXml {loadingImg ?
(
<View style={detailStyle.loader}>
<ActivityIndicator size="large" color={learnihonColors.main} />
</View>
):(<SvgXml
xml={imgXml xml={imgXml
.replace(/fill="#[0-9a-f]{6}"/g, `fill=${detailStyle.svg.color}`)} .replace(/fill="#[0-9a-f]{6}"/g, `fill=${detailStyle.svg.color}`)}
width="100" width="100"
height="100"/> height="100" />)}
<Text style={detailStyle.tinyText}>{kanji.strokes + " strokes"}</Text> <Text style={detailStyle.tinyText}>{kanji.strokes + " strokes"}</Text>
<Text style={detailStyle.meaningText}>{kanji.meaning}</Text> <Text style={detailStyle.meaningText}>{kanji.meaning}</Text>
@ -92,6 +101,12 @@ const detailStyle_light = StyleSheet.create({
color: learnihonColors.main, color: learnihonColors.main,
fontWeight: "900", fontWeight: "900",
textAlign: "center" textAlign: "center"
},
loader: {
justifyContent: 'center',
alignItems: 'center',
width: 100,
height: 100
} }
}) })
@ -127,6 +142,12 @@ const detailStyle_dark = StyleSheet.create({
fontWeight: "900", fontWeight: "900",
textAlign: "center" textAlign: "center"
},
loader: {
justifyContent: 'center',
alignItems: 'center',
width: 100,
height: 100
} }
}); });

@ -1,38 +1,14 @@
import React from 'react'; import React from 'react';
import { StyleSheet, useColorScheme, View } from 'react-native';
import { learnihonColors } from '../assets/colors';
import KanjiCard from '../components/KanjiCard'; import KanjiCard from '../components/KanjiCard';
import LearnihonPage from './LearnihonPage';
const Learn = () => { const Learn = () => {
const learnStyle = useColorScheme() == 'light' ? learnStyle_light : learnStyle_dark;
return ( return (
<View style={learnStyle.container}> <LearnihonPage>
<KanjiCard></KanjiCard> <KanjiCard></KanjiCard>
</View> </LearnihonPage>
); );
}; };
const learnStyle_light = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: learnihonColors.light
}
})
const learnStyle_dark = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: learnihonColors.dark,
},
});
export default Learn; export default Learn;

@ -0,0 +1,39 @@
import React from 'react';
import { StyleSheet, useColorScheme, View } from 'react-native';
import { learnihonColors } from '../assets/colors';
import Header from '../components/Header';
const LearnihonPage = ({ children }: React.PropsWithChildren<{}>) => {
const style = useColorScheme() == 'light' ? style_light : style_dark;
return (
<View style={style.container}>
<Header/>
{children}
</View>
);
};
const style_light = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: learnihonColors.light
}
})
const style_dark = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: learnihonColors.dark,
},
});
export default LearnihonPage;

@ -2,37 +2,14 @@
import { StyleSheet, useColorScheme, View } from 'react-native'; import { StyleSheet, useColorScheme, View } from 'react-native';
import { learnihonColors } from '../assets/colors'; import { learnihonColors } from '../assets/colors';
import KanjiList from '../components/KanjiList'; import KanjiList from '../components/KanjiList';
import LearnihonPage from './LearnihonPage';
const List = () => { const List = () => {
const listStyle = useColorScheme() == 'light' ? listStyle_light : listStyle_dark;
return ( return (
<View style={listStyle.container}> <LearnihonPage>
<KanjiList/> <KanjiList/>
</View> </LearnihonPage>
); );
}; };
const listStyle_light = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: learnihonColors.light,
}
})
const listStyle_dark = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: learnihonColors.dark,
},
});
export default List; export default List;

@ -3,40 +3,15 @@ import { StyleSheet, useColorScheme, View } from 'react-native';
import { learnihonColors } from '../assets/colors'; import { learnihonColors } from '../assets/colors';
import DrawingCanva from '../components/DrawingCanva'; import DrawingCanva from '../components/DrawingCanva';
import KanjiPlaygroundList from '../components/KanjiPlaygroundList'; import KanjiPlaygroundList from '../components/KanjiPlaygroundList';
import LearnihonPage from './LearnihonPage';
const Playground = () => { const Playground = () => {
const playgroundStyle = useColorScheme() == 'light' ? playgroundStyle_light : playgroundStyle_dark;
return ( return (
<View style={playgroundStyle.container}> <LearnihonPage>
<KanjiPlaygroundList/> <KanjiPlaygroundList/>
<DrawingCanva backgroundImage="https://media.kanjialive.com/kanji_strokes/otozu(reru)_11.svg"/> <DrawingCanva/>
</View> </LearnihonPage>
); );
}; };
const playgroundStyle_light = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: learnihonColors.light
}
})
const playgroundStyle_dark = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: learnihonColors.dark,
},
});
export default Playground; export default Playground;
Loading…
Cancel
Save