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

Using AppBar with expo router header the back button always showing.. #4504

Closed
ahmetskilinc opened this issue Sep 22, 2024 · 2 comments
Closed
Labels
question Question related to the library, not an issue

Comments

@ahmetskilinc
Copy link

When I'm using <AppBar.Header ... /> with Expo Routers tabs and stack layouts, the back button always show.

I am using it like so:
_layout.tsx

export default function Layout() {
	return (
		<Stack screenOptions={{ header: (props) => <Header {...props} /> }}>
			{...}
		</Stack>
	);
}

Header.tsx

const Header = (props: NativeStackHeaderProps | BottomTabHeaderProps) => {
	const Left = props.options.headerLeft || (() => null);
	const Right = props.options.headerRight || (() => null);

	return (
		<Appbar.Header {...props}>
			<Left canGoBack={props.navigation.canGoBack()} />
			{props.navigation.canGoBack() ? (
				<Appbar.BackAction onPress={() => props.navigation.goBack()} />
			) : null}
			<Appbar.Content title={props.options.title} />
			<Right canGoBack={props.navigation.canGoBack()} />
		</Appbar.Header>
	);
};

export default Header;

This is the output I'm getting:
Simulator Screenshot - iPhone 15 Pro - 2024-09-23 at 00 52 13

What am I doing wrong? I've tried to search around but cannot find a solution.

@ahmetskilinc ahmetskilinc added the question Question related to the library, not an issue label Sep 22, 2024
@gedu
Copy link
Contributor

gedu commented Sep 28, 2024

Is this a bug from react-native-paper? Are you trying to hide the back arrow button?
Looking at the code, do you know if canGoBack() is returning true? that's why it shows the back button? I think in bottom navigation you can go back because the previous tab is in the history?

{props.navigation.canGoBack() ? (
				<Appbar.BackAction onPress={() => props.navigation.goBack()} />
			) : null}
			```

@ahmetskilinc
Copy link
Author

@gedu I think you're right. It's caused by the Tabs from expo-router. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question related to the library, not an issue
Projects
None yet
Development

No branches or pull requests

2 participants