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

feat: pan gesture timeout configurable by prop #43

Merged
merged 3 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -82,6 +82,10 @@ There are three events fired when the user interacts with the graph:
2. `onPointSelected`: Fired for each point the user pans through. You can use this event to update labels or highlight selection in the graph.
3. `onGestureEnd`: Fired once the user releases his finger and the pan gesture _deactivates_.

Pan gesture can be configures using these props:

1. `panGestureTimeout`: Set timeout for the pan gesture to activate. Set to `0` to start immediately after touch. Defaults to `300`.

Example:

```jsx
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
"useTabs": false,
"semi": false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is necessary otherwise it is adding semicolons everywhere on save.

},
"react-native-builder-bob": {
"source": "src",
Expand Down
5 changes: 4 additions & 1 deletion src/AnimatedLineGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export function AnimatedLineGraph({
onPointSelected,
onGestureStart,
onGestureEnd,
panGestureTimeout = 300,
SelectionDot = DefaultSelectionDot,
enableIndicator = false,
indicatorPulsating = false,
Expand All @@ -79,7 +80,9 @@ export function AnimatedLineGraph({
const [height, setHeight] = useState(0)
const interpolateProgress = useValue(0)

const { gesture, isActive, x } = usePanGesture({ holdDuration: 300 })
const { gesture, isActive, x } = usePanGesture({
holdDuration: panGestureTimeout,
})
const circleX = useValue(0)
const circleY = useValue(0)
const pathEnd = useValue(0)
Expand Down
4 changes: 4 additions & 0 deletions src/LineGraphProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export type AnimatedLineGraphProps = BaseLineGraphProps & {
* Let's the indicator pulsate
*/
indicatorPulsating?: boolean
/**
* Timeout before the pan gesture starts
*/
panGestureTimeout?: number

/**
* Called for each point while the user is scrubbing/panning through the graph
Expand Down