From 75e42dd984952e9fbec6e1c4d6107cb9f1168dd3 Mon Sep 17 00:00:00 2001 From: Artur Yorsh <10753921+artyorsh@users.noreply.github.com> Date: Thu, 17 Oct 2019 15:17:52 +0300 Subject: [PATCH] fix(ui): calendar min-max navigation --- .../ui/calendar/baseCalendar.component.tsx | 34 +++++++--------- .../ui/calendar/calendar.component.tsx | 2 + .../components/calendarHeader.component.tsx | 8 ++-- src/playground/src/ui/screen/calendar/type.ts | 29 ++++---------- .../calendar/calendarBounds.component.tsx | 39 +++++++++++++++++++ .../src/ui/screen/showcases/calendar/index.ts | 1 + 6 files changed, 66 insertions(+), 47 deletions(-) create mode 100644 src/playground/src/ui/screen/showcases/calendar/calendarBounds.component.tsx diff --git a/src/framework/ui/calendar/baseCalendar.component.tsx b/src/framework/ui/calendar/baseCalendar.component.tsx index ab87b7565..1ac6f508f 100644 --- a/src/framework/ui/calendar/baseCalendar.component.tsx +++ b/src/framework/ui/calendar/baseCalendar.component.tsx @@ -155,9 +155,8 @@ export abstract class BaseCalendarComponent extends React.Component { - const yearStart: D = this.dateService.getYearStart(this.min); this.setState({ - visibleDate: this.dateService.addMonth(yearStart, index), + visibleDate: this.dateService.addMonth(this.min, index), }); }; @@ -174,27 +173,20 @@ export abstract class BaseCalendarComponent extends React.Component { - this.onCalendarPagerMove(-1); - }; - - private onCalendarPagerRight = (): void => { - this.onCalendarPagerMove(1); - }; + private onHeaderNavigationLeftPress = (): void => { + const pagerRef: React.RefObject> = this.getCurrentPagerRef(); - private onCalendarPagerMove = (step: number): void => { - const ref: React.RefObject> = this.getCurrentPagerRef(); - const index: number = this.getCalendarPagerIndex(); - - this.onCalendarPagerMoveStart(ref, index, step); + pagerRef.current.scrollToIndex({ + index: pagerRef.current.props.selectedIndex - 1, + animated: true, + }); }; - private onCalendarPagerMoveStart = (ref: React.RefObject>, - index: number, - step: number): void => { + private onHeaderNavigationRightPress = (): void => { + const pagerRef: React.RefObject> = this.getCurrentPagerRef(); - ref.current.scrollToIndex({ - index: index + step, + pagerRef.current.scrollToIndex({ + index: pagerRef.current.props.selectedIndex + 1, animated: true, }); }; @@ -524,8 +516,8 @@ export abstract class BaseCalendarComponent extends React.Component ); }; diff --git a/src/framework/ui/calendar/calendar.component.tsx b/src/framework/ui/calendar/calendar.component.tsx index e5b8467ec..928ccf0fe 100644 --- a/src/framework/ui/calendar/calendar.component.tsx +++ b/src/framework/ui/calendar/calendar.component.tsx @@ -60,6 +60,8 @@ export type CalendarElement = React.ReactElement>; * * @overview-example CalendarFilter * + * @overview-example CalendarBounds + * * @overview-example CalendarCustomLocale * * @example CalendarMoment diff --git a/src/framework/ui/calendar/components/calendarHeader.component.tsx b/src/framework/ui/calendar/components/calendarHeader.component.tsx index f69048707..6b18936e2 100644 --- a/src/framework/ui/calendar/components/calendarHeader.component.tsx +++ b/src/framework/ui/calendar/components/calendarHeader.component.tsx @@ -20,8 +20,8 @@ interface ComponentProps extends ViewProps { iconStyle?: ImageStyle; lateralNavigationAllowed: boolean; onTitlePress?: () => void; - onRight?: () => void; - onLeft?: () => void; + onNavigationLeftPress?: () => void; + onNavigationRightPress?: () => void; } export type CalendarHeaderProps = ComponentProps; @@ -64,14 +64,14 @@ export class CalendarHeader extends React.Component { appearance='ghost' // @ts-ignore icon={this.renderLeftIcon} - onPress={this.props.onLeft} + onPress={this.props.onNavigationLeftPress} />