Created
January 16, 2022 20:19
-
-
Save gbarany/209e1cfab35dd451e2d4133a69511034 to your computer and use it in GitHub Desktop.
Unable to select any hours before noon when TimePickerModal is in 24-hour clock mode patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/node_modules/react-native-paper-dates/src/Time/AnalogClock.tsx b/node_modules/react-native-paper-dates/src/Time/AnalogClock.tsx | |
| index 7cb0d5f..934b010 100644 | |
| --- a/node_modules/react-native-paper-dates/src/Time/AnalogClock.tsx | |
| +++ b/node_modules/react-native-paper-dates/src/Time/AnalogClock.tsx | |
| @@ -14,7 +14,10 @@ import { | |
| getHourType, | |
| getMinutes, | |
| PossibleClockTypes, | |
| + getHourTypeFromOffset, | |
| + hourTypes | |
| } from './timeUtils' | |
| + | |
| import * as React from 'react' | |
| import { useLatest } from '../utils' | |
| @@ -70,13 +73,15 @@ function AnalogClock({ | |
| let pickedHours = getHours(angle, previousHourType) | |
| let hours12AndPm = !hours24 && modeRef.current === 'PM' | |
| + let hourTypeFromOffset = getHourTypeFromOffset(x, y, circleSize) | |
| + let hours24AndPM = hours24 && hourTypeFromOffset === hourTypes.pm | |
| // Avoiding the "24h" | |
| // Should be 12h for 12 hours and PM mode | |
| - if ((hours12AndPm || hours24) && pickedHours + 12 < 24) { | |
| + if ((hours12AndPm || hours24AndPM)) { | |
| pickedHours += 12 | |
| } | |
| - if (modeRef.current === 'AM' && pickedHours === 12) { | |
| + if (!hours24 && modeRef.current === 'AM' && pickedHours === 12) { | |
| pickedHours = 0 | |
| } | |
| diff --git a/node_modules/react-native-paper-dates/src/Time/AnalogClockHours.tsx b/node_modules/react-native-paper-dates/src/Time/AnalogClockHours.tsx | |
| index 287d6a2..e2766bf 100644 | |
| --- a/node_modules/react-native-paper-dates/src/Time/AnalogClockHours.tsx | |
| +++ b/node_modules/react-native-paper-dates/src/Time/AnalogClockHours.tsx | |
| @@ -34,7 +34,10 @@ function AnalogClockHours({ | |
| <View style={styles.outerHourInner}> | |
| {/* Display 00 instead of 12 for AM hours */} | |
| <Text style={hours === i + 1 ? { color } : null} selectable={false}> | |
| - {mode === 'AM' && i + 1 === 12 ? '00' : i + 1} | |
| + {is24Hour ? | |
| + mode === 'AM' && i + 1 === 12 ? '12' : i + 1 | |
| + : | |
| + mode === 'AM' && i + 1 === 12 ? '00' : i + 1} | |
| </Text> | |
| </View> | |
| </View> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment