react-native-paper-dates 0.23.12 → 0.23.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/lib/commonjs/Date/AnimatedCrossView.js +1 -1
  2. package/lib/commonjs/Date/AnimatedCrossView.js.map +1 -1
  3. package/lib/commonjs/Date/CalendarEdit.js +11 -3
  4. package/lib/commonjs/Date/CalendarEdit.js.map +1 -1
  5. package/lib/commonjs/Date/CalendarHeader.js +2 -2
  6. package/lib/commonjs/Date/CalendarHeader.js.map +1 -1
  7. package/lib/commonjs/Date/DatePickerModal.js +1 -1
  8. package/lib/commonjs/Date/DatePickerModal.js.map +1 -1
  9. package/lib/commonjs/Date/DayName.js +2 -3
  10. package/lib/commonjs/Date/DayName.js.map +1 -1
  11. package/lib/commonjs/Date/DayNames.js +1 -2
  12. package/lib/commonjs/Date/DayNames.js.map +1 -1
  13. package/lib/commonjs/Date/YearPicker.js +1 -1
  14. package/lib/commonjs/Date/YearPicker.js.map +1 -1
  15. package/lib/commonjs/Time/AmPmSwitcher.js +20 -7
  16. package/lib/commonjs/Time/AmPmSwitcher.js.map +1 -1
  17. package/lib/commonjs/Time/TimeInputs.js +29 -5
  18. package/lib/commonjs/Time/TimeInputs.js.map +1 -1
  19. package/lib/commonjs/Time/TimePicker.js +9 -2
  20. package/lib/commonjs/Time/TimePicker.js.map +1 -1
  21. package/lib/commonjs/Time/TimePickerModal.js +12 -7
  22. package/lib/commonjs/Time/TimePickerModal.js.map +1 -1
  23. package/lib/commonjs/Time/timeUtils.js +5 -40
  24. package/lib/commonjs/Time/timeUtils.js.map +1 -1
  25. package/lib/commonjs/shared/utils.js +1 -1
  26. package/lib/commonjs/shared/utils.js.map +1 -1
  27. package/lib/module/Date/AnimatedCrossView.js +1 -1
  28. package/lib/module/Date/AnimatedCrossView.js.map +1 -1
  29. package/lib/module/Date/CalendarEdit.js +11 -3
  30. package/lib/module/Date/CalendarEdit.js.map +1 -1
  31. package/lib/module/Date/CalendarHeader.js +2 -2
  32. package/lib/module/Date/CalendarHeader.js.map +1 -1
  33. package/lib/module/Date/DatePickerModal.js +1 -1
  34. package/lib/module/Date/DatePickerModal.js.map +1 -1
  35. package/lib/module/Date/DayName.js +2 -3
  36. package/lib/module/Date/DayName.js.map +1 -1
  37. package/lib/module/Date/DayNames.js +1 -2
  38. package/lib/module/Date/DayNames.js.map +1 -1
  39. package/lib/module/Date/YearPicker.js +1 -1
  40. package/lib/module/Date/YearPicker.js.map +1 -1
  41. package/lib/module/Time/AmPmSwitcher.js +20 -7
  42. package/lib/module/Time/AmPmSwitcher.js.map +1 -1
  43. package/lib/module/Time/TimeInputs.js +30 -6
  44. package/lib/module/Time/TimeInputs.js.map +1 -1
  45. package/lib/module/Time/TimePicker.js +9 -2
  46. package/lib/module/Time/TimePicker.js.map +1 -1
  47. package/lib/module/Time/TimePickerModal.js +12 -7
  48. package/lib/module/Time/TimePickerModal.js.map +1 -1
  49. package/lib/module/Time/timeUtils.js +5 -40
  50. package/lib/module/Time/timeUtils.js.map +1 -1
  51. package/lib/module/shared/utils.js +1 -1
  52. package/lib/module/shared/utils.js.map +1 -1
  53. package/lib/typescript/Date/CalendarEdit.d.ts.map +1 -1
  54. package/lib/typescript/Date/DayName.d.ts.map +1 -1
  55. package/lib/typescript/Date/DayNames.d.ts.map +1 -1
  56. package/lib/typescript/Time/AmPmSwitcher.d.ts +2 -1
  57. package/lib/typescript/Time/AmPmSwitcher.d.ts.map +1 -1
  58. package/lib/typescript/Time/TimeInputs.d.ts.map +1 -1
  59. package/lib/typescript/Time/TimePicker.d.ts.map +1 -1
  60. package/lib/typescript/Time/TimePickerModal.d.ts.map +1 -1
  61. package/lib/typescript/Time/timeUtils.d.ts.map +1 -1
  62. package/package.json +1 -1
  63. package/src/Date/AnimatedCrossView.tsx +1 -1
  64. package/src/Date/CalendarEdit.tsx +6 -0
  65. package/src/Date/CalendarHeader.tsx +2 -2
  66. package/src/Date/DatePickerModal.tsx +1 -1
  67. package/src/Date/DayName.tsx +1 -2
  68. package/src/Date/DayNames.tsx +4 -2
  69. package/src/Date/YearPicker.tsx +1 -1
  70. package/src/Time/AmPmSwitcher.tsx +27 -7
  71. package/src/Time/TimeInputs.tsx +33 -4
  72. package/src/Time/TimePicker.tsx +20 -13
  73. package/src/Time/TimePickerModal.tsx +10 -7
  74. package/src/Time/timeUtils.ts +13 -44
  75. package/src/shared/utils.ts +1 -1
@@ -13,7 +13,7 @@ function DayName({ label }: { label: string }) {
13
13
  maxFontSizeMultiplier={1.5}
14
14
  style={[
15
15
  styles.dayNameLabel,
16
- { ...textFont, color: theme.colors.onSurface },
16
+ { ...textFont, color: theme.colors.onSurfaceVariant },
17
17
  ]}
18
18
  selectable={false}
19
19
  >
@@ -30,7 +30,6 @@ const styles = StyleSheet.create({
30
30
  },
31
31
  dayNameLabel: {
32
32
  fontSize: 14,
33
- opacity: 0.7,
34
33
  },
35
34
  })
36
35
 
@@ -39,7 +39,10 @@ function DayNames({
39
39
 
40
40
  return (
41
41
  <View
42
- style={[styles.dayNames, { backgroundColor: theme.colors.surface }]}
42
+ style={[
43
+ styles.dayNames,
44
+ { backgroundColor: theme.colors.elevation.level3 },
45
+ ]}
43
46
  pointerEvents="none"
44
47
  >
45
48
  {shortDayNames
@@ -53,7 +56,6 @@ function DayNames({
53
56
  const styles = StyleSheet.create({
54
57
  dayNames: {
55
58
  alignItems: 'center',
56
- backgroundColor: '#fff',
57
59
  flexDirection: 'row',
58
60
  height: dayNamesHeight,
59
61
  },
@@ -44,7 +44,7 @@ export default function YearPicker({
44
44
  style={[
45
45
  StyleSheet.absoluteFill,
46
46
  styles.root,
47
- { backgroundColor: theme.colors.surface },
47
+ { backgroundColor: theme.colors.elevation.level3 },
48
48
  selectingYear ? sharedStyles.opacity1 : sharedStyles.opacity0,
49
49
  ]}
50
50
  pointerEvents={selectingYear ? 'auto' : 'none'}
@@ -9,29 +9,34 @@ export default function AmPmSwitcher({
9
9
  onChange,
10
10
  hours,
11
11
  inputType,
12
+ direction = 'vertical',
12
13
  }: {
13
14
  hours: number
14
15
  onChange: (newHours: number) => any
15
16
  inputType: PossibleInputTypes
17
+ direction?: 'vertical' | 'horizontal'
16
18
  }) {
17
19
  const theme = useTheme()
18
20
 
19
21
  const { setMode, mode } = useContext(DisplayModeContext)
20
22
 
21
23
  const backgroundColor = theme.colors.outline
22
-
24
+ const isHorizontal = direction === 'horizontal'
23
25
  const isAM = mode === 'AM'
24
26
 
27
+ const height = isHorizontal ? 38 : inputType === inputTypes.keyboard ? 72 : 80
28
+
25
29
  return (
26
30
  <View
27
31
  style={[
28
- styles.root,
32
+ isHorizontal ? styles.rootHorizontal : styles.rootVertical,
29
33
  // eslint-disable-next-line react-native/no-inline-styles
30
34
  {
31
35
  borderColor: backgroundColor,
32
36
  borderRadius: theme.roundness * 2,
33
- height: inputType === inputTypes.keyboard ? 72 : 80,
34
- marginBottom: inputType === 'keyboard' ? 16 : 0,
37
+ height,
38
+ marginBottom:
39
+ !isHorizontal && inputType === inputTypes.keyboard ? 16 : 0,
35
40
  },
36
41
  ]}
37
42
  >
@@ -46,7 +51,12 @@ export default function AmPmSwitcher({
46
51
  selected={isAM}
47
52
  disabled={isAM}
48
53
  />
49
- <View style={[styles.switchSeparator, { backgroundColor }]} />
54
+ <View
55
+ style={[
56
+ isHorizontal ? styles.separatorHorizontal : styles.separatorVertical,
57
+ { backgroundColor },
58
+ ]}
59
+ />
50
60
  <SwitchButton
51
61
  label="PM"
52
62
  onPress={() => {
@@ -111,15 +121,25 @@ function SwitchButton({
111
121
  }
112
122
 
113
123
  const styles = StyleSheet.create({
114
- root: {
124
+ rootVertical: {
115
125
  width: 52,
116
126
  borderWidth: 1,
117
127
  overflow: 'hidden',
118
128
  },
119
- switchSeparator: {
129
+ rootHorizontal: {
130
+ width: 216,
131
+ flexDirection: 'row',
132
+ borderWidth: 1,
133
+ overflow: 'hidden',
134
+ },
135
+ separatorVertical: {
120
136
  height: 1,
121
137
  width: 52,
122
138
  },
139
+ separatorHorizontal: {
140
+ width: 1,
141
+ alignSelf: 'stretch',
142
+ },
123
143
  switchButtonInner: {
124
144
  flex: 1,
125
145
  alignItems: 'center',
@@ -8,6 +8,7 @@ import { Text, useTheme } from 'react-native-paper'
8
8
 
9
9
  import {
10
10
  clockTypes,
11
+ inputTypes,
11
12
  PossibleClockTypes,
12
13
  PossibleInputTypes,
13
14
  toHourInputFormat,
@@ -52,6 +53,8 @@ function TimeInputs({
52
53
  const endInput = useRef<TextInputNative | null>(null)
53
54
  const dimensions = useWindowDimensions()
54
55
  const isLandscape = dimensions.width > dimensions.height
56
+ const useHorizontalAmPm =
57
+ !is24Hour && isLandscape && inputType === inputTypes.picker
55
58
  const minutesRef = useLatest(minutes)
56
59
 
57
60
  const onSubmitStartInput = useCallback(() => {
@@ -75,8 +78,8 @@ function TimeInputs({
75
78
  [onChange, minutesRef]
76
79
  )
77
80
 
78
- return (
79
- <View style={[styles.inputContainer, isLandscape && sharedStyles.root]}>
81
+ const hourMinuteRow = (
82
+ <View style={styles.inputContainer}>
80
83
  <View style={styles.column}>
81
84
  <TimeInput
82
85
  ref={startInput}
@@ -178,18 +181,37 @@ function TimeInputs({
178
181
  </Text>
179
182
  ) : null}
180
183
  </View>
181
- {!is24Hour && (
184
+ {!is24Hour && !useHorizontalAmPm ? (
182
185
  <>
183
186
  <View style={styles.spaceBetweenInputsAndSwitcher} />
184
187
  <AmPmSwitcher
185
188
  hours={hours}
186
189
  onChange={onChangeHours}
187
190
  inputType={inputType}
191
+ direction="vertical"
188
192
  />
189
193
  </>
190
- )}
194
+ ) : null}
191
195
  </View>
192
196
  )
197
+
198
+ if (useHorizontalAmPm) {
199
+ return (
200
+ <View style={styles.landscapeColumn}>
201
+ {hourMinuteRow}
202
+ <View style={styles.landscapeSwitcherSpacing}>
203
+ <AmPmSwitcher
204
+ hours={hours}
205
+ onChange={onChangeHours}
206
+ inputType={inputType}
207
+ direction="horizontal"
208
+ />
209
+ </View>
210
+ </View>
211
+ )
212
+ }
213
+
214
+ return hourMinuteRow
193
215
  }
194
216
 
195
217
  const styles = StyleSheet.create({
@@ -213,6 +235,13 @@ const styles = StyleSheet.create({
213
235
  flexDirection: 'row',
214
236
  alignItems: 'center',
215
237
  },
238
+ landscapeColumn: {
239
+ flexDirection: 'column',
240
+ alignItems: 'flex-start',
241
+ },
242
+ landscapeSwitcherSpacing: {
243
+ marginTop: 16,
244
+ },
216
245
  spaceBetweenInputsAndSwitcher: {
217
246
  width: 12,
218
247
  },
@@ -84,6 +84,14 @@ function TimePicker({
84
84
  [onChange, hours, is24Hour]
85
85
  )
86
86
 
87
+ const inputsWidth =
88
+ 96 * 2 +
89
+ 24 +
90
+ (is24Hour || (isLandscape && inputType === inputTypes.picker) ? 0 : 12 + 52)
91
+
92
+ const clockWidth =
93
+ inputType === inputTypes.picker ? circleSize + (isLandscape ? 64 : 0) : 0
94
+
87
95
  return (
88
96
  <DisplayModeContext.Provider
89
97
  value={{ mode: displayMode, setMode: setDisplayMode }}
@@ -91,18 +99,7 @@ function TimePicker({
91
99
  <View
92
100
  style={
93
101
  isLandscape
94
- ? [
95
- styles.rootLandscape,
96
- {
97
- width:
98
- 24 * 3 +
99
- 96 * 2 +
100
- 52 +
101
- (inputType === inputTypes.picker
102
- ? circleSize
103
- : -circleSize),
104
- },
105
- ]
102
+ ? [styles.rootLandscape, { width: inputsWidth + clockWidth }]
106
103
  : styles.rootPortrait
107
104
  }
108
105
  >
@@ -118,7 +115,12 @@ function TimePicker({
118
115
  locale={locale}
119
116
  />
120
117
  {inputType === inputTypes.picker ? (
121
- <View style={styles.clockContainer}>
118
+ <View
119
+ style={[
120
+ styles.clockContainer,
121
+ isLandscape && styles.clockContainerLandscape,
122
+ ]}
123
+ >
122
124
  <AnalogClock
123
125
  hours={toHourInputFormat(hours, is24Hour)}
124
126
  minutes={minutes}
@@ -139,6 +141,11 @@ const styles = StyleSheet.create({
139
141
  paddingLeft: 12,
140
142
  paddingRight: 12,
141
143
  },
144
+ clockContainerLandscape: {
145
+ paddingTop: 0,
146
+ paddingLeft: 64,
147
+ paddingRight: 0,
148
+ },
142
149
  rootLandscape: {
143
150
  flexDirection: 'row',
144
151
  alignItems: 'center',
@@ -104,9 +104,7 @@ export function TimePickerModal({
104
104
  labelText = 'Enter time'
105
105
  }
106
106
 
107
- const color = theme.dark
108
- ? theme.colors.elevation.level3
109
- : theme.colors.surface
107
+ const color = theme.colors.elevation.level3
110
108
 
111
109
  return (
112
110
  <Modal
@@ -140,6 +138,10 @@ export function TimePickerModal({
140
138
  {
141
139
  backgroundColor: color,
142
140
  borderRadius: 28,
141
+ minWidth: inputType === inputTypes.picker ? 328 : 280,
142
+ ...(inputType === inputTypes.keyboard
143
+ ? { height: 252 }
144
+ : null),
143
145
  },
144
146
  ]}
145
147
  >
@@ -172,7 +174,7 @@ export function TimePickerModal({
172
174
  </View>
173
175
  <View style={styles.bottom}>
174
176
  <IconButton
175
- iconColor={theme.colors.onBackground}
177
+ iconColor={theme.colors.onSurface}
176
178
  icon={getTimeInputTypeIcon(inputType, {
177
179
  keyboard: keyboardIcon,
178
180
  picker: clockIcon,
@@ -220,7 +222,8 @@ const styles = StyleSheet.create({
220
222
  bottom: {
221
223
  flexDirection: 'row',
222
224
  alignItems: 'center',
223
- padding: 8,
225
+ paddingHorizontal: 24,
226
+ paddingVertical: 8,
224
227
  },
225
228
  center: {
226
229
  justifyContent: 'center',
@@ -228,7 +231,7 @@ const styles = StyleSheet.create({
228
231
  flex: 1,
229
232
  },
230
233
  inputTypeToggle: {
231
- margin: 4,
234
+ margin: 0,
232
235
  },
233
236
  labelContainer: {
234
237
  justifyContent: 'flex-end',
@@ -249,8 +252,8 @@ const styles = StyleSheet.create({
249
252
  shadowOpacity: 0.34,
250
253
  shadowRadius: 6.27,
251
254
  elevation: 3,
252
- minWidth: 328,
253
255
  paddingVertical: 8,
256
+ justifyContent: 'space-between',
254
257
  },
255
258
  timePickerContainer: {
256
259
  paddingLeft: 24,
@@ -1,4 +1,3 @@
1
- import { useMemo } from 'react'
2
1
  import { useTheme } from 'react-native-paper'
3
2
 
4
3
  export const circleSize = 256
@@ -155,55 +154,25 @@ export function getAngle(left: number, top: number, size: number) {
155
154
 
156
155
  export function useSwitchColors(highlighted: boolean) {
157
156
  const theme = useTheme()
158
- const backgroundColor = useMemo<string>(() => {
159
- if (theme.dark) {
160
- if (highlighted) {
161
- return theme.colors.tertiaryContainer
162
- }
163
- return theme.colors.backdrop
164
- }
165
-
166
- if (highlighted) {
167
- return theme.colors.primaryContainer
168
- }
169
- return theme.colors.surface
170
- }, [highlighted, theme])
171
-
172
- const color = useMemo<string>(() => {
173
- if (highlighted && !theme.dark) {
174
- return theme.colors.onSurfaceVariant
175
- }
176
- if (highlighted && theme.dark) {
177
- return theme.colors.onTertiaryContainer
178
- }
179
- return theme.colors.onSurfaceVariant
180
- }, [highlighted, theme])
157
+ const backgroundColor = highlighted
158
+ ? theme.colors.tertiaryContainer
159
+ : 'transparent'
160
+ const color = highlighted
161
+ ? theme.colors.onTertiaryContainer
162
+ : theme.colors.onSurfaceVariant
181
163
 
182
164
  return { backgroundColor, color }
183
165
  }
184
166
 
185
167
  export function useInputColors(highlighted: boolean) {
186
168
  const theme = useTheme()
187
- const backgroundColor = useMemo<string>(() => {
188
- if (theme.dark) {
189
- if (highlighted) {
190
- return theme.colors.primaryContainer
191
- }
192
- return theme.colors.surfaceVariant
193
- }
194
-
195
- if (highlighted) {
196
- return theme.colors.secondaryContainer
197
- }
198
- return theme.colors.surfaceVariant
199
- }, [highlighted, theme])
200
-
201
- const color = useMemo<string>(() => {
202
- if (!highlighted) {
203
- return theme.colors.onSurface
204
- }
205
- return theme.colors.onPrimaryContainer
206
- }, [highlighted, theme])
169
+ // M3: primaryContainer / surfaceContainerHighest (Paper: surfaceVariant)
170
+ const backgroundColor = highlighted
171
+ ? theme.colors.primaryContainer
172
+ : theme.colors.surfaceVariant
173
+ const color = highlighted
174
+ ? theme.colors.onPrimaryContainer
175
+ : theme.colors.onSurface
207
176
 
208
177
  return { backgroundColor, color }
209
178
  }
@@ -26,7 +26,7 @@ export function useLatest<T>(value: T) {
26
26
 
27
27
  export function useHeaderBackgroundColor() {
28
28
  const theme = useTheme()
29
- return theme.colors.surface
29
+ return theme.colors.elevation.level3
30
30
  }
31
31
 
32
32
  export function useHeaderTextColor() {