Skip to content

Commit 784264f

Browse files
authored
feature: custom arrowsHitSlop for Header (#1809)
* Add custom arrowsHitSlop for Header * Add transformer to Insets if number is provided * Add styles types to header styles, remove ts-expect-error * Add default in calendar.api.json remove des * Remove changes from CHANGELOG.md * Restore hitSlop, add useMemo, fix conflict merge * Restore CHANGELOG.md formatting * Move hitSlop outside _renderArrow
1 parent ae063f1 commit 784264f

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,4 +793,4 @@
793793
- 'input.js' - renaming 'velocityTracker'.
794794
- 'test.js' - renaming 'testUtils' and removing from folder.
795795

796-
*** End of changelog - please see release tags for notes ***
796+
*** End of changelog - please see release tags for notes ***

docsRNC/docs/Calendar.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ Whether to hide the days names
130130
Whether to hide the arrows
131131
<span style={{color: 'grey'}}>boolean</span>
132132

133+
### arrowsHitSlop
134+
135+
Left & Right arrows. Additional distance outside of the buttons in which a press is detected, default: 20
136+
<span style={{color: 'grey'}}>null | Insets | number</span>
133137
### disableArrowLeft
134138

135139
Whether to disable the left arrow

src/calendar/calendar.api.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@
132132
"type": "boolean",
133133
"description": "Whether to hide the arrows"
134134
},
135+
{
136+
"name": "arrowsHitSlop",
137+
"type": "null | Insets | number",
138+
"default": 20
139+
},
135140
{
136141
"name": "disableArrowLeft",
137142
"type": "boolean",

src/calendar/header/index.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
StyleProp,
1313
ViewStyle,
1414
AccessibilityActionEvent,
15-
ColorValue
15+
ColorValue,
16+
Insets
1617
} from 'react-native';
1718
import {formatNumbers, weekDayNames} from '../../dateutils';
1819
import {
@@ -50,6 +51,8 @@ export interface CalendarHeaderProps {
5051
onPressArrowLeft?: (method: () => void, month?: XDate) => void; //TODO: replace with string
5152
/** Handler which gets executed when press arrow icon right. It receive a callback can go next month */
5253
onPressArrowRight?: (method: () => void, month?: XDate) => void; //TODO: replace with string
54+
/** Left & Right arrows. Additional distance outside of the buttons in which a press is detected, default: 20 */
55+
arrowsHitSlop?: Insets | number;
5356
/** Disable left arrow */
5457
disableArrowLeft?: boolean;
5558
/** Disable right arrow */
@@ -75,7 +78,6 @@ export interface CalendarHeaderProps {
7578
timelineLeftInset?: number;
7679
}
7780

78-
const arrowHitSlop = {left: 20, right: 20, top: 20, bottom: 20};
7981
const accessibilityActions = [
8082
{name: 'increment', label: 'increment'},
8183
{name: 'decrement', label: 'decrement'}
@@ -95,6 +97,7 @@ const CalendarHeader = forwardRef((props: CalendarHeaderProps, ref) => {
9597
renderArrow,
9698
onPressArrowLeft,
9799
onPressArrowRight,
100+
arrowsHitSlop = 20,
98101
disableArrowLeft,
99102
disableArrowRight,
100103
disabledDaysIndexes,
@@ -123,7 +126,14 @@ const CalendarHeader = forwardRef((props: CalendarHeaderProps, ref) => {
123126
const dayNamesStyle = useMemo(() => {
124127
return [style.current.week, numberOfDaysCondition ? partialWeekStyle : undefined];
125128
}, [numberOfDaysCondition, partialWeekStyle]);
126-
129+
const hitSlop: Insets | undefined = useMemo(
130+
() =>
131+
typeof arrowsHitSlop === 'number'
132+
? {top: arrowsHitSlop, left: arrowsHitSlop, bottom: arrowsHitSlop, right: arrowsHitSlop}
133+
: arrowsHitSlop,
134+
[arrowsHitSlop]
135+
);
136+
127137
useImperativeHandle(ref, () => ({
128138
onPressLeft,
129139
onPressRight
@@ -225,14 +235,14 @@ const CalendarHeader = forwardRef((props: CalendarHeaderProps, ref) => {
225235
const shouldDisable = isLeft ? disableArrowLeft : disableArrowRight;
226236
const onPress = !shouldDisable ? isLeft ? onPressLeft : onPressRight : undefined;
227237
const imageSource = isLeft ? require('../img/previous.png') : require('../img/next.png');
228-
const renderArrowDirection = isLeft ? 'left' : 'right';
229-
238+
const renderArrowDirection = isLeft ? 'left' : 'right';
239+
230240
return (
231241
<TouchableOpacity
232242
onPress={onPress}
233243
disabled={shouldDisable}
234244
style={style.current.arrow}
235-
hitSlop={arrowHitSlop}
245+
hitSlop={hitSlop}
236246
testID={testId}
237247
>
238248
{renderArrow ? (
@@ -301,5 +311,6 @@ export default CalendarHeader;
301311
CalendarHeader.displayName = 'CalendarHeader';
302312
CalendarHeader.defaultProps = {
303313
monthFormat: 'MMMM yyyy',
304-
webAriaLevel: 1
314+
webAriaLevel: 1,
315+
arrowsHitSlop: 20
305316
};

0 commit comments

Comments
 (0)