Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions src/MaterialTabBar/TabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,22 @@ const MaterialTabBar = <T extends TabName = TabName>({
if (!event.nativeEvent?.layout) return
const { width, x } = event.nativeEvent.layout

itemLayoutGathering.current.set(name, {
width,
x,
})

// pick out the layouts for the tabs we know about (in case they changed dynamically)
const layout = Array.from(itemLayoutGathering.current.entries())
.filter(([tabName]) => tabNames.includes(tabName))
.map(([, layout]) => layout)
.sort((a, b) => a.x - b.x)

if (layout.length === tabNames.length) {
setItemsLayout(layout)
// Only update if we don't already have a layout for this tab
if (!itemLayoutGathering.current.has(name)) {
itemLayoutGathering.current.set(name, {
width,
x,
})

// pick out the layouts for the tabs we know about (in case they changed dynamically)
const layout = Array.from(itemLayoutGathering.current.entries())
.filter(([tabName]) => tabNames.includes(tabName))
.map(([, layout]) => layout)
.sort((a, b) => a.x - b.x)

if (layout.length === tabNames.length) {
setItemsLayout(layout)
}
}
}
},
Expand Down