import React, { useCallback, useEffect, useMemo, useState } from "react"; import { View, Text, TextInput, StyleSheet, ColorValue, Modal, TouchableOpacity, } from "react-native"; import Button from "@/containers/Button"; import { MaterialCommunityIcons } from "@expo/vector-icons"; import styles from "@/styles/styles"; import i18n from "@/i18n/i18n"; const colors: ColorValue[] = ["white", "red", "green", "blue", "black"]; const ChipInputModal = ({ showModal, setShowModal, totalChipsCount, update, }: { showModal: [boolean, ColorValue]; setShowModal: React.Dispatch>; totalChipsCount: number[]; update: Function; }) => { const color: ColorValue = useMemo(() => showModal[1], [showModal]); const colorIdx = useMemo(() => colors.indexOf(color), [color]); const [value, setValue] = useState(); // value may be undefined initially // Reset the color value when the specific color this modal is for, changes. The same modal is shared/reused in all cases. useEffect(() => { setValue(totalChipsCount[colorIdx]); }, [colorIdx]); const shadow = useMemo(() => color === "white", [color]); return ( setShowModal([false, color])} style={styles.modal} presentationStyle="fullScreen" animationType="slide" > {value !== undefined && ( <> {i18n.t("number_of_chips", { color: showModal[1]?.toString(), })}{" "} { const dirtyNum: number = parseInt(v); !isNaN(dirtyNum) ? setValue(dirtyNum) : setValue(0); }} testID="modalInput" /> )}