@@ -11,6 +11,7 @@ import TabBarItem from './TabBarItem';
11
11
// import ReanimatedObject from './ReanimatedObject';
12
12
import { asBaseComponent , forwardRef } from '../../commons' ;
13
13
import View from '../../components/view' ;
14
+ import ScrollBarGradient from '../scrollBar/ScrollBarGradient' ;
14
15
import { Colors , Spacings , Typography } from '../../style' ;
15
16
import { Constants } from '../../helpers' ;
16
17
import { LogService } from '../../services' ;
@@ -270,11 +271,32 @@ class TabBar extends PureComponent {
270
271
} ;
271
272
272
273
onScroll = ( { nativeEvent : { contentOffset} } ) => {
274
+ const { fadeLeft, fadeRight} = this . state ;
273
275
this . tabBarScrollOffset = contentOffset . x ;
276
+ const stateUpdate = { } ;
277
+ // TODO: extract this logic to scrollbar presenter or something
278
+ const leftThreshold = 50 ;
279
+ if ( this . tabBarScrollOffset > leftThreshold && ! fadeLeft ) {
280
+ stateUpdate . fadeLeft = true ;
281
+ } else if ( this . tabBarScrollOffset <= leftThreshold && fadeLeft ) {
282
+ stateUpdate . fadeLeft = false ;
283
+ }
284
+
285
+ const rightThreshold = ( this . contentWidth - this . containerWidth ) ;
286
+ if ( this . tabBarScrollOffset < rightThreshold && ! fadeRight ) {
287
+ stateUpdate . fadeRight = true ;
288
+ } else if ( this . tabBarScrollOffset >= rightThreshold && fadeRight ) {
289
+ stateUpdate . fadeRight = false ;
290
+ }
291
+
292
+ if ( ! _ . isEmpty ( stateUpdate ) ) {
293
+ this . setState ( stateUpdate ) ;
294
+ }
274
295
} ;
275
296
276
297
onContentSizeChange = ( width ) => {
277
- if ( width > this . containerWidth ) {
298
+ if ( width > this . containerWidth && ! this . contentWidth ) {
299
+ this . contentWidth = width ;
278
300
this . setState ( { scrollEnabled : true } ) ;
279
301
}
280
302
} ;
@@ -375,7 +397,7 @@ class TabBar extends PureComponent {
375
397
376
398
render ( ) {
377
399
const { height, enableShadow, containerStyle, testID} = this . props ;
378
- const { itemsWidths, scrollEnabled} = this . state ;
400
+ const { itemsWidths, scrollEnabled, fadeLeft , fadeRight } = this . state ;
379
401
return (
380
402
< View
381
403
style = { [ styles . container , enableShadow && styles . containerShadow , { width : this . containerWidth } , containerStyle ] }
@@ -400,6 +422,8 @@ class TabBar extends PureComponent {
400
422
{ this . renderSelectedIndicator ( ) }
401
423
</ ScrollView >
402
424
{ _ . size ( itemsWidths ) > 1 && < Code > { this . renderCodeBlock } </ Code > }
425
+ < ScrollBarGradient left visible = { fadeLeft } />
426
+ < ScrollBarGradient visible = { fadeRight } />
403
427
</ View >
404
428
) ;
405
429
}
0 commit comments