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 13, 2024
1 parent 2cde6ad commit 2727316
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
3 changes: 0 additions & 3 deletions packages/example/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ThemeProvider } from '@emotion/react';
import { NavigationContainer } from '@react-navigation/native';
import { useWindowDimensions } from 'react-native';
import { GoBackConfiguration } from './src/components/GoBackConfiguration';
import { theme } from './src/design-system/theme/theme';
import { Home } from './src/pages/Home';
import { ProgramGridPage } from './src/pages/ProgramGridPage';
Expand Down Expand Up @@ -78,8 +77,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
2 changes: 2 additions & 0 deletions packages/example/src/components/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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 { 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 2727316

Please sign in to comment.