Skip to content

Commit

Permalink
chore(example): more GoBackConfiguration so that each page has its own
Browse files Browse the repository at this point in the history
Otherwise we can't catch hardware back press properly
  • Loading branch information
pierpo committed Sep 11, 2024
1 parent 9b69e78 commit 6144737
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 0 additions & 2 deletions packages/example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ function App(): JSX.Element {
<NavigationContainer>
<ThemeProvider theme={theme}>
<SpatialNavigationDeviceTypeProvider>
<GoBackConfiguration />

<Container width={width} height={height}>
<Stack.Navigator
screenOptions={{
Expand Down
3 changes: 3 additions & 0 deletions packages/example/src/components/GoBackConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export const GoBackConfiguration = () => {

const goBackOnBackPress = useCallback(
(pressedKey: SupportedKeys) => {
if (!navigation.isFocused) {
return false;
}
if (pressedKey !== SupportedKeys.Back) return false;
if (navigation.canGoBack()) {
navigation.goBack();
Expand Down
4 changes: 3 additions & 1 deletion packages/example/src/components/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { useIsFocused } from '@react-navigation/native';
import { ReactNode, useCallback, useEffect } from 'react';
import { SpatialNavigationRoot, useLockSpatialNavigation } from 'react-tv-space-navigation';
import { useMenuContext } from './Menu/MenuContext';
import { Keyboard } from 'react-native';
import { BackHandler, Keyboard } from 'react-native';

Check failure on line 6 in packages/example/src/components/Page.tsx

View workflow job for this annotation

GitHub Actions / build (20.x)

'BackHandler' is defined but never used
import { GoBackConfiguration } from './GoBackConfiguration';

type Props = { children: ReactNode };

Expand Down Expand Up @@ -51,6 +52,7 @@ export const Page = ({ children }: Props) => {
isActive={isActive}
onDirectionHandledWithoutMovement={onDirectionHandledWithoutMovement}
>
<GoBackConfiguration />
<SpatialNavigationKeyboardLocker />
{children}
</SpatialNavigationRoot>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class RemoteControlManager implements RemoteControlManagerInterface {
66: SupportedKeys.Enter,
23: SupportedKeys.Enter,
67: SupportedKeys.Back,
4: SupportedKeys.Back,
}[keyEvent.keyCode];

if (!mappedKey) {
Expand Down

0 comments on commit 6144737

Please sign in to comment.