Skip to content

Feat/add haptics to Drawer #1266

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

Merged
merged 6 commits into from
May 23, 2021
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: 0 additions & 4 deletions generatedTypes/components/drawer/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ interface Props {
* Callback for just before right item full swipe
*/
onWillFullSwipeRight?: Function;
/**
* Haptic trigger function to use onToggleSwipeLeft
*/
leftToggleHapticTrigger?: Function;
/**
* Style
*/
Expand Down
7 changes: 6 additions & 1 deletion src/components/drawer/Swipeable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import React, {Component} from 'react';
import {Animated, StyleSheet, View, I18nManager} from 'react-native';
import {PanGestureHandler, TapGestureHandler, State} from 'react-native-gesture-handler';
import {Constants} from '../../helpers';
import {HapticService} from '../../services';


const DRAG_TOSS = 0.05;
const LEFT_TOGGLE_THRESHOLD = 0.6;
const HAPTIC_METHOD = 'impactMedium';

// Math.sign polyfill for iOS 8.x
if (!Math.sign) {
Expand Down Expand Up @@ -123,7 +125,8 @@ export default class Swipeable extends Component<Props, StateType> {
if (!this.dragThresholdReached && x >= threshold && x < threshold + 10) {
// move item right
this.dragThresholdReached = true;
onToggleSwipeLeft({rowWidth, leftWidth, dragX: x, triggerHaptic: true});
HapticService.triggerHaptic(HAPTIC_METHOD, 'Drawer');
onToggleSwipeLeft({rowWidth, leftWidth, dragX: x});
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should keep the haptic optional, not all users will want to use it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not get the haptic method from the HapticService, i.e. HapticMethods.impactMedium?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll be able to do that only when I'll fix the HapticMethods in the HapticService as we talked about in our dev sync.
I'm waiting for this PR to be merged to do so

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok. Add the other PR as a dependency and we'll merge this after it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the dependency merged?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes :)

}
if (this.dragThresholdReached && x < threshold - 10) {
// move item left
Expand Down Expand Up @@ -260,8 +263,10 @@ export default class Swipeable extends Component<Props, StateType> {
// Swipe left toggle
toValue = rowWidth * LEFT_TOGGLE_THRESHOLD;
} else if (!onToggleSwipeLeft && fullSwipeLeft && translationX > rowWidth * fullLeftThreshold) {
HapticService.triggerHaptic(HAPTIC_METHOD, 'Drawer');
toValue = rowWidth;
} else if (fullSwipeRight && translationX < -rowWidth * fullRightThreshold) {
HapticService.triggerHaptic(HAPTIC_METHOD, 'Drawer');
toValue = -rowWidth;
} else if (translationX > leftThreshold) {
if (!onToggleSwipeLeft || onToggleSwipeLeft && translationX < rowWidth * LEFT_TOGGLE_THRESHOLD) {
Expand Down
7 changes: 0 additions & 7 deletions src/components/drawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ interface Props {
* Callback for just before right item full swipe
*/
onWillFullSwipeRight?: Function;
/**
* Haptic trigger function to use onToggleSwipeLeft
*/
leftToggleHapticTrigger?: Function;
/**
* Style
*/
Expand Down Expand Up @@ -214,9 +210,6 @@ class Drawer extends PureComponent<Props> {

private onToggleSwipeLeft = (options?: any) => {
if (this.props.onToggleSwipeLeft) {
if (options?.triggerHaptic) {
_.invoke(this.props, 'leftToggleHapticTrigger');
}
this.animateItem(options);
}
};
Expand Down