react-native-paper-dates 0.22.45 → 0.22.47
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.
|
@@ -90,7 +90,9 @@ function Swiper({
|
|
|
90
90
|
}), renderFooter && renderFooter(renderProps)]
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
|
-
const visibleArray = i =>
|
|
93
|
+
const visibleArray = i => {
|
|
94
|
+
return [i - 2, i - 1, i, i + 1, i + 2];
|
|
95
|
+
};
|
|
94
96
|
function VerticalScroller({
|
|
95
97
|
width,
|
|
96
98
|
height,
|
|
@@ -101,9 +103,12 @@ function VerticalScroller({
|
|
|
101
103
|
startYear,
|
|
102
104
|
endYear
|
|
103
105
|
}) {
|
|
106
|
+
// Provide default values for startYear and endYear
|
|
107
|
+
const effectiveStartYear = startYear || 1800;
|
|
108
|
+
const effectiveEndYear = endYear || 2200;
|
|
104
109
|
// Ensure initial index is within allowed range
|
|
105
|
-
const constrainedInitialIndex = (0, _SwiperUtils.isIndexWithinRange)(initialIndex,
|
|
106
|
-
const [visibleIndexes, setVisibleIndexes] = (0, _react.useState)(visibleArray(constrainedInitialIndex));
|
|
110
|
+
const constrainedInitialIndex = (0, _SwiperUtils.isIndexWithinRange)(initialIndex, effectiveStartYear, effectiveEndYear) ? initialIndex : Math.max(Math.min(initialIndex, (0, _SwiperUtils.getMaxIndex)(effectiveEndYear)), (0, _SwiperUtils.getMinIndex)(effectiveStartYear));
|
|
111
|
+
const [visibleIndexes, setVisibleIndexes] = (0, _react.useState)(() => visibleArray(constrainedInitialIndex));
|
|
107
112
|
const idx = (0, _react.useRef)(constrainedInitialIndex);
|
|
108
113
|
const parentRef = (0, _react.useRef)(null);
|
|
109
114
|
useIsomorphicLayoutEffect(() => {
|
|
@@ -111,7 +116,7 @@ function VerticalScroller({
|
|
|
111
116
|
if (!element) {
|
|
112
117
|
return;
|
|
113
118
|
}
|
|
114
|
-
const top = (0, _Month.getVerticalMonthsOffset)(idx.current, startWeekOnMonday) - _Month.montHeaderHeight;
|
|
119
|
+
const top = (0, _Month.getVerticalMonthsOffset)(idx.current, startWeekOnMonday, effectiveStartYear, effectiveEndYear) - _Month.montHeaderHeight;
|
|
115
120
|
element.scrollTo({
|
|
116
121
|
top
|
|
117
122
|
});
|
|
@@ -122,18 +127,19 @@ function VerticalScroller({
|
|
|
122
127
|
if (top === 0) {
|
|
123
128
|
return;
|
|
124
129
|
}
|
|
125
|
-
const
|
|
126
|
-
const
|
|
130
|
+
const dynamicBeginOffset = (0, _dateUtils.getBeginOffset)(effectiveStartYear, effectiveEndYear);
|
|
131
|
+
const offset = top - dynamicBeginOffset;
|
|
132
|
+
const index = (0, _Month.getIndexFromVerticalOffset)(offset, startWeekOnMonday, effectiveStartYear, effectiveEndYear);
|
|
127
133
|
|
|
128
134
|
// Check if the new index is within allowed range
|
|
129
|
-
if (!(0, _SwiperUtils.isIndexWithinRange)(index,
|
|
135
|
+
if (!(0, _SwiperUtils.isIndexWithinRange)(index, effectiveStartYear, effectiveEndYear)) {
|
|
130
136
|
return;
|
|
131
137
|
}
|
|
132
138
|
if (idx.current !== index) {
|
|
133
139
|
idx.current = index;
|
|
134
140
|
setVisibleIndexesThrottled(visibleArray(index));
|
|
135
141
|
}
|
|
136
|
-
}, [setVisibleIndexesThrottled, startWeekOnMonday,
|
|
142
|
+
}, [setVisibleIndexesThrottled, startWeekOnMonday, effectiveStartYear, effectiveEndYear]);
|
|
137
143
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
138
144
|
ref: parentRef
|
|
139
145
|
// eslint-disable-next-line react-native/no-inline-styles
|
|
@@ -147,25 +153,31 @@ function VerticalScroller({
|
|
|
147
153
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
148
154
|
// eslint-disable-next-line react-native/no-inline-styles
|
|
149
155
|
style: {
|
|
150
|
-
height: estimatedHeight * _dateUtils.
|
|
156
|
+
height: estimatedHeight * (0, _dateUtils.getTotalMonths)(effectiveStartYear, effectiveEndYear),
|
|
151
157
|
position: 'relative'
|
|
152
158
|
},
|
|
153
|
-
children: [0, 1, 2, 3, 4].map(vi =>
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
159
|
+
children: [0, 1, 2, 3, 4].map(vi => {
|
|
160
|
+
const monthIndex = visibleIndexes[vi];
|
|
161
|
+
if (monthIndex === undefined) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
165
|
+
// eslint-disable-next-line react-native/no-inline-styles
|
|
166
|
+
style: {
|
|
167
|
+
willChange: 'transform',
|
|
168
|
+
transform: `translateY(${(0, _Month.getVerticalMonthsOffset)(monthIndex, startWeekOnMonday, effectiveStartYear, effectiveEndYear)}px)`,
|
|
169
|
+
left: 0,
|
|
170
|
+
right: 0,
|
|
171
|
+
position: 'absolute',
|
|
172
|
+
height: (0, _Month.getMonthHeight)('vertical', monthIndex, startWeekOnMonday, effectiveStartYear, effectiveEndYear)
|
|
173
|
+
},
|
|
174
|
+
children: renderItem({
|
|
175
|
+
index: monthIndex,
|
|
176
|
+
onPrev: empty,
|
|
177
|
+
onNext: empty
|
|
178
|
+
})
|
|
179
|
+
}, vi);
|
|
180
|
+
}).filter(item => item !== null)
|
|
169
181
|
})
|
|
170
182
|
});
|
|
171
183
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_Month","_dateUtils","_utils","_SwiperUtils","_AutoSizer","_interopRequireDefault","_react","_styles","_jsxRuntime","e","__esModule","default","useIsomorphicLayoutEffect","window","useLayoutEffect","useEffect","Swiper","scrollMode","renderItem","renderHeader","renderFooter","selectedYear","initialIndex","startWeekOnMonday","startYear","endYear","isHorizontal","index","setIndex","useState","onPrev","useCallback","prev","newIndex","isIndexWithinRange","onNext","renderProps","indexRef","useLatest","useYearChange","currentIndexRef","jsxs","Fragment","children","jsx","View","style","sharedStyles","root","width","height","VerticalScroller","estimatedHeight","estimatedMonthHeight","visibleArray","i","constrainedInitialIndex","Math","max","min","getMaxIndex","getMinIndex","visibleIndexes","setVisibleIndexes","idx","useRef","parentRef","element","current","top","getVerticalMonthsOffset","montHeaderHeight","scrollTo","setVisibleIndexesThrottled","useDebouncedCallback","onScroll","currentTarget","scrollTop","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_Month","_dateUtils","_utils","_SwiperUtils","_AutoSizer","_interopRequireDefault","_react","_styles","_jsxRuntime","e","__esModule","default","useIsomorphicLayoutEffect","window","useLayoutEffect","useEffect","Swiper","scrollMode","renderItem","renderHeader","renderFooter","selectedYear","initialIndex","startWeekOnMonday","startYear","endYear","isHorizontal","index","setIndex","useState","onPrev","useCallback","prev","newIndex","isIndexWithinRange","onNext","renderProps","indexRef","useLatest","useYearChange","currentIndexRef","jsxs","Fragment","children","jsx","View","style","sharedStyles","root","width","height","VerticalScroller","estimatedHeight","estimatedMonthHeight","visibleArray","i","effectiveStartYear","effectiveEndYear","constrainedInitialIndex","Math","max","min","getMaxIndex","getMinIndex","visibleIndexes","setVisibleIndexes","idx","useRef","parentRef","element","current","top","getVerticalMonthsOffset","montHeaderHeight","scrollTo","setVisibleIndexesThrottled","useDebouncedCallback","onScroll","currentTarget","scrollTop","dynamicBeginOffset","getBeginOffset","offset","getIndexFromVerticalOffset","ref","overflow","getTotalMonths","position","map","vi","monthIndex","undefined","willChange","transform","left","right","getMonthHeight","empty","filter","item","callback","mounted","timerId","latest","cancelAnimationFrame","args","requestAnimationFrame","_default","exports","memo"],"sourceRoot":"../../../src","sources":["Date/Swiper.tsx"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAMA,IAA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G,IAAAnC,aAAM,EAAM,IAAI,CAAC;EACjC,MAAMoC,MAAM,GAAG,IAAAjE,gBAAS,EAAC8D,QAAQ,CAAC;EAElC,IAAArF,gBAAS,EAAC,MAAM;IACd,OAAO,MAAM;MACXsF,OAAO,CAAC/B,OAAO,GAAG,KAAK;MACvB,IAAIgC,OAAO,CAAChC,OAAO,EAAE;QACnBzD,MAAM,CAAC2F,oBAAoB,CAACF,OAAO,CAAChC,OAAO,CAAC;MAC9C;IACF,CAAC;EACH,CAAC,EAAE,CAAC+B,OAAO,EAAEC,OAAO,CAAC,CAAC;EAEtB,OAAO,IAAAvE,kBAAW,EACf0E,IAAS,IAAK;IACb,IAAIH,OAAO,CAAChC,OAAO,EAAE;MACnBzD,MAAM,CAAC2F,oBAAoB,CAACF,OAAO,CAAChC,OAAO,CAAC;IAC9C;IACAgC,OAAO,CAAChC,OAAO,GAAGzD,MAAM,CAAC6F,qBAAqB,CAAC,YAAY;MACzD,IAAIL,OAAO,CAAC/B,OAAO,EAAE;QACnBiC,MAAM,CAACjC,OAAO,CAACmC,IAAI,CAAC;MACtB;IACF,CAAC,CAAC;EACJ,CAAC,EACD,CAACJ,OAAO,EAAEC,OAAO,EAAEC,MAAM,CAC3B,CAAC;AACH;AAAC,IAAAI,QAAA,GAAAC,OAAA,CAAAjG,OAAA,gBAEc,IAAAkG,WAAI,EAAC7F,MAAM,CAAC","ignoreList":[]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { View } from 'react-native';
|
|
4
4
|
import { getIndexFromVerticalOffset, getMonthHeight, getVerticalMonthsOffset, montHeaderHeight } from './Month';
|
|
5
|
-
import {
|
|
5
|
+
import { getBeginOffset, estimatedMonthHeight, getTotalMonths } from './dateUtils';
|
|
6
6
|
import { useLatest } from '../shared/utils';
|
|
7
7
|
import { useYearChange, isIndexWithinRange, getMinIndex, getMaxIndex } from './SwiperUtils';
|
|
8
8
|
import AutoSizer from './AutoSizer';
|
|
@@ -84,7 +84,9 @@ function Swiper({
|
|
|
84
84
|
}), renderFooter && renderFooter(renderProps)]
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
|
-
const visibleArray = i =>
|
|
87
|
+
const visibleArray = i => {
|
|
88
|
+
return [i - 2, i - 1, i, i + 1, i + 2];
|
|
89
|
+
};
|
|
88
90
|
function VerticalScroller({
|
|
89
91
|
width,
|
|
90
92
|
height,
|
|
@@ -95,9 +97,12 @@ function VerticalScroller({
|
|
|
95
97
|
startYear,
|
|
96
98
|
endYear
|
|
97
99
|
}) {
|
|
100
|
+
// Provide default values for startYear and endYear
|
|
101
|
+
const effectiveStartYear = startYear || 1800;
|
|
102
|
+
const effectiveEndYear = endYear || 2200;
|
|
98
103
|
// Ensure initial index is within allowed range
|
|
99
|
-
const constrainedInitialIndex = isIndexWithinRange(initialIndex,
|
|
100
|
-
const [visibleIndexes, setVisibleIndexes] = useState(visibleArray(constrainedInitialIndex));
|
|
104
|
+
const constrainedInitialIndex = isIndexWithinRange(initialIndex, effectiveStartYear, effectiveEndYear) ? initialIndex : Math.max(Math.min(initialIndex, getMaxIndex(effectiveEndYear)), getMinIndex(effectiveStartYear));
|
|
105
|
+
const [visibleIndexes, setVisibleIndexes] = useState(() => visibleArray(constrainedInitialIndex));
|
|
101
106
|
const idx = useRef(constrainedInitialIndex);
|
|
102
107
|
const parentRef = useRef(null);
|
|
103
108
|
useIsomorphicLayoutEffect(() => {
|
|
@@ -105,7 +110,7 @@ function VerticalScroller({
|
|
|
105
110
|
if (!element) {
|
|
106
111
|
return;
|
|
107
112
|
}
|
|
108
|
-
const top = getVerticalMonthsOffset(idx.current, startWeekOnMonday) - montHeaderHeight;
|
|
113
|
+
const top = getVerticalMonthsOffset(idx.current, startWeekOnMonday, effectiveStartYear, effectiveEndYear) - montHeaderHeight;
|
|
109
114
|
element.scrollTo({
|
|
110
115
|
top
|
|
111
116
|
});
|
|
@@ -116,18 +121,19 @@ function VerticalScroller({
|
|
|
116
121
|
if (top === 0) {
|
|
117
122
|
return;
|
|
118
123
|
}
|
|
119
|
-
const
|
|
120
|
-
const
|
|
124
|
+
const dynamicBeginOffset = getBeginOffset(effectiveStartYear, effectiveEndYear);
|
|
125
|
+
const offset = top - dynamicBeginOffset;
|
|
126
|
+
const index = getIndexFromVerticalOffset(offset, startWeekOnMonday, effectiveStartYear, effectiveEndYear);
|
|
121
127
|
|
|
122
128
|
// Check if the new index is within allowed range
|
|
123
|
-
if (!isIndexWithinRange(index,
|
|
129
|
+
if (!isIndexWithinRange(index, effectiveStartYear, effectiveEndYear)) {
|
|
124
130
|
return;
|
|
125
131
|
}
|
|
126
132
|
if (idx.current !== index) {
|
|
127
133
|
idx.current = index;
|
|
128
134
|
setVisibleIndexesThrottled(visibleArray(index));
|
|
129
135
|
}
|
|
130
|
-
}, [setVisibleIndexesThrottled, startWeekOnMonday,
|
|
136
|
+
}, [setVisibleIndexesThrottled, startWeekOnMonday, effectiveStartYear, effectiveEndYear]);
|
|
131
137
|
return /*#__PURE__*/_jsx("div", {
|
|
132
138
|
ref: parentRef
|
|
133
139
|
// eslint-disable-next-line react-native/no-inline-styles
|
|
@@ -141,25 +147,31 @@ function VerticalScroller({
|
|
|
141
147
|
children: /*#__PURE__*/_jsx("div", {
|
|
142
148
|
// eslint-disable-next-line react-native/no-inline-styles
|
|
143
149
|
style: {
|
|
144
|
-
height: estimatedHeight *
|
|
150
|
+
height: estimatedHeight * getTotalMonths(effectiveStartYear, effectiveEndYear),
|
|
145
151
|
position: 'relative'
|
|
146
152
|
},
|
|
147
|
-
children: [0, 1, 2, 3, 4].map(vi =>
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
153
|
+
children: [0, 1, 2, 3, 4].map(vi => {
|
|
154
|
+
const monthIndex = visibleIndexes[vi];
|
|
155
|
+
if (monthIndex === undefined) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
return /*#__PURE__*/_jsx("div", {
|
|
159
|
+
// eslint-disable-next-line react-native/no-inline-styles
|
|
160
|
+
style: {
|
|
161
|
+
willChange: 'transform',
|
|
162
|
+
transform: `translateY(${getVerticalMonthsOffset(monthIndex, startWeekOnMonday, effectiveStartYear, effectiveEndYear)}px)`,
|
|
163
|
+
left: 0,
|
|
164
|
+
right: 0,
|
|
165
|
+
position: 'absolute',
|
|
166
|
+
height: getMonthHeight('vertical', monthIndex, startWeekOnMonday, effectiveStartYear, effectiveEndYear)
|
|
167
|
+
},
|
|
168
|
+
children: renderItem({
|
|
169
|
+
index: monthIndex,
|
|
170
|
+
onPrev: empty,
|
|
171
|
+
onNext: empty
|
|
172
|
+
})
|
|
173
|
+
}, vi);
|
|
174
|
+
}).filter(item => item !== null)
|
|
163
175
|
})
|
|
164
176
|
});
|
|
165
177
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["View","getIndexFromVerticalOffset","getMonthHeight","getVerticalMonthsOffset","montHeaderHeight","
|
|
1
|
+
{"version":3,"names":["View","getIndexFromVerticalOffset","getMonthHeight","getVerticalMonthsOffset","montHeaderHeight","getBeginOffset","estimatedMonthHeight","getTotalMonths","useLatest","useYearChange","isIndexWithinRange","getMinIndex","getMaxIndex","AutoSizer","memo","useCallback","useEffect","useLayoutEffect","useRef","useState","sharedStyles","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","useIsomorphicLayoutEffect","window","Swiper","scrollMode","renderItem","renderHeader","renderFooter","selectedYear","initialIndex","startWeekOnMonday","startYear","endYear","isHorizontal","index","setIndex","onPrev","prev","newIndex","onNext","renderProps","indexRef","currentIndexRef","children","style","root","width","height","VerticalScroller","estimatedHeight","visibleArray","i","effectiveStartYear","effectiveEndYear","constrainedInitialIndex","Math","max","min","visibleIndexes","setVisibleIndexes","idx","parentRef","element","current","top","scrollTo","setVisibleIndexesThrottled","useDebouncedCallback","onScroll","e","currentTarget","scrollTop","dynamicBeginOffset","offset","ref","overflow","position","map","vi","monthIndex","undefined","willChange","transform","left","right","empty","filter","item","callback","mounted","timerId","latest","cancelAnimationFrame","args","requestAnimationFrame"],"sourceRoot":"../../../src","sources":["Date/Swiper.tsx"],"mappings":";;AAAA,SAASA,IAAI,QAAQ,cAAc;AACnC,SACEC,0BAA0B,EAC1BC,cAAc,EACdC,uBAAuB,EACvBC,gBAAgB,QACX,SAAS;AAChB,SACEC,cAAc,EACdC,oBAAoB,EACpBC,cAAc,QACT,aAAa;AACpB,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAGEC,aAAa,EACbC,kBAAkB,EAClBC,WAAW,EACXC,WAAW,QACN,eAAe;AACtB,OAAOC,SAAS,MAAM,aAAa;AACnC,SACEC,IAAI,EAEJC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,MAAM,EACNC,QAAQ,QACH,OAAO;AACd,SAASC,YAAY,QAAQ,kBAAkB;AAAA,SAAAC,GAAA,IAAAC,IAAA,EAAAC,QAAA,IAAAC,SAAA,EAAAC,IAAA,IAAAC,KAAA;AAE/C,MAAMC,yBAAyB,GAC7B,OAAOC,MAAM,KAAK,WAAW,GAAGX,eAAe,GAAGD,SAAS;AAE7D,SAASa,MAAMA,CAAC;EACdC,UAAU;EACVC,UAAU;EACVC,YAAY;EACZC,YAAY;EACZC,YAAY;EACZC,YAAY;EACZC,iBAAiB;EACjBC,SAAS;EACTC;AACW,CAAC,EAAE;EACd,MAAMC,YAAY,GAAGT,UAAU,KAAK,YAAY;EAEhD,MAAM,CAACU,KAAK,EAAEC,QAAQ,CAAC,GAAGtB,QAAQ,CAACgB,YAAY,CAAC;EAEhD,MAAMO,MAAM,GAAG3B,WAAW,CAAC,MAAM;IAC/B0B,QAAQ,CAAEE,IAAI,IAAK;MACjB,MAAMC,QAAQ,GAAGD,IAAI,GAAG,CAAC;MACzB;MACA,IAAIjC,kBAA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;EACvD,MAAMC,OAAO,GAAG7E,MAAM,CAAU,IAAI,CAAC;EACrC,MAAM8E,OAAO,GAAG9E,MAAM,CAAM,IAAI,CAAC;EACjC,MAAM+E,MAAM,GAAGzF,SAAS,CAACsF,QAAQ,CAAC;EAElC9E,SAAS,CAAC,MAAM;IACd,OAAO,MAAM;MACX+E,OAAO,CAAC1B,OAAO,GAAG,KAAK;MACvB,IAAI2B,OAAO,CAAC3B,OAAO,EAAE;QACnBzC,MAAM,CAACsE,oBAAoB,CAACF,OAAO,CAAC3B,OAAO,CAAC;MAC9C;IACF,CAAC;EACH,CAAC,EAAE,CAAC0B,OAAO,EAAEC,OAAO,CAAC,CAAC;EAEtB,OAAOjF,WAAW,CACfoF,IAAS,IAAK;IACb,IAAIH,OAAO,CAAC3B,OAAO,EAAE;MACnBzC,MAAM,CAACsE,oBAAoB,CAACF,OAAO,CAAC3B,OAAO,CAAC;IAC9C;IACA2B,OAAO,CAAC3B,OAAO,GAAGzC,MAAM,CAACwE,qBAAqB,CAAC,YAAY;MACzD,IAAIL,OAAO,CAAC1B,OAAO,EAAE;QACnB4B,MAAM,CAAC5B,OAAO,CAAC8B,IAAI,CAAC;MACtB;IACF,CAAC,CAAC;EACJ,CAAC,EACD,CAACJ,OAAO,EAAEC,OAAO,EAAEC,MAAM,CAC3B,CAAC;AACH;AAEA,4BAAenF,IAAI,CAACe,MAAM,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Swiper.d.ts","sourceRoot":"","sources":["../../../src/Date/Swiper.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Swiper.d.ts","sourceRoot":"","sources":["../../../src/Date/Swiper.tsx"],"names":[],"mappings":"AAaA,OAAO,EAEL,WAAW,EAKZ,MAAM,eAAe,CAAA;AAgBtB,iBAAS,MAAM,CAAC,EACd,UAAU,EACV,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,OAAO,GACR,EAAE,WAAW,2CAyEb;AA4KD,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG,CA2BvD;;AAED,wBAA2B"}
|
package/package.json
CHANGED
|
@@ -1,59 +1,21 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "react-native-paper-dates",
|
|
3
|
-
"version": "0.22.45",
|
|
4
|
-
"description": "Performant Date Picker for React Native Paper",
|
|
5
|
-
"main": "lib/commonjs/index",
|
|
6
|
-
"module": "lib/module/index",
|
|
7
|
-
"types": "lib/typescript/index.d.ts",
|
|
8
|
-
"react-native": "src/index",
|
|
9
|
-
"source": "src/index",
|
|
10
|
-
"files": [
|
|
11
|
-
"src",
|
|
12
|
-
"lib",
|
|
13
|
-
"android",
|
|
14
|
-
"ios",
|
|
15
|
-
"cpp",
|
|
16
|
-
"react-native-paper-dates.podspec",
|
|
17
|
-
"!lib/typescript/example",
|
|
18
|
-
"!android/build",
|
|
19
|
-
"!ios/build",
|
|
20
|
-
"!**/__tests__",
|
|
21
|
-
"!**/__fixtures__",
|
|
22
|
-
"!**/__mocks__"
|
|
23
|
-
],
|
|
24
|
-
"scripts": {
|
|
25
|
-
"test": "jest --config=jest.config.js --watchAll=false",
|
|
26
|
-
"test-watch": "jest --config=jest.config.js --watchAll",
|
|
27
|
-
"typecheck": "tsc --noEmit",
|
|
28
|
-
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
29
|
-
"prepare": "husky install && bob build",
|
|
30
|
-
"release": "release-it --ci --github.autoGenerate",
|
|
31
|
-
"example": "yarn --cwd example",
|
|
32
|
-
"pods": "cd example && pod-install --quiet",
|
|
33
|
-
"bootstrap": "yarn example && yarn && yarn pods",
|
|
34
|
-
"prepack": "bob build",
|
|
35
|
-
"build-example": "cd example && npx expo export:web"
|
|
36
|
-
},
|
|
37
|
-
"keywords": [
|
|
38
|
-
"react-native",
|
|
39
|
-
"ios",
|
|
40
|
-
"android"
|
|
41
|
-
],
|
|
42
|
-
"repository": "https://github.com/web-ridge/react-native-paper-dates",
|
|
43
2
|
"author": "Richard Lindhout <info@webridge.nl> (https://github.com/web-ridge)",
|
|
44
|
-
"license": "MIT",
|
|
45
3
|
"bugs": {
|
|
46
4
|
"url": "https://github.com/web-ridge/react-native-paper-dates/issues"
|
|
47
5
|
},
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
6
|
+
"commitlint": {
|
|
7
|
+
"extends": [
|
|
8
|
+
"@commitlint/config-conventional"
|
|
9
|
+
]
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"color": "^4.2.3"
|
|
51
13
|
},
|
|
14
|
+
"description": "Performant Date Picker for React Native Paper",
|
|
52
15
|
"devDependencies": {
|
|
53
16
|
"@commitlint/config-conventional": "^19.8.0",
|
|
54
17
|
"@react-native-community/eslint-config": "^3.2.0",
|
|
55
|
-
"@react-native-vector-icons/
|
|
56
|
-
"@react-native-vector-icons/material-design-icons": "^7.4.47",
|
|
18
|
+
"@react-native-vector-icons/material-design-icons": "^12.0.0",
|
|
57
19
|
"@react-native/babel-preset": "^0.79.2",
|
|
58
20
|
"@release-it/conventional-changelog": "^10.0.1",
|
|
59
21
|
"@testing-library/react-native": "^13.2.0",
|
|
@@ -79,45 +41,10 @@
|
|
|
79
41
|
"react-native-builder-bob": "^0.40.0",
|
|
80
42
|
"react-native-paper": "^5.14.0",
|
|
81
43
|
"react-native-safe-area-context": "^5.4.0",
|
|
82
|
-
"react-native-vector-icons": "^10.2.0",
|
|
83
44
|
"react-test-renderer": "~19.0.0",
|
|
84
45
|
"release-it": "^19.0.1",
|
|
85
46
|
"typescript": "~5.8.3"
|
|
86
47
|
},
|
|
87
|
-
"peerDependencies": {
|
|
88
|
-
"react": "*",
|
|
89
|
-
"react-native": "*",
|
|
90
|
-
"react-native-paper": "*",
|
|
91
|
-
"react-native-safe-area-context": "*"
|
|
92
|
-
},
|
|
93
|
-
"husky": {
|
|
94
|
-
"hooks": {
|
|
95
|
-
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
|
|
96
|
-
"pre-commit": "yarn lint && yarn typecheck"
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
"commitlint": {
|
|
100
|
-
"extends": [
|
|
101
|
-
"@commitlint/config-conventional"
|
|
102
|
-
]
|
|
103
|
-
},
|
|
104
|
-
"release-it": {
|
|
105
|
-
"git": {
|
|
106
|
-
"commitMessage": "chore: release ${version}",
|
|
107
|
-
"tagName": "v${version}"
|
|
108
|
-
},
|
|
109
|
-
"npm": {
|
|
110
|
-
"publish": true
|
|
111
|
-
},
|
|
112
|
-
"github": {
|
|
113
|
-
"release": true
|
|
114
|
-
},
|
|
115
|
-
"plugins": {
|
|
116
|
-
"@release-it/conventional-changelog": {
|
|
117
|
-
"preset": "angular"
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
48
|
"eslintConfig": {
|
|
122
49
|
"root": true,
|
|
123
50
|
"extends": [
|
|
@@ -147,6 +74,42 @@
|
|
|
147
74
|
"docusaurus",
|
|
148
75
|
"coverage"
|
|
149
76
|
],
|
|
77
|
+
"files": [
|
|
78
|
+
"src",
|
|
79
|
+
"lib",
|
|
80
|
+
"android",
|
|
81
|
+
"ios",
|
|
82
|
+
"cpp",
|
|
83
|
+
"react-native-paper-dates.podspec",
|
|
84
|
+
"!lib/typescript/example",
|
|
85
|
+
"!android/build",
|
|
86
|
+
"!ios/build",
|
|
87
|
+
"!**/__tests__",
|
|
88
|
+
"!**/__fixtures__",
|
|
89
|
+
"!**/__mocks__"
|
|
90
|
+
],
|
|
91
|
+
"homepage": "https://github.com/web-ridge/react-native-paper-dates#readme",
|
|
92
|
+
"husky": {
|
|
93
|
+
"hooks": {
|
|
94
|
+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
|
|
95
|
+
"pre-commit": "yarn lint && yarn typecheck"
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
"keywords": [
|
|
99
|
+
"react-native",
|
|
100
|
+
"ios",
|
|
101
|
+
"android"
|
|
102
|
+
],
|
|
103
|
+
"license": "MIT",
|
|
104
|
+
"main": "lib/commonjs/index",
|
|
105
|
+
"module": "lib/module/index",
|
|
106
|
+
"name": "react-native-paper-dates",
|
|
107
|
+
"peerDependencies": {
|
|
108
|
+
"react": "*",
|
|
109
|
+
"react-native": "*",
|
|
110
|
+
"react-native-paper": "*",
|
|
111
|
+
"react-native-safe-area-context": "*"
|
|
112
|
+
},
|
|
150
113
|
"prettier": {
|
|
151
114
|
"quoteProps": "consistent",
|
|
152
115
|
"singleQuote": true,
|
|
@@ -155,6 +118,10 @@
|
|
|
155
118
|
"useTabs": false,
|
|
156
119
|
"semi": false
|
|
157
120
|
},
|
|
121
|
+
"publishConfig": {
|
|
122
|
+
"registry": "https://registry.npmjs.org/"
|
|
123
|
+
},
|
|
124
|
+
"react-native": "src/index",
|
|
158
125
|
"react-native-builder-bob": {
|
|
159
126
|
"source": "src",
|
|
160
127
|
"output": "lib",
|
|
@@ -170,7 +137,38 @@
|
|
|
170
137
|
]
|
|
171
138
|
]
|
|
172
139
|
},
|
|
173
|
-
"
|
|
174
|
-
"
|
|
175
|
-
|
|
140
|
+
"release-it": {
|
|
141
|
+
"git": {
|
|
142
|
+
"commitMessage": "chore: release ${version}",
|
|
143
|
+
"tagName": "v${version}"
|
|
144
|
+
},
|
|
145
|
+
"npm": {
|
|
146
|
+
"publish": true
|
|
147
|
+
},
|
|
148
|
+
"github": {
|
|
149
|
+
"release": true
|
|
150
|
+
},
|
|
151
|
+
"plugins": {
|
|
152
|
+
"@release-it/conventional-changelog": {
|
|
153
|
+
"preset": "angular"
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
"repository": "https://github.com/web-ridge/react-native-paper-dates",
|
|
158
|
+
"scripts": {
|
|
159
|
+
"test": "jest --config=jest.config.js --watchAll=false",
|
|
160
|
+
"test-watch": "jest --config=jest.config.js --watchAll",
|
|
161
|
+
"typecheck": "tsc --noEmit",
|
|
162
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
163
|
+
"prepare": "husky install && bob build",
|
|
164
|
+
"release": "release-it --ci --github.autoGenerate",
|
|
165
|
+
"example": "yarn --cwd example",
|
|
166
|
+
"pods": "cd example && pod-install --quiet",
|
|
167
|
+
"bootstrap": "yarn example && yarn && yarn pods",
|
|
168
|
+
"prepack": "bob build",
|
|
169
|
+
"build-example": "cd example && npx expo export:web"
|
|
170
|
+
},
|
|
171
|
+
"source": "src/index",
|
|
172
|
+
"types": "lib/typescript/index.d.ts",
|
|
173
|
+
"version": "0.22.47"
|
|
176
174
|
}
|
package/src/Date/Swiper.tsx
CHANGED
|
@@ -5,7 +5,11 @@ import {
|
|
|
5
5
|
getVerticalMonthsOffset,
|
|
6
6
|
montHeaderHeight,
|
|
7
7
|
} from './Month'
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
getBeginOffset,
|
|
10
|
+
estimatedMonthHeight,
|
|
11
|
+
getTotalMonths,
|
|
12
|
+
} from './dateUtils'
|
|
9
13
|
import { useLatest } from '../shared/utils'
|
|
10
14
|
import {
|
|
11
15
|
RenderProps,
|
|
@@ -115,7 +119,9 @@ function Swiper({
|
|
|
115
119
|
)
|
|
116
120
|
}
|
|
117
121
|
|
|
118
|
-
const visibleArray = (i: number) =>
|
|
122
|
+
const visibleArray = (i: number) => {
|
|
123
|
+
return [i - 2, i - 1, i, i + 1, i + 2]
|
|
124
|
+
}
|
|
119
125
|
|
|
120
126
|
function VerticalScroller({
|
|
121
127
|
width,
|
|
@@ -136,19 +142,22 @@ function VerticalScroller({
|
|
|
136
142
|
startYear?: number
|
|
137
143
|
endYear?: number
|
|
138
144
|
}) {
|
|
145
|
+
// Provide default values for startYear and endYear
|
|
146
|
+
const effectiveStartYear = startYear || 1800
|
|
147
|
+
const effectiveEndYear = endYear || 2200
|
|
139
148
|
// Ensure initial index is within allowed range
|
|
140
149
|
const constrainedInitialIndex = isIndexWithinRange(
|
|
141
150
|
initialIndex,
|
|
142
|
-
|
|
143
|
-
|
|
151
|
+
effectiveStartYear,
|
|
152
|
+
effectiveEndYear
|
|
144
153
|
)
|
|
145
154
|
? initialIndex
|
|
146
155
|
: Math.max(
|
|
147
|
-
Math.min(initialIndex, getMaxIndex(
|
|
148
|
-
getMinIndex(
|
|
156
|
+
Math.min(initialIndex, getMaxIndex(effectiveEndYear)),
|
|
157
|
+
getMinIndex(effectiveStartYear)
|
|
149
158
|
)
|
|
150
159
|
|
|
151
|
-
const [visibleIndexes, setVisibleIndexes] = useState<number[]>(
|
|
160
|
+
const [visibleIndexes, setVisibleIndexes] = useState<number[]>(() =>
|
|
152
161
|
visibleArray(constrainedInitialIndex)
|
|
153
162
|
)
|
|
154
163
|
|
|
@@ -161,7 +170,12 @@ function VerticalScroller({
|
|
|
161
170
|
return
|
|
162
171
|
}
|
|
163
172
|
const top =
|
|
164
|
-
getVerticalMonthsOffset(
|
|
173
|
+
getVerticalMonthsOffset(
|
|
174
|
+
idx.current,
|
|
175
|
+
startWeekOnMonday,
|
|
176
|
+
effectiveStartYear,
|
|
177
|
+
effectiveEndYear
|
|
178
|
+
) - montHeaderHeight
|
|
165
179
|
|
|
166
180
|
element.scrollTo({
|
|
167
181
|
top,
|
|
@@ -177,11 +191,20 @@ function VerticalScroller({
|
|
|
177
191
|
return
|
|
178
192
|
}
|
|
179
193
|
|
|
180
|
-
const
|
|
181
|
-
|
|
194
|
+
const dynamicBeginOffset = getBeginOffset(
|
|
195
|
+
effectiveStartYear,
|
|
196
|
+
effectiveEndYear
|
|
197
|
+
)
|
|
198
|
+
const offset = top - dynamicBeginOffset
|
|
199
|
+
const index = getIndexFromVerticalOffset(
|
|
200
|
+
offset,
|
|
201
|
+
startWeekOnMonday,
|
|
202
|
+
effectiveStartYear,
|
|
203
|
+
effectiveEndYear
|
|
204
|
+
)
|
|
182
205
|
|
|
183
206
|
// Check if the new index is within allowed range
|
|
184
|
-
if (!isIndexWithinRange(index,
|
|
207
|
+
if (!isIndexWithinRange(index, effectiveStartYear, effectiveEndYear)) {
|
|
185
208
|
return
|
|
186
209
|
}
|
|
187
210
|
|
|
@@ -190,7 +213,12 @@ function VerticalScroller({
|
|
|
190
213
|
setVisibleIndexesThrottled(visibleArray(index))
|
|
191
214
|
}
|
|
192
215
|
},
|
|
193
|
-
[
|
|
216
|
+
[
|
|
217
|
+
setVisibleIndexesThrottled,
|
|
218
|
+
startWeekOnMonday,
|
|
219
|
+
effectiveStartYear,
|
|
220
|
+
effectiveEndYear,
|
|
221
|
+
]
|
|
194
222
|
)
|
|
195
223
|
|
|
196
224
|
return (
|
|
@@ -207,37 +235,53 @@ function VerticalScroller({
|
|
|
207
235
|
<div
|
|
208
236
|
// eslint-disable-next-line react-native/no-inline-styles
|
|
209
237
|
style={{
|
|
210
|
-
height:
|
|
238
|
+
height:
|
|
239
|
+
estimatedHeight *
|
|
240
|
+
getTotalMonths(effectiveStartYear, effectiveEndYear),
|
|
211
241
|
position: 'relative',
|
|
212
242
|
}}
|
|
213
243
|
>
|
|
214
|
-
{[0, 1, 2, 3, 4]
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
244
|
+
{[0, 1, 2, 3, 4]
|
|
245
|
+
.map((vi) => {
|
|
246
|
+
const monthIndex = visibleIndexes[vi]
|
|
247
|
+
|
|
248
|
+
if (monthIndex === undefined) {
|
|
249
|
+
return null
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return (
|
|
253
|
+
<div
|
|
254
|
+
key={vi}
|
|
255
|
+
// eslint-disable-next-line react-native/no-inline-styles
|
|
256
|
+
style={{
|
|
257
|
+
willChange: 'transform',
|
|
258
|
+
transform: `translateY(${getVerticalMonthsOffset(
|
|
259
|
+
monthIndex,
|
|
260
|
+
startWeekOnMonday,
|
|
261
|
+
effectiveStartYear,
|
|
262
|
+
effectiveEndYear
|
|
263
|
+
)}px)`,
|
|
264
|
+
left: 0,
|
|
265
|
+
right: 0,
|
|
266
|
+
position: 'absolute',
|
|
267
|
+
height: getMonthHeight(
|
|
268
|
+
'vertical',
|
|
269
|
+
monthIndex,
|
|
270
|
+
startWeekOnMonday,
|
|
271
|
+
effectiveStartYear,
|
|
272
|
+
effectiveEndYear
|
|
273
|
+
),
|
|
274
|
+
}}
|
|
275
|
+
>
|
|
276
|
+
{renderItem({
|
|
277
|
+
index: monthIndex,
|
|
278
|
+
onPrev: empty,
|
|
279
|
+
onNext: empty,
|
|
280
|
+
})}
|
|
281
|
+
</div>
|
|
282
|
+
)
|
|
283
|
+
})
|
|
284
|
+
.filter((item) => item !== null)}
|
|
241
285
|
</div>
|
|
242
286
|
</div>
|
|
243
287
|
)
|