Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed onLayout measurements on web #3019

Merged
merged 8 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion src/components/tabController/TabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ const TabBar = (props: Props) => {
key={`${index}_${item.label}`}
index={index}
onLayout={onItemLayout}
spreadItems={spreadItems}
/>
);
});
Expand All @@ -234,7 +235,8 @@ const TabBar = (props: Props) => {
backgroundColor,
activeBackgroundColor,
centerSelected,
onItemLayout
onItemLayout,
spreadItems
]);

const _indicatorTransitionStyle = useAnimatedStyle(() => {
Expand Down
11 changes: 7 additions & 4 deletions src/components/tabController/TabBarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import {Colors, Typography, Spacings} from '../../style';
import Badge, {BadgeProps} from '../badge';
import View from '../view';
import TabBarContext from './TabBarContext';
import Constants from '../../commons/Constants';
import type {TabControllerBarProps} from './TabBar';

const DEFAULT_LABEL_COLOR = Colors.$textDefault;
const DEFAULT_SELECTED_LABEL_COLOR = Colors.$textPrimary;

export interface TabControllerItemProps {
export interface TabControllerItemProps extends Pick<TabControllerBarProps, 'spreadItems'> {
/**
* label of the tab
*/
Expand Down Expand Up @@ -132,6 +134,7 @@ export default function TabBarItem({
testID,
ignore,
style,
spreadItems,
...props
}: Props) {
const {currentPage, setCurrentIndex} = useContext(TabBarContext);
Expand Down Expand Up @@ -193,9 +196,10 @@ export default function TabBarItem({
});

const _style = useMemo(() => {
const flex = Constants.isWeb ? (spreadItems ? 1 : undefined) : 1;
const constantWidthStyle = itemWidth.current ? {flex: 0, width: itemWidth.current} : undefined;
return [styles.tabItem, style, constantWidthStyle, pressStyle];
}, [style]);
return [styles.tabItem, {flex}, style, constantWidthStyle, pressStyle];
}, [style, spreadItems]);

const gesture = Gesture.Tap()
.maxDuration(60000)
Expand Down Expand Up @@ -250,7 +254,6 @@ export default function TabBarItem({

const styles = StyleSheet.create({
tabItem: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
Expand Down