Skip to content

Commit

Permalink
Add move list screen
Browse files Browse the repository at this point in the history
  • Loading branch information
minsoeaung committed Nov 25, 2024
1 parent b739126 commit 7935ccd
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 4 deletions.
7 changes: 5 additions & 2 deletions components/MyTabBar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FontAwesome6, Ionicons, MaterialCommunityIcons, MaterialIcons } from '@expo/vector-icons';
import { FontAwesome6, Ionicons, MaterialCommunityIcons, MaterialIcons, Octicons } from '@expo/vector-icons';
import { BottomTabBarProps } from '@react-navigation/bottom-tabs';
import { Pressable, StyleSheet, View } from 'react-native';

Expand Down Expand Up @@ -55,8 +55,11 @@ const MyTabBar = ({ state, descriptors, navigation }: BottomTabBarProps) => {
style={styles.tab}
>
{route.name === 'PokeDexStack' && <MaterialIcons style={iconStyles} name="catching-pokemon" />}
{route.name === 'MovesStack' && (
<MaterialCommunityIcons style={iconStyles} name="lightning-bolt" />
)}
{route.name === 'AbilitiesStack' && <FontAwesome6 style={iconStyles} name="dumbbell" />}
{route.name === 'ItemsStack' && <MaterialCommunityIcons style={iconStyles} name="view-grid" />}
{route.name === 'ItemsStack' && <Octicons style={iconStyles} name="tools" />}
{route.name === 'AboutStack' && <Ionicons style={iconStyles} name="settings" />}
<MyText style={styles.label}>{label}</MyText>
</Pressable>
Expand Down
2 changes: 1 addition & 1 deletion constants/MOVES.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions screens/AbilityDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,6 @@ const styles = StyleSheet.create({
borderColor: colors.text,
borderBottomLeftRadius: 5,
borderBottomRightRadius: 5,
backgroundColor: colors.card,
},
});
2 changes: 2 additions & 0 deletions screens/BottomTabsNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { StyleSheet, View } from 'react-native';
import { AbilitiesStack } from './AbilitiesStack';
import AboutStack from './AboutStack';
import { ItemsStack } from './ItemsStack';
import { MovesStack } from './MovesStack';
import PokeDexStack from './PokeDexStack';
import MyTabBar from '../components/MyTabBar';
import { colors } from '../constants/colors';
Expand All @@ -21,6 +22,7 @@ export const BottomTabsNavigator: React.FC = () => {
sceneContainerStyle={{ backgroundColor: colors.background }}
>
<BottomTabs.Screen name="PokeDexStack" component={PokeDexStack} options={{ title: 'PokeDex' }} />
<BottomTabs.Screen name="MovesStack" component={MovesStack} options={{ title: 'Moves' }} />
<BottomTabs.Screen name="AbilitiesStack" component={AbilitiesStack} options={{ title: 'Abilities' }} />
<BottomTabs.Screen name="ItemsStack" component={ItemsStack} options={{ title: 'Items' }} />
<BottomTabs.Screen name="AboutStack" component={AboutStack} options={{ title: 'Settings' }} />
Expand Down
3 changes: 2 additions & 1 deletion screens/MoveDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import MyText from '../components/MyText';
import PikachuRunning from '../components/PikachuRunning';
import PokemonCellItem from '../components/PokemonCellItem';
import TitleOnlyCard from '../components/TitleOnlyCard';
import { colors, typeColor } from '../constants/colors';
import pokemonDetails from '../constants/POKEMON_DETAILS';
import { colors, typeColor } from '../constants/colors';
import useFetchData from '../hooks/useFetchData';
import { MoveLearnMethod, StackParamList } from '../types';
import getFormattedName from '../utils/getFormattedName';
Expand Down Expand Up @@ -214,6 +214,7 @@ const styles = StyleSheet.create({
borderColor: colors.text,
borderBottomLeftRadius: 5,
borderBottomRightRadius: 5,
backgroundColor: colors.card,
},
type: {
paddingHorizontal: 3,
Expand Down
229 changes: 229 additions & 0 deletions screens/MoveList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
import { useNavigation, useScrollToTop } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { FlashList } from '@shopify/flash-list';
import React, { useRef } from 'react';
import { Pressable, StyleSheet, TextInput, View } from 'react-native';

import ClearInputButton from '../components/ClearInputButton';
import { MoveDamageClass } from '../components/MoveDamageClass';
import MyText from '../components/MyText';
import SmallGreyText from '../components/SmallGreyText';
import MOVES from '../constants/MOVES';
import { colors, typeColor } from '../constants/colors';
import { fonts } from '../constants/fonts';
import useSearchableList from '../hooks/useSearchableList';
import { StackParamList } from '../types';
import getFormattedName from '../utils/getFormattedName';

import hairlineWidth = StyleSheet.hairlineWidth;

const moveNames = Object.keys(MOVES).map(moveName => ({ name: moveName }));

export default function MoveList() {
const { list, value, handleChangeText, clearInput } = useSearchableList(moveNames);
const navigation = useNavigation<NativeStackNavigationProp<StackParamList, 'MoveList'>>();
const listRef = useRef(null);
useScrollToTop(listRef);

return (
<View style={styles.container}>
<View style={styles.searchInputWrap}>
<TextInput
style={styles.searchInput}
value={value}
onChangeText={handleChangeText}
placeholder="Search..."
selectionColor="tomato"
placeholderTextColor="grey"
/>
<ClearInputButton onPress={clearInput} />
</View>
<View style={styles.moveListWrap}>
<FlashList
data={['StickyHeader', ...list]}
keyExtractor={item => {
if (typeof item === 'string') {
return item;
} else {
return item.name;
}
}}
estimatedItemSize={77}
stickyHeaderIndices={[0]}
renderItem={({ item }) => {
if (typeof item === 'string') {
return (
<View style={styles.header}>
<MyText style={{ flex: 3, textAlign: 'center', fontSize: 10 }}>Name</MyText>
<MyText style={{ flex: 2, textAlign: 'center', fontSize: 10 }}>Type,Cat.</MyText>
<MyText style={{ flex: 1, textAlign: 'center', fontSize: 10 }}>Power</MyText>
<MyText style={{ flex: 1, textAlign: 'center', fontSize: 10 }}>Acc.%</MyText>
<MyText style={{ flex: 1, textAlign: 'center', fontSize: 10 }}>PP</MyText>
<MyText style={{ flex: 1, textAlign: 'center', fontSize: 10 }}>&nbsp;</MyText>
</View>
);
} else {
const move = MOVES[item.name];

return (
<Pressable
style={{
flex: 1,
borderBottomWidth: hairlineWidth,
borderLeftWidth: hairlineWidth,
borderRightWidth: hairlineWidth,
borderColor: 'black',
paddingVertical: 10,
marginHorizontal: 10,
}}
onPress={() => {
navigation.push('MoveDetail', move);
}}
>
{({ pressed }) => (
<>
<View
style={{
flex: 1,
flexDirection: 'row',
alignItems: 'center',
}}
>
<View style={{ flex: 3, paddingLeft: 15 }}>
<MyText
numberOfLines={1}
style={{ color: pressed ? colors.tomato : 'black' }}
>
{getFormattedName(move.name)}
</MyText>
</View>
<View
style={{
flex: 2,
flexDirection: 'row',
gap: 5,
alignItems: 'center',
}}
>
<MyText
style={StyleSheet.flatten([
styles.type,
{
backgroundColor:
typeColor[move.type as keyof typeof typeColor],
},
])}
>
{move.type}
</MyText>
<MoveDamageClass damageClass={move.damageClass} />
</View>
<MyText
style={{
flex: 1,
textAlign: 'center',
color: pressed ? colors.tomato : 'black',
}}
>
{move.power || '-'}
</MyText>
<MyText
style={{
flex: 1,
textAlign: 'center',
color: pressed ? colors.tomato : 'black',
}}
>
{move.accuracy || '-'}
</MyText>
<MyText
style={{
flex: 1,
textAlign: 'center',
color: pressed ? colors.tomato : 'black',
}}
>
{move.pp || '-'}
</MyText>
<MyText
style={{
flex: 1,
textAlign: 'center',
color: pressed ? colors.tomato : 'black',
}}
>
{'>'}
</MyText>
</View>
{move.description && (
<View style={{ marginLeft: 10 }}>
<SmallGreyText text={move.description} />
</View>
)}
</>
)}
</Pressable>
);

// return <Move item={item.name} learnMethod="other" />;
}
}}
/>
</View>
</View>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
padding: 10,
paddingBottom: 0,
backgroundColor: colors.background,
},
searchInputWrap: {
backgroundColor: colors.card,
borderRadius: 5,
marginBottom: 10,
paddingRight: 5,
position: 'relative',
flexDirection: 'row',
justifyContent: 'space-between',
},
searchInput: {
height: 40,
paddingVertical: 10,
paddingLeft: 20,
color: colors.cardText,
width: '90%',
fontFamily: fonts.fontDotGothic,
},
moveListWrap: {
flex: 1,
backgroundColor: colors.card,
color: colors.cardText,
borderRadius: 5,
overflow: 'hidden',
position: 'relative',
},
header: {
borderWidth: hairlineWidth,
borderColor: 'black',
marginHorizontal: 10,
flexDirection: 'row',
backgroundColor: colors.card,
},
type: {
paddingHorizontal: 3,
paddingVertical: 2,
color: colors.typeText,
fontSize: 9,
lineHeight: 12,
borderRadius: 2,

textShadowColor: 'rgba(0, 0, 0, 0.9)',
textShadowOffset: { width: 0.5, height: 0.5 },
textShadowRadius: 3,
textTransform: 'capitalize',
},
});
30 changes: 30 additions & 0 deletions screens/MovesStack.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import React from 'react';

import AbilityDetail from './AbilityDetail';
import PokemonDetail from './PokemonDetail';
import TypeDetail from './TypeDetail';
import MyHeader from '../components/MyHeader';
import { StackParamList } from '../types';
import MoveDetail from './MoveDetail';
import MoveList from './MoveList';

const Stack = createNativeStackNavigator<StackParamList>();

export const MovesStack: React.FC = () => {
return (
<Stack.Navigator
initialRouteName="MoveList"
screenOptions={{
header: props => <MyHeader headerProps={props} />,
animation: 'fade',
}}
>
<Stack.Screen name="MoveList" component={MoveList} options={{ title: 'Moves' }} />
<Stack.Screen name="AbilityDetail" component={AbilityDetail} />
<Stack.Screen name="PokemonDetail" component={PokemonDetail} />
<Stack.Screen name="TypeDetail" component={TypeDetail} />
<Stack.Screen name="MoveDetail" component={MoveDetail} />
</Stack.Navigator>
);
};
2 changes: 2 additions & 0 deletions types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type StackParamList = {
PokeDex: undefined;
AbilityList: undefined;
ItemList: undefined;
MoveList: undefined;
About: undefined;

PokemonDetail: Name;
Expand Down Expand Up @@ -105,6 +106,7 @@ export type PokemonMoveDetailType = {
power: number | null;
accuracy: number | null;
pp: number | null;
description: string | null;
};

export type MoveLearnMethod = 'levelUp' | 'machine' | 'tutor' | 'egg';

0 comments on commit 7935ccd

Please sign in to comment.