import React, {useRef, useState} from 'react'; import {ScrollView, StyleSheet} from 'react-native'; import DateTimePickerModal from 'react-native-modal-datetime-picker'; import {Button, TextInput} from 'react-native-paper'; import Set from './set'; import {format} from './time'; export default function SetForm({ save, set, }: { set: Set; save: (set: Set) => void; }) { const [name, setName] = useState(set.name); const [reps, setReps] = useState(set.reps.toString()); const [weight, setWeight] = useState(set.weight.toString()); const [created, setCreated] = useState(new Date(set.created)); const [unit, setUnit] = useState(set.unit); const [showDate, setShowDate] = useState(false); const weightRef = useRef(null); const onConfirm = (date: Date) => { setCreated(date); setShowDate(false); }; const handleSubmit = () => { save({ name, reps: Number(reps), created: created.toISOString(), weight: Number(weight), id: set.id, unit, }); }; const textInputs = ( <> weightRef.current?.focus()} selection={{start: 0, end: set.reps.toString().length}} autoFocus /> ); return ( <> {textInputs} setShowDate(false)} date={created} /> ); } const styles = StyleSheet.create({ marginBottom: { marginBottom: 10, }, });