abstract picker component; added small buttons; visual tweaks

This commit is contained in:
David Westgate 2025-03-17 23:48:31 -07:00
parent e720e2e010
commit 2e5efda69a
5 changed files with 98 additions and 81 deletions

View File

@ -15,8 +15,9 @@ import {
import styles, { COLORS } from "@/styles/styles"; import styles, { COLORS } from "@/styles/styles";
import Section from "@/containers/Section"; import Section from "@/containers/Section";
import AppContext from "@/util/context"; import AppContext from "@/util/context";
import { Picker } from "@react-native-picker/picker";
import i18n from "@/i18n/i18n"; import i18n from "@/i18n/i18n";
import { Picker, PickerItem } from "@/containers/Picker";
import { ItemValue } from "@react-native-picker/picker/typings/Picker";
const IndexScreen: React.FC = () => { const IndexScreen: React.FC = () => {
const [playerCount, setPlayerCount] = useState(2); const [playerCount, setPlayerCount] = useState(2);
@ -84,9 +85,9 @@ const IndexScreen: React.FC = () => {
} }
}; };
const handleLanguageChange = (language: string) => { const handleLanguageChange = (language: ItemValue, _: any) => {
setSelectedLanguage(language); setSelectedLanguage(language.toString());
i18n.changeLanguage(language); i18n.changeLanguage(language.toString());
}; };
return ( return (
@ -121,25 +122,9 @@ const IndexScreen: React.FC = () => {
<Picker <Picker
selectedValue={selectedLanguage} selectedValue={selectedLanguage}
onValueChange={handleLanguageChange} onValueChange={handleLanguageChange}
style={[styles.picker, { color: colors.TEXT }]}
dropdownIconColor={colors.TEXT}
> >
<Picker.Item <PickerItem label={i18n.t("english")} value="en" />
label={i18n.t("english")} <PickerItem label={i18n.t("spanish")} value="es" />
value="en"
style={{
color: colors.TEXT,
backgroundColor: colors.PRIMARY,
}}
/>
<Picker.Item
label={i18n.t("spanish")}
value="es"
style={{
color: colors.TEXT,
backgroundColor: colors.PRIMARY,
}}
/>
</Picker> </Picker>
</Section> </Section>
@ -227,19 +212,23 @@ const IndexScreen: React.FC = () => {
title={i18n.t("save_slot_1")} title={i18n.t("save_slot_1")}
onPress={() => handleSave("SLOT1")} onPress={() => handleSave("SLOT1")}
disabled={buyInAmount === null} disabled={buyInAmount === null}
size="small"
/> />
<Button <Button
title={i18n.t("save_slot_2")} title={i18n.t("save_slot_2")}
onPress={() => handleSave("SLOT2")} onPress={() => handleSave("SLOT2")}
disabled={buyInAmount === null} disabled={buyInAmount === null}
size="small"
/> />
<Button <Button
title={i18n.t("load_slot_1")} title={i18n.t("load_slot_1")}
onPress={() => handleLoad("SLOT1")} onPress={() => handleLoad("SLOT1")}
size="small"
/> />
<Button <Button
title={i18n.t("load_slot_2")} title={i18n.t("load_slot_2")}
onPress={() => handleLoad("SLOT2")} onPress={() => handleLoad("SLOT2")}
size="small"
/> />
</> </>
</Section> </Section>

View File

@ -1,8 +1,6 @@
import React, { useMemo } from "react"; import React from "react";
import { Picker } from "@react-native-picker/picker";
import styles, { COLORS } from "@/styles/styles";
import i18n from "@/i18n/i18n"; import i18n from "@/i18n/i18n";
import { useColorScheme } from "react-native"; import { Picker, PickerItem } from "@/containers/Picker";
interface CurrencySelectorProps { interface CurrencySelectorProps {
selectedCurrency: string; selectedCurrency: string;
@ -13,53 +11,17 @@ const CurrencySelector: React.FC<CurrencySelectorProps> = ({
selectedCurrency, selectedCurrency,
setSelectedCurrency, setSelectedCurrency,
}) => { }) => {
const colorScheme = useColorScheme();
const darkMode = useMemo(() => colorScheme === "dark", [colorScheme]);
const colors = useMemo(
() => (darkMode ? COLORS.DARK : COLORS.LIGHT),
[darkMode]
);
return ( return (
<> <>
<Picker <Picker
selectedValue={selectedCurrency} selectedValue={selectedCurrency}
onValueChange={(itemValue) => setSelectedCurrency(itemValue)} onValueChange={(itemValue) => setSelectedCurrency(itemValue.toString())}
style={[styles.picker, { color: colors.TEXT }]}
dropdownIconColor={colors.TEXT}
testID="currency-picker" // ✅ Add testID here testID="currency-picker" // ✅ Add testID here
> >
<Picker.Item <PickerItem label={i18n.t("usd")} value="$" />
label={i18n.t("usd")} <PickerItem label={i18n.t("euro")} value="€" />
value="$" <PickerItem label={i18n.t("pound")} value="£" />
style={{ <PickerItem label={i18n.t("inr")} value="₹" />
color: colors.TEXT,
backgroundColor: colors.PRIMARY,
}}
/>
<Picker.Item
label={i18n.t("euro")}
value="€"
style={{
color: colors.TEXT,
backgroundColor: colors.PRIMARY,
}}
/>
<Picker.Item
label={i18n.t("pound")}
value="£"
style={{
color: colors.TEXT,
backgroundColor: colors.PRIMARY,
}}
/>
<Picker.Item
label={i18n.t("inr")}
value="₹"
style={{
color: colors.TEXT,
backgroundColor: colors.PRIMARY,
}}
/>
</Picker> </Picker>
</> </>
); );

View File

@ -11,9 +11,15 @@ interface ButtonProps {
title: string; title: string;
onPress: () => void; onPress: () => void;
disabled?: boolean; disabled?: boolean;
size?: "normal" | "small";
} }
const Button: React.FC<ButtonProps> = ({ title, onPress, disabled }) => { const Button: React.FC<ButtonProps> = ({
title,
onPress,
disabled,
size = "normal",
}) => {
const colorScheme = useColorScheme(); const colorScheme = useColorScheme();
const darkMode = useMemo(() => colorScheme === "dark", [colorScheme]); const darkMode = useMemo(() => colorScheme === "dark", [colorScheme]);
const colors = useMemo( const colors = useMemo(
@ -26,12 +32,19 @@ const Button: React.FC<ButtonProps> = ({ title, onPress, disabled }) => {
disabled={disabled} disabled={disabled}
accessibilityRole="button" accessibilityRole="button"
style={[ style={[
styles.button, size == "normal" ? styles.button : styles.buttonSmall,
{ backgroundColor: colors.PRIMARY }, { backgroundColor: colors.PRIMARY },
disabled && styles.disabled, disabled && styles.disabled,
]} ]}
> >
<Text style={[styles.buttonText, { color: colors.TEXT }]}>{title}</Text> <Text
style={[
size == "normal" ? styles.buttonText : styles.buttonTextSmall,
{ color: colors.TEXT },
]}
>
{title}
</Text>
</TouchableOpacity> </TouchableOpacity>
); );
}; };
@ -44,22 +57,22 @@ const styles = StyleSheet.create({
marginHorizontal: 5, marginHorizontal: 5,
marginVertical: 5, marginVertical: 5,
}, },
darkButton: {
backgroundColor: "#333333",
},
lightButton: {
backgroundColor: "#DDDDDD",
},
buttonText: { buttonText: {
fontSize: 16, fontSize: 16,
fontWeight: "bold", fontWeight: "bold",
textAlign: "center", textAlign: "center",
}, },
darkText: { buttonSmall: {
color: "#FFFFFF", paddingVertical: 5,
paddingHorizontal: 10,
borderRadius: 8,
marginHorizontal: 2,
marginVertical: 2,
}, },
lightText: { buttonTextSmall: {
color: "#000000", fontSize: 12,
fontWeight: "bold",
textAlign: "center",
}, },
disabled: { disabled: {
opacity: 0.5, opacity: 0.5,

49
containers/Picker.tsx Normal file
View File

@ -0,0 +1,49 @@
import styles, { COLORS } from "@/styles/styles";
import { PickerItemProps, PickerProps } from "@react-native-picker/picker";
import { useMemo } from "react";
import { useColorScheme, View } from "react-native";
import { Picker as RNPicker } from "@react-native-picker/picker";
export const PickerItem: React.FC<PickerItemProps> = (props) => {
const colorScheme = useColorScheme();
const darkMode = useMemo(() => colorScheme === "dark", [colorScheme]);
const colors = useMemo(
() => (darkMode ? COLORS.DARK : COLORS.LIGHT),
[darkMode]
);
return (
<RNPicker.Item
style={[
styles.pickerItem,
{ color: colors.TEXT, backgroundColor: colors.PRIMARY },
]}
{...props}
/>
);
};
export const Picker: React.FC<PickerProps> = (props) => {
const colorScheme = useColorScheme();
const darkMode = useMemo(() => colorScheme === "dark", [colorScheme]);
const colors = useMemo(
() => (darkMode ? COLORS.DARK : COLORS.LIGHT),
[darkMode]
);
return (
<View style={styles.pickerWrapper}>
<RNPicker
style={[
styles.picker,
{
color: colors.TEXT,
backgroundColor: colors.PRIMARY,
},
]}
dropdownIconColor={colors.TEXT}
{...props}
/>
</View>
);
};

View File

@ -32,7 +32,7 @@ const GlobalStyles = StyleSheet.create({
gap: 10, gap: 10,
}, },
h1: { fontSize: 20, fontWeight: "bold" }, h1: { fontSize: 19, fontWeight: "bold" },
h2: { fontSize: 18, fontWeight: "normal" }, h2: { fontSize: 18, fontWeight: "normal" },
p: { p: {
fontSize: 16, fontSize: 16,
@ -63,6 +63,10 @@ const GlobalStyles = StyleSheet.create({
width: 150, width: 150,
}, },
pickerItem: {}, pickerItem: {},
pickerWrapper: {
borderRadius: 10,
overflow: "hidden",
},
}); });
export default GlobalStyles; export default GlobalStyles;