fix hoisting errors

This commit is contained in:
Samuel Newman
2025-10-08 17:09:22 +03:00
parent aac898d229
commit 46103b661e
2 changed files with 17 additions and 17 deletions
+10 -10
View File
@@ -53,6 +53,16 @@ export function InterestTabs({
const pendingTabOffsets = useRef<{x: number; width: number}[]>([])
const [tabOffsets, setTabOffsets] = useState<{x: number; width: number}[]>([])
function scrollIntoViewIfNeeded(index: number) {
const btnLayout = tabOffsets[index]
if (!btnLayout) return
listRef.current?.scrollTo({
// centered
x: btnLayout.x - (totalWidth / 2 - btnLayout.width / 2),
animated: true,
})
}
const onInitialLayout = useNonReactiveCallback(() => {
const index = interests.indexOf(selectedInterest)
scrollIntoViewIfNeeded(index)
@@ -64,16 +74,6 @@ export function InterestTabs({
}
}, [tabOffsets, onInitialLayout])
function scrollIntoViewIfNeeded(index: number) {
const btnLayout = tabOffsets[index]
if (!btnLayout) return
listRef.current?.scrollTo({
// centered
x: btnLayout.x - (totalWidth / 2 - btnLayout.width / 2),
animated: true,
})
}
function handleSelectTab(index: number) {
const tab = interests[index]
onSelectTab(tab)
+7 -7
View File
@@ -41,12 +41,6 @@ export function Pager({
const scrollYs = useRef<Array<number | null>>([])
const anchorRef = useRef(null)
useImperativeHandle(ref, () => ({
setPage: (index: number) => {
onTabBarSelect(index)
},
}))
const onTabBarSelect = useCallback(
(index: number) => {
const scrollY = window.scrollY
@@ -80,12 +74,18 @@ export function Pager({
[selectedPage, setSelectedPage, onPageSelected],
)
useImperativeHandle(ref, () => ({
setPage: (index: number) => {
onTabBarSelect(index)
},
}))
return (
<View style={s.hContentRegion}>
{renderTabBar({
selectedPage,
tabBarAnchor: <View ref={anchorRef} />,
onSelect: e => onTabBarSelect(e),
onSelect: onTabBarSelect,
})}
{Children.map(children, (child, i) => (
<View