Skip to content

Commit bbb086a

Browse files
committed
Clean up code
1 parent f844290 commit bbb086a

18 files changed

+37
-54
lines changed

docusaurus/docs/date-picker/input-date-picker.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ Flag indicating if the text in the component should be uppercase. Defaults to `t
113113

114114
**startYear**
115115
`Type: number | undefined`
116-
The start year when the component is rendered. Defaults to `DEFAULT_START_YEAR` (1800).
116+
The start year when the component is rendered. Defaults to `1800`.
117117

118118
**endYear**
119119
`Type: number | undefined`
120-
The end year when the component is rendered. Defaults to `DEFAULT_END_YEAR` (2200).
120+
The end year when the component is rendered. Defaults to `2200`.
121121

122122
**startWeekOnMonday**
123123
`Type: boolean | undefined`

docusaurus/docs/date-picker/multiple-dates-picker.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ The animation used when opening the component. Defaults to `'slide'` on ios/andr
125125

126126
**startYear**
127127
`Type: number | undefined`
128-
The start year when the component is rendered. Defaults to `DEFAULT_START_YEAR` (1800).
128+
The start year when the component is rendered. Defaults to `1800`.
129129

130130
**endYear**
131131
`Type: number | undefined`
132-
The end year when the component is rendered. Defaults to `DEFAULT_END_YEAR` (2200).
132+
The end year when the component is rendered. Defaults to `2200`.
133133

134134
**startWeekOnMonday**
135135
`Type: boolean | undefined`

docusaurus/docs/date-picker/range-date-picker.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ The animation used when opening the component. Defaults to `'slide'` on ios/andr
128128

129129
**startYear**
130130
`Type: number | undefined`
131-
The start year when the component is rendered. Defaults to `DEFAULT_START_YEAR` (1800).
131+
The start year when the component is rendered. Defaults to `1800`.
132132

133133
**endYear**
134134
`Type: number | undefined`
135-
The end year when the component is rendered. Defaults to `DEFAULT_END_YEAR` (2200).
135+
The end year when the component is rendered. Defaults to `2200`.
136136

137137
**startWeekOnMonday**
138138
`Type: boolean | undefined`

docusaurus/docs/date-picker/single-date-picker.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ The animation used when opening the component. Defaults to `'slide'` on ios/andr
115115

116116
**startYear**
117117
`Type: number | undefined`
118-
The start year when the component is rendered. Defaults to `DEFAULT_START_YEAR` (1800).
118+
The start year when the component is rendered. Defaults to `1800`.
119119

120120
**endYear**
121121
`Type: number | undefined`
122-
The end year when the component is rendered. Defaults to `DEFAULT_END_YEAR` (2200).
122+
The end year when the component is rendered. Defaults to `2200`.
123123

124124
**startWeekOnMonday**
125125
`Type: boolean | undefined`

example/src/ReadMeExampleMultiple.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export default function ReadMeExampleMultiple() {
4242
// startLabel="From" // optional
4343
// endLabel="To" // optional
4444
// animationType="slide" // optional, default is slide on ios/android and none on web
45-
// startYear={2000} // optional, default is DEFAULT_START_YEAR (1800)
46-
// endYear={2100} // optional, default is DEFAULT_END_YEAR (2200)
45+
// startYear={2000} // optional, default is 1800
46+
// endYear={2100} // optional, default is 2200
4747
// startWeekOnMonday={true} // optional, default is false
4848
/>
4949
</>

example/src/ReadMeExampleRange.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export default function ReadMeExampleRange() {
5050
// startLabel="From" // optional
5151
// endLabel="To" // optional
5252
// animationType="slide" // optional, default is slide on ios/android and none on web
53-
// startYear={2000} // optional, default is DEFAULT_START_YEAR (1800)
54-
// endYear={2100} // optional, default is DEFAULT_END_YEAR (2200)
53+
// startYear={2000} // optional, default is 1800
54+
// endYear={2100} // optional, default is 2200
5555
// startWeekOnMonday={true} // optional, default is false
5656
/>
5757
</>

example/src/ReadMeExampleSingle.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export default function ReadMeExampleSingle() {
4141
// uppercase={false} // optional, default is true
4242
// label="Select date" // optional
4343
// animationType="slide" // optional, default is 'slide' on ios/android and 'none' on web
44-
// startYear={2000} // optional, default is DEFAULT_START_YEAR (1800)
45-
// endYear={2100} // optional, default is DEFAULT_END_YEAR (2200)
44+
// startYear={2000} // optional, default is 1800
45+
// endYear={2100} // optional, default is 2200
4646
// startWeekOnMonday={true} // optional, default is false
4747
//
4848
/>

src/Date/Calendar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Color from 'color'
1616
import { useTheme } from 'react-native-paper'
1717
import { darkenBy, lightenBy, useLatest } from '../shared/utils'
1818
import { sharedStyles } from '../shared/styles'
19-
import { DEFAULT_START_YEAR, DEFAULT_END_YEAR } from './constants'
19+
import { defaultStartYear, defaultEndYear } from './dateUtils'
2020

2121
export type ModeType = 'single' | 'range' | 'multiple'
2222

@@ -221,8 +221,8 @@ function Calendar(
221221
selectedYear={selectedYear}
222222
selectingYear={selectingYear}
223223
onPressYear={onPressYear}
224-
startYear={startYear || DEFAULT_START_YEAR}
225-
endYear={endYear || DEFAULT_END_YEAR}
224+
startYear={startYear || defaultStartYear}
225+
endYear={endYear || defaultEndYear}
226226
/>
227227
) : null}
228228
</View>

src/Date/DatePickerInput.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { DatePickerInputProps } from './DatePickerInput.shared'
55
import DatePickerInputWithoutModal from './DatePickerInputWithoutModal'
66
import { Platform, StyleProp, ViewStyle } from 'react-native'
77
import { forwardRef, useCallback, useState } from 'react'
8-
import { DEFAULT_START_YEAR, DEFAULT_END_YEAR } from './constants'
8+
import { defaultStartYear, defaultEndYear } from './dateUtils'
99

1010
function DatePickerInput(
1111
{
@@ -79,8 +79,8 @@ function DatePickerInput(
7979
saveLabel={saveLabel}
8080
saveLabelDisabled={saveLabelDisabled ?? false}
8181
uppercase={uppercase}
82-
startYear={startYear ?? DEFAULT_START_YEAR}
83-
endYear={endYear ?? DEFAULT_END_YEAR}
82+
startYear={startYear ?? defaultStartYear}
83+
endYear={endYear ?? defaultEndYear}
8484
inputEnabled={inputEnabled}
8585
disableStatusBarPadding={disableStatusBarPadding ?? false}
8686
animationType={animationType}

src/Date/SwiperUtils.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
getStartAtIndex,
88
getTotalMonths,
99
} from './dateUtils'
10-
import { DEFAULT_START_YEAR, DEFAULT_END_YEAR } from './constants'
10+
import { defaultStartYear, defaultEndYear } from './dateUtils'
1111

1212
export type RenderProps = {
1313
index: number
@@ -37,7 +37,7 @@ export function getMinIndex(startYear?: number, endYear?: number): number {
3737
const dynamicStartAtIndex = getStartAtIndex(startYear, endYear)
3838
const minIndex = dynamicStartAtIndex + months
3939
const totalMonths = getTotalMonths(startYear, endYear)
40-
40+
4141
// Allow any valid index within the dynamic range, no hard minimum
4242
return Math.max(0, Math.min(minIndex, totalMonths - 1))
4343
}
@@ -46,14 +46,14 @@ export function getMinIndex(startYear?: number, endYear?: number): number {
4646
export function getMaxIndex(startYear?: number, endYear?: number): number {
4747
const dynamicStartAtIndex = getStartAtIndex(startYear, endYear)
4848
const totalMonths = getTotalMonths(startYear, endYear)
49-
49+
5050
if (!endYear) return totalMonths - 1
5151

5252
const today = new Date()
5353
const endDate = new Date(endYear, 11, 31) // December 31st of endYear
5454
const months = differenceInMonths(today, endDate)
5555
const maxIndex = dynamicStartAtIndex + months
56-
56+
5757
// Allow any valid index within the dynamic range
5858
return Math.max(0, Math.min(maxIndex, totalMonths - 1))
5959
}
@@ -64,8 +64,8 @@ export function isIndexWithinRange(
6464
startYear?: number,
6565
endYear?: number
6666
): boolean {
67-
const minIndex = getMinIndex(startYear || DEFAULT_START_YEAR, endYear)
68-
const maxIndex = getMaxIndex(startYear, endYear || DEFAULT_END_YEAR)
67+
const minIndex = getMinIndex(startYear || defaultStartYear, endYear)
68+
const maxIndex = getMaxIndex(startYear, endYear || defaultEndYear)
6969
return index >= minIndex && index <= maxIndex
7070
}
7171

0 commit comments

Comments
 (0)