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

Issue with customRenderTabBar #33

Closed
alexpchin opened this issue Jan 4, 2021 · 11 comments · Fixed by #35
Closed

Issue with customRenderTabBar #33

alexpchin opened this issue Jan 4, 2021 · 11 comments · Fixed by #35
Labels
bug Something isn't working

Comments

@alexpchin
Copy link
Contributor

alexpchin commented Jan 4, 2021

Hi @PedroBern I hope you had a nice Christmas and New Year.

I'm just looking into an issue when you use a custom tab bar. Everything works when you don't render a custom tab bar, however, when using a custom tab bar it seems like the preventDefault does not prevent clicking on the tab when the user is scrolling. Is this perhaps because the isGliding.current is being passed instead of isGliding?

Basically it becomes gittery.

The code below:

/**
   *
   * Wraps the tab bar with `Animated.View` to
   * control the translateY property.
   *
   * Render the header with `renderHeader` prop.
   *
   * Render the default `<TabBar />` with additional
   * `tabBarProps`, or a custom tab bar from the
   * `renderTabBar` prop, inside the Animated wrapper.
   */
  const renderTabBar = (
    props: SceneRendererProps & {
      navigationState: NavigationState<T>;
    }
  ): React.ReactNode => {
    return (
      <Animated.View
        pointerEvents="box-none"
        style={[
          styles.headerContainer,
          { transform: [{ translateY }] },
          headerContainerStyle,
        ]}
        onLayout={getHeaderHeight}
      >
        {renderHeader()}
        {customRenderTabBar ? (
          customRenderTabBar({
            ...props,
            ...tabBarProps,
            isGliding: isGliding.current,
          })
        ) : (
          <TabBar
            {...props}
            {...tabBarProps}
            onTabPress={(event) => {
              if (isGliding.current && preventTabPressOnGliding) {
                event.preventDefault();
              }
              tabBarProps?.onTabPress && tabBarProps.onTabPress(event);
            }}
          />
        )}
      </Animated.View>
    );
  };

Within my custom TabBar, I'm using (shortened version):

import { TabBar as RNTVTabBar } from 'react-native-tab-view';

const TabBar = (
  { badges, isGliding, ...props },
) => {
  return (
    <RNTVTabBar
      {...props}
      .
      .
      onTabPress={(event) => {
          if (isGliding) {
            event.preventDefault();
          }
          props?.onTabPress && props.onTabPress(event);
        }}
      />
  );
};

This is a video showing it working with no custom tab bar:

This is a video showing it not working with a custom tab bar:

@alexpchin alexpchin added the bug Something isn't working label Jan 4, 2021
@PedroBern
Copy link
Owner

Hi @alexpchin thanks, I hope you had a nice time too :)

If you log the isGlidding, does it update from false to true and vice versa?

@alexpchin
Copy link
Contributor Author

@PedroBern When first loading, without scrolling isGliding is false. Then when I scroll up and wait for the tabBar to reach the top, isGliding is false. However, if I click during the scroll, isGliding is true and then it doesn't switch back and it seemingly gets stuck.

@alexpchin
Copy link
Contributor Author

What if we do:

customRenderTabBar({
    ...props,
    ...tabBarProps,
    isGliding,
    preventTabPressOnGliding
  })

Why do we pass the .current reference instead of the whole ref? Am I forgetting something?

@PedroBern
Copy link
Owner

If we pass the whole ref, then we will need to use the .current inside the custom tab bar. But if this fixes, ok then. I didn't test with a custom tab bar yet.

Can you test and send a PR? If you can't, I probably will see it only later this week

@alexpchin
Copy link
Contributor Author

@PedroBern I'll take a look now

@alexpchin
Copy link
Contributor Author

Hi @PedroBern I've made a PR #34 Please take a look!

PedroBern added a commit that referenced this issue Jan 5, 2021
BREAKING CHANGE: pass isGliding ref instead of isGliding.current

Migration: use isGliding.current instead of isGliding inside your
custom renderTabBar function

Fixes #33
PedroBern added a commit that referenced this issue Jan 5, 2021
BREAKING CHANGE: pass isGliding ref instead of isGliding.current

Migration: use isGliding.current instead of isGliding inside your
custom renderTabBar function

Fixes #33
PedroBern added a commit that referenced this issue Jan 5, 2021
BREAKING CHANGE: pass isGliding ref instead of isGliding.current

Migration: use isGliding.current instead of isGliding inside your
custom renderTabBar function


Fixes #33
@PedroBern
Copy link
Owner

@alexpchin thanks for the PR, v2 is out 🚀

@PedroBern
Copy link
Owner

@alexpchin I did some modifications to the example after updating the types 👍

@alexpchin
Copy link
Contributor Author

@PedroBern Thanks for merging so quiickly. My Typescript is a bit rusty... I thought you might have to do that!

@PedroBern
Copy link
Owner

the problem was with the CollapsibleTabView types definition, now its good, but I still need to add the generics for the createMaterialCollapsibleTabView

@PedroBern
Copy link
Owner

PedroBern commented Jan 5, 2021

Now it's possible to pass the custom tab bar props type into the CollapsibleTabView and tabBarProps and renderTabBar will recognize the props

<CollapsibleTabView<Route, CustomTabBarProps> ... tabBarProps={{... typedProps ...}} ...  />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants