Skip to content

Commit ca6b157

Browse files
committed
Move TabBar to functional component
1 parent 2e36572 commit ca6b157

File tree

4 files changed

+297
-298
lines changed

4 files changed

+297
-298
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react';
2+
import { ViewProps, ScrollViewProps } from 'react-native';
3+
export declare type FadedScrollViewProps = ViewProps & ScrollViewProps & {
4+
children?: React.ReactNode | React.ReactNode[];
5+
};
6+
declare const _default: React.ComponentClass<FadedScrollViewProps, any> | React.FunctionComponent<FadedScrollViewProps>;
7+
export default _default;

generatedTypes/components/tabController/TabBarItem.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ export interface TabControllerItemProps {
4343
* Badge component props to display next the item label
4444
*/
4545
badge?: BadgeProps;
46+
/**
47+
* maximun number of lines the label can break
48+
*/
49+
/**
50+
* whether the tab will have a divider on its right
51+
*/
4652
/**
4753
* A fixed width for the item
4854
*/
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React, {useCallback} from 'react';
2+
import {ViewProps, ScrollView, ScrollViewProps, NativeSyntheticEvent, NativeScrollEvent} from 'react-native';
3+
import Fader from '../../components/fader';
4+
import withScrollEnabler, {WithScrollEnablerProps} from '../../commons/withScrollEnabler';
5+
import withScrollReached, {WithScrollReachedProps} from '../../commons/withScrollReached';
6+
import forwardRef, {ForwardRefInjectedProps} from '../../commons/forwardRef';
7+
8+
export type FadedScrollViewProps = ViewProps & ScrollViewProps & {
9+
children?: React.ReactNode | React.ReactNode[];
10+
};
11+
12+
type ScrollReachedProps = FadedScrollViewProps & WithScrollReachedProps;
13+
type ScrollEnabledProps = ScrollReachedProps & WithScrollEnablerProps;
14+
type Props = ScrollEnabledProps & ForwardRefInjectedProps;
15+
16+
const FADER_SIZE = 76;
17+
18+
const FadedScrollView = (props: Props) => {
19+
const {scrollEnablerProps, scrollReachedProps, children, onScroll: propsOnScroll, ...other} = props;
20+
const fadeLeft = scrollEnablerProps.scrollEnabled && !scrollReachedProps.isScrollAtStart;
21+
const fadeRight = scrollEnablerProps.scrollEnabled && !scrollReachedProps.isScrollAtEnd;
22+
23+
const onScroll = useCallback(
24+
(event: NativeSyntheticEvent<NativeScrollEvent>) => {
25+
scrollReachedProps.onScroll(event);
26+
propsOnScroll?.(event);
27+
},
28+
[scrollReachedProps.onScroll, propsOnScroll]
29+
);
30+
31+
if (children) {
32+
return (
33+
<>
34+
<ScrollView
35+
horizontal
36+
showsHorizontalScrollIndicator={false}
37+
scrollEventThrottle={16}
38+
decelerationRate={'fast'}
39+
{...other}
40+
scrollEnabled={scrollEnablerProps.scrollEnabled}
41+
onContentSizeChange={scrollEnablerProps.onContentSizeChange}
42+
onLayout={scrollEnablerProps.onLayout}
43+
onScroll={onScroll}
44+
ref={props.forwardedRef}
45+
>
46+
{children}
47+
</ScrollView>
48+
<Fader visible={fadeLeft} position={Fader.position.LEFT} size={FADER_SIZE} />
49+
<Fader visible={fadeRight} position={Fader.position.RIGHT} size={FADER_SIZE} />
50+
</>
51+
);
52+
}
53+
54+
return null;
55+
};
56+
57+
// TODO: fix withScrollEnabler props (add <>)
58+
export default withScrollReached<FadedScrollViewProps>(withScrollEnabler(forwardRef<Props>(FadedScrollView)), {
59+
horizontal: true,
60+
threshold: 50
61+
});

0 commit comments

Comments
 (0)