Skip to content

Commit

Permalink
feat: export useCollapsibleStyle hook
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroBern committed Jan 30, 2021
1 parent 826966d commit dde28fe
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/createCollapsibleTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -681,17 +681,17 @@ const createCollapsibleTabs = <T extends ParamList>() => {
return scrollHandler
}

const useStyle = () => {
const useCollapsibleStyle = () => {
const { headerHeight, tabBarHeight, containerHeight } = useTabsContext()
const windowWidth = useWindowDimensions().width

return {
_style: { width: windowWidth },
_contentContainerStyle: {
style: { width: windowWidth },
contentContainerStyle: {
minHeight: (containerHeight || 0) + headerHeight,
paddingTop: headerHeight + tabBarHeight,
},
_progressViewOffset: headerHeight + tabBarHeight,
progressViewOffset: headerHeight + tabBarHeight,
}
}

Expand All @@ -703,7 +703,11 @@ const createCollapsibleTabs = <T extends ParamList>() => {
const name = useTabNameContext()
const { refMap } = useTabsContext()
const scrollHandler = useScrollHandlerY(name)
const { _style, _contentContainerStyle, _progressViewOffset } = useStyle()
const {
style: _style,
contentContainerStyle: _contentContainerStyle,
progressViewOffset,
} = useCollapsibleStyle()

return (
<AnimatedFlatList
Expand All @@ -716,7 +720,7 @@ const createCollapsibleTabs = <T extends ParamList>() => {
// @ts-ignore
contentContainerStyle,
]}
progressViewOffset={_progressViewOffset}
progressViewOffset={progressViewOffset}
onScroll={scrollHandler}
scrollEventThrottle={16}
{...rest}
Expand All @@ -733,7 +737,10 @@ const createCollapsibleTabs = <T extends ParamList>() => {
const name = useTabNameContext()
const { refMap } = useTabsContext()
const scrollHandler = useScrollHandlerY(name)
const { _style, _contentContainerStyle, _progressViewOffset } = useStyle()
const {
style: _style,
contentContainerStyle: _contentContainerStyle,
} = useCollapsibleStyle()

return (
<Animated.ScrollView
Expand All @@ -745,7 +752,6 @@ const createCollapsibleTabs = <T extends ParamList>() => {
// @ts-ignore
contentContainerStyle,
]}
progressViewOffset={_progressViewOffset}
onScroll={scrollHandler}
scrollEventThrottle={16}
{...rest}
Expand All @@ -755,7 +761,14 @@ const createCollapsibleTabs = <T extends ParamList>() => {
)
}

return { FlatList, ScrollView, Container, useTabsContext, Lazy }
return {
FlatList,
ScrollView,
Container,
useTabsContext,
useCollapsibleStyle,
Lazy,
}
}

const styles = StyleSheet.create({
Expand Down

0 comments on commit dde28fe

Please sign in to comment.