Skip to content
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

Copy Directions enum to JS #1366

Merged
merged 7 commits into from
Feb 16, 2021
Merged
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
10 changes: 8 additions & 2 deletions src/Directions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import RNGestureHandlerModule from './RNGestureHandlerModule';
export const Directions = {
RIGHT: 1,
LEFT: 2,
UP: 4,
DOWN: 8,
} as const;

export default RNGestureHandlerModule.Direction;
// eslint-disable-next-line @typescript-eslint/no-redeclare -- backward compatibility; it can be used as a type and as a value
export type Directions = typeof Directions[keyof typeof Directions];
18 changes: 10 additions & 8 deletions src/RNGestureHandlerModule.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { NativeModules } from 'react-native';

const { RNGestureHandlerModule } = NativeModules;

type Directions = Readonly<{
RIGHT: 1;
LEFT: 2;
UP: 4;
DOWN: 8;
}>;
if (RNGestureHandlerModule == null) {
console.error(
`react-native-gesture-handler module was not found. Make sure you're running your app on the native platform and your code is linked properly (cd ios && pod install && cd ..).

For installation instructions, please refer to https://docs.swmansion.com/react-native-gesture-handler/docs/#installation`
.split('\n')
.map((line) => line.trim())
.join('\n')
);
}

export type RNGestureHandlerModuleProps = {
Direction: Directions;
handleSetJSResponder: (tag: number, blockNativeResponder: boolean) => void;
handleClearJSResponder: () => void;
createGestureHandler: (
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { default as Directions } from './Directions';
export { Directions } from './Directions';
export { State } from './State';
export { default as gestureHandlerRootHOC } from './gestureHandlerRootHOC';
export { default as GestureHandlerRootView } from './GestureHandlerRootView';
Expand Down