Skip to content

Instantly share code, notes, and snippets.

@Krisztiaan
Last active August 26, 2020 20:54
Show Gist options
  • Save Krisztiaan/11856c0faffc70f00766b7f791375a75 to your computer and use it in GitHub Desktop.
Save Krisztiaan/11856c0faffc70f00766b7f791375a75 to your computer and use it in GitHub Desktop.
Simple react-native-tvos typescript support. Use with `patch-package`.
diff --git a/node_modules/@types/react-native/index.d.ts b/node_modules/@types/react-native/index.d.ts
index dba6a80..114a383 100644
--- a/node_modules/@types/react-native/index.d.ts
+++ b/node_modules/@types/react-native/index.d.ts
@@ -63,6 +63,41 @@
import * as React from 'react';
+export const TVMenuControl: {
+ enableTVMenuKey(): void;
+ disableTVMenuKey(): void;
+};
+
+export interface HWKeyEvent {
+ eventType: string;
+ eventKeyAction: number;
+ tag?: number;
+};
+
+export class TVEventHandler {
+ enable<T extends React.Component<unknown>>(
+ component?: T,
+ callback?: (component: T, data: HWKeyEvent) => void
+ ): void;
+ disable(): void;
+};
+
+export interface FocusGuideProps extends ViewProps {
+ /**
+ * Array of `Component`s to register as destinations with `UIFocusGuide`
+ */
+ destinations?: (null | number | React.Component<any, any> | React.ComponentClass<any>)[]
+};
+
+/**
+ * This component provides support for Apple's `UIFocusGuide` API,
+ * to help ensure that focusable controls can be navigated to,
+ * even if they are not directly in line with other controls.
+ * An example is provided in `RNTester` that shows two different ways of using this component.
+ * https://github.com/react-native-community/react-native-tvos/blob/master/RNTester/js/TVFocusGuideExample.js
+ */
+export declare class TVFocusGuideView extends React.Component<FocusGuideProps> {}
+
type Constructor<T> = new (...args: any[]) => T;
export type MeasureOnSuccessCallback = (
@pedro-pedrosa
Copy link

would it make sense to add this to DefinitelyTyped? and follow the same approach as the react-native-tvos module and have users change their package.json manually:

  "devDependencies": {
    "@types/react-native": "npm:@types/react-native-tvos@^0.62.14",
  }

I would definitely add a few contributions

@Krisztiaan
Copy link
Author

Yeah I'll look into it tomorrow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment