Skip to content

Commit

Permalink
fix: prevent rerenders on layout
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroBern committed Jan 23, 2021
1 parent 1944fd3 commit 2e3aceb
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/createCollapsibleTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,29 @@ const createCollapsibleTabs = <T extends string>() => {
}
}, [diffClampEnabled])

const getHeaderHeight = React.useCallback((event: LayoutChangeEvent) => {
setHeaderHeight(event.nativeEvent.layout.height || 0)
}, [])
const getHeaderHeight = React.useCallback(
(event: LayoutChangeEvent) => {
const height = event.nativeEvent.layout.height
if (headerHeight !== height) setHeaderHeight(height)
},
[headerHeight]
)

const getTabBarHeight = React.useCallback((event: LayoutChangeEvent) => {
setTabBarHeight(event.nativeEvent.layout.height || 0)
}, [])
const getTabBarHeight = React.useCallback(
(event: LayoutChangeEvent) => {
const height = event.nativeEvent.layout.height
if (tabBarHeight !== height) setTabBarHeight(height)
},
[tabBarHeight]
)

const onLayout = React.useCallback((e: LayoutChangeEvent) => {
setContainerHeight(e.nativeEvent.layout.height || 0)
}, [])
const onLayout = React.useCallback(
(event: LayoutChangeEvent) => {
const height = event.nativeEvent.layout.height
if (containerHeight !== height) setContainerHeight(height)
},
[containerHeight]
)

return (
<Context.Provider
Expand Down

0 comments on commit 2e3aceb

Please sign in to comment.