Skip to content

Add typescript definition file #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Installation with yarn
yarn add react-native-hooks
```

## Typescript

✅ A Typescript definition file is included with the library

## API
- [useAccessibilityInfo](https://github.com/react-native-community/react-native-hooks#useaccessibilityinfo)
- [useAppState](https://github.com/react-native-community/react-native-hooks#useappstate)
Expand Down
37 changes: 37 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
AppState,
AppStateStatus,
ScaledSize,
KeyboardStatic,
GetPhotosReturnType,
LayoutRectangle
} from "react-native";

export interface DeviceOrientation {
portrait?: boolean;
landscape?: boolean;
}

declare function useDimensions(): { window: ScaledSize; screen: ScaledSize };
declare function useAppState(): AppStateStatus;
declare function useBackHandler(handler: () => boolean): void;
declare function useCameraRoll(): {
photos: GetPhotosReturnType;
getPhotos: (config?: { first: number; groupTypes: string }) => Promise<void>;
saveToCameraRoll: (tag: string, type?: "photo" | "video") => Promise<void>;
};
declare function useClipboard(): {
data: string;
setString: (content: string) => void;
};
declare function useAccessibilityInfo(): boolean;
declare function useKeyboard(): KeyboardStatic;
declare function useInteractionManager(): boolean;
declare function useDeviceOrientation(): DeviceOrientation;
declare function useLayout(): LayoutRectangle & {
onLayout: (event: {
nativeEvent: {
layout: LayoutRectangle;
};
}) => void;
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type LayoutRectangle could be imported from react-native and then this could be changed to:

declare function useLayout(): LayoutRectangle & {
  onLayout: (event: {
    nativeEvent: {
      layout: { x: number; y: number; width: number; height: number };
    };
  }) => void;
};