Skip to content

Commit abad74f

Browse files
authored
Carousel - fix counter flickering between numbers (#1591)
1 parent fb3d7eb commit abad74f

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

generatedTypes/src/components/carousel/CarouselPresenter.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { PropsWithChildren } from 'react';
22
import { CarouselProps, CarouselState } from './types';
33
export declare function getChildrenLength(props: PropsWithChildren<CarouselProps>): number;
4-
export declare function calcOffset(props: CarouselProps, state: Omit<CarouselState, 'initialOffset' | 'prevProps'>): {
4+
export declare function calcOffset(props: CarouselProps, state: Omit<CarouselState, 'initialOffset' | 'prevProps' | 'currentStandingPage'>): {
55
x: number;
66
y: number;
77
};

generatedTypes/src/components/carousel/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export interface CarouselProps extends ScrollViewProps {
9898
export interface CarouselState {
9999
containerWidth?: number;
100100
currentPage: number;
101-
currentStandingPage?: number;
101+
currentStandingPage: number;
102102
pageWidth: number;
103103
pageHeight: number;
104104
initialOffset: PointPropType;

src/components/carousel/CarouselPresenter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function getChildrenLength(props: PropsWithChildren<CarouselProps>): numb
66
return React.Children.count(props.children);
77
}
88

9-
export function calcOffset(props: CarouselProps, state: Omit<CarouselState, 'initialOffset' | 'prevProps'>) {
9+
export function calcOffset(props: CarouselProps, state: Omit<CarouselState, 'initialOffset' | 'prevProps' | 'currentStandingPage'>) {
1010
const {currentPage, pageWidth, pageHeight} = state;
1111
const {loop, containerMarginHorizontal = 0} = props;
1212
const actualCurrentPage = loop ? currentPage + 1 : currentPage;

src/components/carousel/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Carousel extends Component<CarouselProps, CarouselState> {
5656
containerWidth: undefined,
5757
// @ts-ignore (defaultProps)
5858
currentPage: this.shouldUsePageWidth() ? this.getCalcIndex(props.initialPage) : props.initialPage,
59-
currentStandingPage: props.initialPage,
59+
currentStandingPage: props.initialPage || 0,
6060
pageWidth: defaultPageWidth,
6161
pageHeight,
6262
initialOffset: presenter.calcOffset(props, {
@@ -262,7 +262,7 @@ class Carousel extends Component<CarouselProps, CarouselState> {
262262

263263
onMomentumScrollEnd = () => {
264264
// finished full page scroll
265-
const {currentStandingPage = 0, currentPage} = this.state;
265+
const {currentStandingPage, currentPage} = this.state;
266266
const index = this.getCalcIndex(currentPage);
267267

268268
const pagesCount = presenter.getChildrenLength(this.props);
@@ -420,14 +420,14 @@ class Carousel extends Component<CarouselProps, CarouselState> {
420420

421421
renderCounter() {
422422
const {pageWidth, showCounter, counterTextStyle} = this.props;
423-
const {currentPage} = this.state;
423+
const {currentStandingPage} = this.state;
424424
const pagesCount = presenter.getChildrenLength(this.props);
425425

426426
if (showCounter && !pageWidth) {
427427
return (
428428
<View center style={styles.counter}>
429429
<Text grey80 text90 style={[{fontWeight: 'bold'}, counterTextStyle]}>
430-
{currentPage + 1}/{pagesCount}
430+
{currentStandingPage + 1}/{pagesCount}
431431
</Text>
432432
</View>
433433
);

src/components/carousel/types.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export interface CarouselProps extends ScrollViewProps {
101101
export interface CarouselState {
102102
containerWidth?: number;
103103
currentPage: number;
104-
currentStandingPage?: number;
104+
currentStandingPage: number;
105105
pageWidth: number;
106106
pageHeight: number;
107107
initialOffset: PointPropType;

0 commit comments

Comments
 (0)