Skip to content

Commit b68e7bb

Browse files
author
Pierre Poupin
authored
chore(example): fix typescript checks not running on the example (#152)
* chore(example): fix expo start command * chore(example): make ts work on the example * chore(example): fix incorrect program row on page with variable size * chore(example): fix/ignore remaining ts errors
1 parent aeb548e commit b68e7bb

17 files changed

Lines changed: 79 additions & 29 deletions

File tree

packages/example/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const TabNavigator = () => {
6464
);
6565
};
6666

67-
function App(): JSX.Element {
67+
function App() {
6868
useTVPanEvent();
6969
const { height, width } = useWindowDimensions();
7070
const areFontsLoaded = useFonts();

packages/example/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
"version": "1.0.0",
44
"main": "index.js",
55
"scripts": {
6-
"start": "expo start",
6+
"start": "EXPO_NO_CLIENT_ENV_VARS=1 EXPO_TV=1 expo start",
77
"android": "EXPO_NO_CLIENT_ENV_VARS=1 EXPO_TV=1 expo run:android",
88
"ios": "EXPO_NO_CLIENT_ENV_VARS=1 EXPO_TV=1 expo run:ios",
99
"web": "EXPO_NO_CLIENT_ENV_VARS=1 expo start --web",
1010
"build:web": "expo export -p web",
11+
"test:types": "tsc",
1112
"prebuild": "EXPO_TV=1 expo prebuild --clean"
1213
},
1314
"dependencies": {
@@ -32,7 +33,8 @@
3233
"react-native-safe-area-context": "4.10.1",
3334
"react-native-screens": "3.31.1",
3435
"react-native-svg": "15.2.0",
35-
"react-test-renderer": "^18.2.0"
36+
"react-test-renderer": "^18.2.0",
37+
"typescript": "^5.6.2"
3638
},
3739
"devDependencies": {
3840
"@babel/core": "^7.24.0",

packages/example/src/components/Menu/Menu.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ export const Menu = ({ state, navigation }: BottomTabBarProps) => {
112112
return (
113113
<Fragment key={route.key}>
114114
<MenuItem
115+
// @ts-expect-error TODO fix this type error
115116
label={menuItems[route.name].label}
117+
// @ts-expect-error TODO fix this type error
116118
icon={menuItems[route.name].icon}
117119
isMenuOpen={isMenuOpen}
118120
isActive={state.index === index}

packages/example/src/components/PanEvent/PanEvent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getGridCoordinates, moveFocus } from './PanEvent.utils';
22

33
class PanEvent {
4-
private orientation = undefined;
4+
private orientation: string | undefined = undefined;
55
private lastIndex = 0;
66

77
reset = () => {

packages/example/src/components/PanEvent/PanEvent.utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import { SupportedKeys } from '../remote-control/SupportedKeys';
44
import PanEvent from './PanEvent';
55
import { EMIT_KEY_DOWN_INTERVAL, GRID_SIZE, NUMBER_OF_COLUMNS } from './PanEvent.constants';
66

7-
export const getGridCoordinates = (x: number, y: number, panEvent: PanEvent): number => {
7+
export const getGridCoordinates = (
8+
x: number,
9+
y: number,
10+
panEvent: PanEvent,
11+
): number | undefined => {
812
const gridElementSize = GRID_SIZE / NUMBER_OF_COLUMNS;
913

1014
const xIndex = Math.floor((x + gridElementSize / 2) / gridElementSize);

packages/example/src/components/VirtualizedSpatialGrid.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { scaledPixels } from '../design-system/helpers/scaledPixels';
88
import { theme } from '../design-system/theme/theme';
99
import { Header } from '../modules/header/view/Header';
1010
import { BottomArrow, TopArrow } from '../design-system/components/Arrows';
11+
import { ProgramInfo } from '../modules/program/domain/programInfo';
1112

1213
const NUMBER_OF_ROWS_VISIBLE_ON_SCREEN = 2;
1314
const NUMBER_OF_RENDERED_ROWS = NUMBER_OF_ROWS_VISIBLE_ON_SCREEN + 5;
@@ -16,7 +17,9 @@ const INFINITE_SCROLL_ROW_THRESHOLD = 2;
1617

1718
export const VirtualizedSpatialGrid = ({ containerStyle }: { containerStyle?: ViewStyle }) => {
1819
const renderItem = useCallback(
19-
({ item, index }) => <ProgramNode programInfo={item} label={index?.toString?.()} />,
20+
({ item, index }: { item: ProgramInfo; index: number }) => (
21+
<ProgramNode programInfo={item} label={index?.toString?.()} />
22+
),
2023
[],
2124
);
2225

packages/example/src/components/remote-control/CustomEventEmitter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@ export default class CustomEventEmitter<Events extends Record<EventType, unknown
2929
off = <Key extends keyof Events>(eventType: Key, handler?: Handler<Events[keyof Events]>) => {
3030
this.handlers.set(
3131
eventType,
32+
// @ts-expect-error TODO fix the type error
3233
this.handlers.get(eventType).filter((h) => h !== handler),
3334
);
3435
};
3536

3637
emit = <Key extends keyof Events>(eventType: Key, evt?: Events[Key]) => {
3738
const eventTypeHandlers = this.handlers.get(eventType);
39+
// @ts-expect-error TODO fix the type error
3840
for (let index = eventTypeHandlers.length - 1; index >= 0; index--) {
41+
// @ts-expect-error TODO fix the type error
3942
const handler = eventTypeHandlers[index];
43+
// @ts-expect-error TODO fix the type error
4044
if (handler(evt)) {
4145
return;
4246
}

packages/example/src/hooks/useKey.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export const useKey = (key: SupportedKeys, callback: (pressedKey: SupportedKeys)
1313
if (actualKey !== key) return;
1414
return callback(key);
1515
};
16+
// @ts-expect-error TODO fix the type error
1617
RemoteControlManager.addKeydownListener(remoteControlListener);
18+
// @ts-expect-error TODO fix the type error
1719
return () => RemoteControlManager.removeKeydownListener(remoteControlListener);
1820
}, [key, callback]);
1921
};

packages/example/src/modules/header/view/Header.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ interface HeaderProps {
2525
}
2626

2727
export const Header = ({ title, description, verticalSize }: HeaderProps) => {
28+
// @ts-expect-error TODO fix type error
2829
const imageSource = images[Math.floor(Math.random() * 9)];
2930
return (
3031
<SpatialNavigationNode orientation="horizontal">

packages/example/src/modules/program/view/ProgramList.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type ProgramListProps = {
3333
data?: ProgramInfo[];
3434
listSize?: number;
3535
variant?: 'normal' | 'variable-size';
36-
parentRef?: MutableRefObject<SpatialNavigationVirtualizedListRef>;
36+
parentRef?: MutableRefObject<SpatialNavigationVirtualizedListRef | null>;
3737
isActive: boolean;
3838
};
3939

@@ -45,7 +45,7 @@ export const ProgramList = React.forwardRef<View, ProgramListProps>(
4545
({ orientation, containerStyle, data, parentRef, isActive, variant, listSize = 1000 }, ref) => {
4646
const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
4747
const theme = useTheme();
48-
const listRef = useRef<SpatialNavigationVirtualizedListRef>(null);
48+
const listRef = useRef<SpatialNavigationVirtualizedListRef | null>(null);
4949

5050
const renderItem = useCallback(
5151
({ item, index }: { item: ProgramInfo; index: number }) => (
@@ -80,13 +80,13 @@ export const ProgramList = React.forwardRef<View, ProgramListProps>(
8080
(pressedKey: SupportedKeys) => {
8181
const isBackKey = pressedKey === SupportedKeys.Back;
8282
const isRowActive = isActive && isScreenFocused;
83-
const isFirstElementFocused = listRef.current.currentlyFocusedItemIndex === 0;
83+
const isFirstElementFocused = listRef.current?.currentlyFocusedItemIndex === 0;
8484

8585
if (!isBackKey || !isRowActive || isFirstElementFocused) {
8686
return false;
8787
}
8888

89-
listRef.current.focus(0);
89+
listRef.current?.focus(0);
9090
return true;
9191
},
9292
[isActive, isScreenFocused, listRef],
@@ -104,8 +104,10 @@ export const ProgramList = React.forwardRef<View, ProgramListProps>(
104104
numberOfRenderedItems={WINDOW_SIZE}
105105
numberOfItemsVisibleOnScreen={NUMBER_OF_ITEMS_VISIBLE_ON_SCREEN}
106106
onEndReachedThresholdItemsNumber={NUMBER_OF_ITEMS_VISIBLE_ON_SCREEN}
107+
// @ts-expect-error TODO change the type from ReactElement to ReactNode in the core
107108
descendingArrow={isActive ? <LeftArrow /> : null}
108109
descendingArrowContainerStyle={styles.leftArrowContainer}
110+
// @ts-expect-error TODO change the type from ReactElement to ReactNode in the core
109111
ascendingArrow={isActive ? <RightArrow /> : null}
110112
ascendingArrowContainerStyle={styles.rightArrowContainer}
111113
ref={(elementRef) => {
@@ -124,11 +126,13 @@ export const ProgramsRow = ({
124126
variant = 'normal',
125127
listSize,
126128
parentRef,
129+
data,
127130
}: {
128131
containerStyle?: object;
129132
variant?: 'normal' | 'variable-size';
130133
listSize?: number;
131-
parentRef?: MutableRefObject<SpatialNavigationVirtualizedListRef>;
134+
parentRef?: MutableRefObject<SpatialNavigationVirtualizedListRef | null>;
135+
data?: ProgramInfo[];
132136
}) => {
133137
const theme = useTheme();
134138
return (
@@ -143,6 +147,7 @@ export const ProgramsRow = ({
143147
listSize={listSize}
144148
parentRef={parentRef}
145149
isActive={isActive}
150+
data={data}
146151
/>
147152
)}
148153
</SpatialNavigationNode>

0 commit comments

Comments
 (0)