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

Add duration to long press event #1505

Merged
merged 4 commits into from
Jul 16, 2021

Conversation

j-piasecki
Copy link
Member

@j-piasecki j-piasecki commented Jul 15, 2021

Description

Fixes #1090.

Added duration property to the LongPressGestureHandler events. This change allows to check how long the entire event lasted.

Code I used to test it:

import React, { Component } from 'react';
import { StyleSheet, View } from 'react-native';

import {
  LongPressGestureHandler,
  LongPressGestureHandlerStateChangeEvent,
} from 'react-native-gesture-handler';

export class PressBox extends Component {
  private onHandlerStateChange = (
    event: LongPressGestureHandlerStateChangeEvent
  ) => {
    console.log(`Duration: ${event.nativeEvent.duration}`);
  };

  render() {
    return (
      <LongPressGestureHandler
        onHandlerStateChange={this.onHandlerStateChange}
        minDurationMs={600}>
          <View style={styles.box} />
      </LongPressGestureHandler>
    );
  }
}

export default class Example extends Component {
  render() {
    return (
      <PressBox />
    );
  }
}

const styles = StyleSheet.create({
  box: {
    width: 150,
    height: 150,
    alignSelf: 'center',
    backgroundColor: 'plum',
    margin: 10,
    zIndex: 200,
  },
});

@jakub-gonet jakub-gonet self-assigned this Jul 15, 2021
Copy link
Member

@jakub-gonet jakub-gonet left a comment

Choose a reason for hiding this comment

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

If you have a code example you tested it on, please attach it to the PR description.

I wonder if calculating duration in extractEventData is a good idea since this effectively ties this method to state transitions. We can alternatively store it and send it only when the state transitions to FINISHED or FAILED.

ios/Handlers/RNLongPressHandler.m Outdated Show resolved Hide resolved
@jakub-gonet jakub-gonet changed the title Long press duration Add duration to long press event Jul 16, 2021
@jakub-gonet jakub-gonet merged commit 777fab8 into software-mansion:master Jul 16, 2021
@jakub-gonet
Copy link
Member

🍉 🍉 🍉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose the duration of press in LongPressGestureHandler
2 participants