From b5a9c46590f95cddb524107ae1bbdf6731236d5d Mon Sep 17 00:00:00 2001 From: PalaashPandey Date: Wed, 18 Sep 2024 18:45:33 -0500 Subject: [PATCH] Fixed TimeInput's keyboard/selection issues (#186) Co-authored-by: Brandon Wees --- .../sheets/route_planning/InputRoute.tsx | 11 +++++++++-- app/components/ui/TimeInput.tsx | 14 ++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/components/sheets/route_planning/InputRoute.tsx b/app/components/sheets/route_planning/InputRoute.tsx index 5673204..fcae9f6 100644 --- a/app/components/sheets/route_planning/InputRoute.tsx +++ b/app/components/sheets/route_planning/InputRoute.tsx @@ -53,6 +53,8 @@ const InputRoute: React.FC = ({ sheetRef }) => { const addLocationFavorite = addFavoriteLocationMutation(); const removeLocationFavorite = removeFavoriteLocationMutation(); + const [timeInputFocused, setTimeInputFocused] = useState(false); + function toggleFavoriteLocation(location: SearchSuggestion) { if (favoriteLocations && (favoriteLocations as SearchSuggestion[]).find((item) => suggestionEqual(item, location))) @@ -63,6 +65,10 @@ const InputRoute: React.FC = ({ sheetRef }) => { } } + function toggleTimeInputFocused(newValue: boolean) { + setTimeInputFocused(newValue) + } + useEffect(() => { setSheetCloseCallback(() => { setTimeout(() => { @@ -122,7 +128,7 @@ const InputRoute: React.FC = ({ sheetRef }) => { > { - if (!suggestionOutput) Keyboard.dismiss() + if (!suggestionOutput && !timeInputFocused) Keyboard.dismiss() }} style={[!(routeInfoError == "") && {flex: 1}]} > @@ -208,6 +214,7 @@ const InputRoute: React.FC = ({ sheetRef }) => { setTime(time)} + onTimeInputFocused={toggleTimeInputFocused} /> @@ -365,4 +372,4 @@ const InputRoute: React.FC = ({ sheetRef }) => { ) } -export default memo(InputRoute); \ No newline at end of file +export default memo(InputRoute); diff --git a/app/components/ui/TimeInput.tsx b/app/components/ui/TimeInput.tsx index 05dc244..3ba27b3 100644 --- a/app/components/ui/TimeInput.tsx +++ b/app/components/ui/TimeInput.tsx @@ -5,9 +5,10 @@ import { TouchableOpacity } from 'react-native-gesture-handler'; interface Props { onTimeChange: (time: Date) => void; + onTimeInputFocused: (newValue: boolean) => void } -const TimeInput: React.FC = ({ onTimeChange }) => { +const TimeInput: React.FC = ({ onTimeChange, onTimeInputFocused }) => { const [time, setTime] = useState('') const [meridiem, setMeridiem] = useState('AM') const [isFocused, setIsFocused] = useState(false) @@ -87,9 +88,14 @@ const TimeInput: React.FC = ({ onTimeChange }) => { setIsFocused(true)} - onBlur={() => setIsFocused(false)} - selection={{ start: time.length, end: time.length }} + onFocus={() => { + setIsFocused(true) + onTimeInputFocused(true) + }} + onBlur={() => { + setIsFocused(false) + onTimeInputFocused(false) + }} style={{ color: theme.text, fontWeight: 'bold',