From 7606768202f0fac6bc5fb38aea0ba0e832cdab61 Mon Sep 17 00:00:00 2001 From: Ansh Nanda Date: Sun, 9 Apr 2023 13:08:58 -0700 Subject: [PATCH] fix swiping on main feed --- src/view/com/pager/TabBar.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/view/com/pager/TabBar.tsx b/src/view/com/pager/TabBar.tsx index 2070898bf5..8f3951e7b1 100644 --- a/src/view/com/pager/TabBar.tsx +++ b/src/view/com/pager/TabBar.tsx @@ -1,4 +1,4 @@ -import React, {createRef, useState, useMemo} from 'react' +import React, {createRef, useState, useMemo, useRef} from 'react' import { Animated, StyleSheet, @@ -46,6 +46,7 @@ export function TabBar({ [items.length], ) const panX = Animated.add(position, offset) + const containerRef = useRef(null) const indicatorStyle = { backgroundColor: indicatorColor || pal.colors.link, @@ -73,7 +74,12 @@ export function TabBar({ for (let i = 0; i < items.length; i++) { promises.push( new Promise(resolve => { - itemRefs[i].current?.measure( + if (!containerRef.current || !itemRefs[i].current) { + return resolve({x: 0, width: 0}) + } + + itemRefs[i].current?.measureLayout( + containerRef.current, (x: number, _y: number, width: number) => { resolve({x, width}) }, @@ -94,7 +100,11 @@ export function TabBar({ } return ( - + {items.map((item, i) => { const selected = i === selectedPage