1- import React , { useCallback , useEffect , useRef , useState } from 'react' ;
1+ import React , { useEffect , useRef } from 'react' ;
22import {
33 Animated ,
44 Easing ,
55 EasingFunction ,
6- LayoutChangeEvent ,
76 StyleProp ,
87 StyleSheet ,
98 View ,
@@ -61,7 +60,6 @@ export const PageIndicator = ({
6160 const pixelDashSize = evenPixelRound ( dashSize ?? pixelSize * 4 ) ;
6261 const pixelBorderRadius = clamp ( borderRadius ?? pixelSize / 2 , 0 , pixelSize / 2 ) ;
6362
64- const [ trainStroke , setTrainStroke ] = useState ( pixelDashSize ) ;
6563 const shouldAnimate = typeof current === 'number' ;
6664 const flexDirection = vertical ? 'column' : 'row' ;
6765 const animatedValue = useRef (
@@ -79,26 +77,18 @@ export const PageIndicator = ({
7977 }
8078 } , [ shouldAnimate , animatedValue , current , count , duration , easing ] ) ;
8179
82- const handleLayout = useCallback (
83- ( e : LayoutChangeEvent ) => {
84- if ( variant === Variants . TRAIN && pixelDashSize === 0 ) {
85- const { width, height } = e . nativeEvent . layout ;
86- setTrainStroke ( ( vertical ? height : width ) / count - gap ) ;
87- }
88- } ,
89- [ variant , pixelDashSize , vertical , count , gap ] ,
90- ) ;
91-
80+ const trainDashSize = Math . max ( pixelDashSize , pixelSize ) ;
81+ const morseDashSize = Math . max ( pixelDashSize , pixelSize * 2 ) ;
9282 const rootStyle : StyleProp < ViewStyle > = [ styles . root , style , { flexDirection } ] ;
9383
9484 if ( variant === Variants . MORSE ) {
9585 rootStyle . push ( {
96- [ vertical ? 'height' : 'width' ] : pixelDashSize + pixelSize * ( count - 1 ) + gap * count ,
86+ [ vertical ? 'height' : 'width' ] : morseDashSize + pixelSize * ( count - 1 ) + gap * count ,
9787 } ) ;
9888 }
9989
10090 return (
101- < View { ...props } style = { rootStyle } pointerEvents = "none" onLayout = { handleLayout } >
91+ < View { ...props } style = { rootStyle } pointerEvents = "none" >
10292 { [ ...Array ( count ) . keys ( ) ] . map ( ( index ) =>
10393 variant === Variants . BEADS ? (
10494 < IndicatorBeads
@@ -123,7 +113,7 @@ export const PageIndicator = ({
123113 index = { index }
124114 vertical = { vertical }
125115 activeColor = { activeColor }
126- dashSize = { trainStroke }
116+ dashSize = { trainDashSize }
127117 opacity = { clamp ( opacity , 0 , 1 ) }
128118 borderRadius = { pixelBorderRadius }
129119 animatedValue = { animatedValue }
@@ -138,7 +128,7 @@ export const PageIndicator = ({
138128 index = { index }
139129 vertical = { vertical }
140130 activeColor = { activeColor }
141- dashSize = { Math . max ( pixelDashSize , pixelSize * 2 ) }
131+ dashSize = { morseDashSize }
142132 opacity = { clamp ( opacity , 0 , 1 ) }
143133 borderRadius = { pixelBorderRadius }
144134 animatedValue = { animatedValue }
0 commit comments