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

Conversation

ethanshar
Copy link
Collaborator

Description

Avoid blocking TabBarItem re-onLayout callback

To reproduce (copy in playground)

const twoItems = [
  {label: 'February', key: 'feb'},
  {label: 'April', key: 'apr'}
];
const threeItems = [
  {label: 'February', key: 'feb'},
  {label: 'March', key: 'mar'},
  {label: 'April', key: 'apr'}
];

export default class PlaygroundScreen extends Component {
  state = {
    items: twoItems
  };

  onPress = () => {
    this.setState({
      items: this.state.items.length === 2 ? threeItems : twoItems
    });
  };

  render() {
    return (
      <View bg-grey80 flex>
        <View center padding-page>
          <Button label="Change items" onPress={this.onPress}/>
        </View>
        <TabController items={this.state.items}>
          <TabController.TabBar/>
        </TabController>
      </View>
    );
  }
}

Changelog

Fix issue with TabController items not calculating their layout after change in items

@ethanshar ethanshar changed the title Avoid block TabBarItem re-onLayout callback Avoid blocking TabBarItem re-onLayout callback Feb 27, 2022
@ethanshar ethanshar requested a review from M-i-k-e-l February 27, 2022 05:18
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.

@ethanshar ethanshar requested a review from M-i-k-e-l February 28, 2022 15:25
@M-i-k-e-l M-i-k-e-l merged commit 9e9f83c into master Feb 28, 2022
@@ -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

@ethanshar ethanshar deleted the fix/TabControllerDyanmicItems branch June 13, 2022 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants