Skip to content

Commit

Permalink
chore: example of non virtualized manual grid
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienIzz committed Jan 30, 2024
1 parent 0668fa4 commit f1c7edb
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { BottomTabBarProps, createBottomTabNavigator } from '@react-navigation/b
import { ProgramInfo } from './src/modules/program/domain/programInfo';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { ProgramDetail } from './src/pages/ProgramDetail';
import { NonVirtualizedGridPage } from './src/pages/NonVirtualizedGridPage';

const Stack = createNativeStackNavigator<RootStackParamList>();

Expand All @@ -21,6 +22,7 @@ const Tab = createBottomTabNavigator<RootTabParamList>();
export type RootTabParamList = {
Home: undefined;
ProgramGridPage: undefined;
NonVirtualizedGridPage: undefined;
};

export type RootStackParamList = {
Expand All @@ -45,6 +47,7 @@ const TabNavigator = () => {
>
<Tab.Screen name="Home" component={Home} />
<Tab.Screen name="ProgramGridPage" component={ProgramGridPage} />
<Tab.Screen name="NonVirtualizedGridPage" component={NonVirtualizedGridPage} />
</Tab.Navigator>
);
};
Expand Down
66 changes: 66 additions & 0 deletions packages/example/src/pages/NonVirtualizedGridPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { DefaultFocus, SpatialNavigationNode } from 'react-tv-space-navigation';
import { Page } from '../components/Page';
import '../components/configureRemoteControl';
import { getPrograms } from '../modules/program/infra/programInfos';
import { useNavigation } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { RootStackParamList } from '../../App';
import styled from '@emotion/native';
import { Fragment } from 'react';
import { scaledPixels } from '../design-system/helpers/scaledPixels';
import { ProgramNode } from '../modules/program/view/ProgramNode';

export const NonVirtualizedGridPage = () => {
return (
<Page>
<Container>
<SpatialNavigationNode alignInGrid>
<Fragment>
<DefaultFocus>
<ShortProgramList />
</DefaultFocus>
<ShortProgramList />
<ShortProgramList />
</Fragment>
</SpatialNavigationNode>
</Container>
</Page>
);
};

const ShortProgramList = () => {
const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
const programs = getPrograms().slice(0, 6);
return (
<SpatialNavigationNode orientation="horizontal">
<ListContainer>
{programs.map((program) => {
return (
<ProgramNode
programInfo={program}
onSelect={() => navigation.push('ProgramDetail', { programInfo: program })}
key={program.id}
/>
);
})}
</ListContainer>
</SpatialNavigationNode>
);
};

const ListContainer = styled.View(({ theme }) => ({
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'center',
gap: theme.spacings.$4,
padding: theme.spacings.$4,
}));

const Container = styled.View({
backgroundColor: '#222',
margin: 'auto',
borderRadius: scaledPixels(20),
padding: scaledPixels(30),
justifyContent: 'center',
alignItems: 'center',
});

0 comments on commit f1c7edb

Please sign in to comment.