Simplify the calculation
This commit is contained in:
@@ -34,14 +34,13 @@ export function TabBar({
|
|||||||
const {isDesktop, isTablet} = useWebMediaQueries()
|
const {isDesktop, isTablet} = useWebMediaQueries()
|
||||||
const [layouts, setLayouts] = useState([])
|
const [layouts, setLayouts] = useState([])
|
||||||
|
|
||||||
const approxIndex = useDerivedValue(() => dragProgress.value * (items.length - 1))
|
|
||||||
const indicatorStyle = useAnimatedStyle(() => {
|
const indicatorStyle = useAnimatedStyle(() => {
|
||||||
if (layouts.length < items.length - 1 || layouts.some(l => l === undefined)) {
|
if (layouts.length < items.length - 1 || layouts.some(l => l === undefined)) {
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
width: interpolate(approxIndex.value, layouts.map((l, i) => i), layouts.map(l => l.width)),
|
width: interpolate(dragProgress.value, layouts.map((l, i) => i), layouts.map(l => l.width)),
|
||||||
left: interpolate(approxIndex.value, layouts.map((l, i) => i), layouts.map(l => l.x)),
|
left: interpolate(dragProgress.value, layouts.map((l, i) => i), layouts.map(l => l.x)),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -56,12 +55,12 @@ export function TabBar({
|
|||||||
)
|
)
|
||||||
|
|
||||||
useAnimatedReaction(() => {
|
useAnimatedReaction(() => {
|
||||||
return dragProgress.value * (contentSize.value - SCREEN.width)
|
return (dragProgress.value / (items.length - 1)) * (contentSize.value - SCREEN.width)
|
||||||
}, (nextX, prevX) => {
|
}, (nextX, prevX) => {
|
||||||
if (prevX !== nextX) {
|
if (prevX !== nextX) {
|
||||||
scrollTo(scrollElRef, nextX, 0, false);
|
scrollTo(scrollElRef, nextX, 0, false);
|
||||||
}
|
}
|
||||||
}, [dragProgress, contentSize])
|
})
|
||||||
|
|
||||||
const onItemLayout = (e: LayoutChangeEvent, index: number) => {
|
const onItemLayout = (e: LayoutChangeEvent, index: number) => {
|
||||||
const l = e.nativeEvent.layout
|
const l = e.nativeEvent.layout
|
||||||
@@ -97,7 +96,7 @@ export function TabBar({
|
|||||||
<MaybeHighlightedText
|
<MaybeHighlightedText
|
||||||
type={isDesktop || isTablet ? 'xl-bold' : 'lg-bold'}
|
type={isDesktop || isTablet ? 'xl-bold' : 'lg-bold'}
|
||||||
testID={testID ? `${testID}-${item}` : undefined}
|
testID={testID ? `${testID}-${item}` : undefined}
|
||||||
approxIndex={approxIndex}
|
approxIndex={dragProgress}
|
||||||
index={i}>
|
index={i}>
|
||||||
{item}
|
{item}
|
||||||
</MaybeHighlightedText>
|
</MaybeHighlightedText>
|
||||||
|
|||||||
@@ -84,12 +84,10 @@ export const HomeScreen = withAuthRequired(
|
|||||||
const onPageScroll = React.useCallback(
|
const onPageScroll = React.useCallback(
|
||||||
e => {
|
e => {
|
||||||
'worklet'
|
'worklet'
|
||||||
if (customFeeds.length > 0) {
|
const progress = e.offset + e.position
|
||||||
const progress = (e.offset + e.position) / customFeeds.length
|
dragProgress.value = progress
|
||||||
dragProgress.value = progress
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
[customFeeds, dragProgress],
|
[dragProgress],
|
||||||
)
|
)
|
||||||
|
|
||||||
const onPressSelected = React.useCallback(() => {
|
const onPressSelected = React.useCallback(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user