Skip to content

Avoid blocking TabBarItem re-onLayout callback #1869

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

Merged
merged 1 commit into from
Feb 28, 2022
Merged
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: 2 additions & 2 deletions src/components/tabController/TabBarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default function TabBarItem({
const sharedSelectedLabelStyle = useSharedValue(JSON.parse(JSON.stringify(selectedLabelStyle)));

useEffect(() => {
if (itemWidth.current) {
if (props.width) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is unnecessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it on purpose cause I want it to be clear it depends on the prop being passed.
While the width ref is kept for later use.

props.onLayout?.({nativeEvent: {layout: {x: 0, y: 0, width: itemWidth.current, height: 0}}} as LayoutChangeEvent,
index);
}
Expand All @@ -149,7 +149,7 @@ export default function TabBarItem({
const onLayout = useCallback((event: LayoutChangeEvent) => {
const {width} = event.nativeEvent.layout;

if (!itemWidth.current && itemRef?.current) {
if (!props.width && itemRef?.current) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this causes infinite onLayout update

itemWidth.current = width;
// @ts-ignore
itemRef.current?.setNativeProps({style: {width, paddingHorizontal: null, flex: null}});
Expand Down