Files
mattermost-mobile/app/components/touchable_with_feedback/touchable_with_feedback.ios.tsx
Elias Nahum 7aa5bd0611 Update Dependencies and bug fixes (#7000)
* update dependencies

* update dependencies

* feedback review

* update @mattermost/react-native-turbo-mailer
2023-01-24 09:14:23 +02:00

57 lines
1.8 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {memo} from 'react';
import {PanResponder, Touchable, TouchableHighlight, TouchableOpacity, TouchableWithoutFeedback, View} from 'react-native';
type TouchableProps = Touchable & {
cancelTouchOnPanning: boolean;
children: React.ReactNode | React.ReactNode[];
testID: string;
type: 'native' | 'opacity' | 'none';
}
const TouchableWithFeedbackIOS = ({testID, children, type = 'native', cancelTouchOnPanning, ...props}: TouchableProps) => {
const panResponder = React.useRef(PanResponder.create({
onMoveShouldSetPanResponderCapture: (evt, gestureState) => {
return cancelTouchOnPanning && (gestureState.dx >= 5 || gestureState.dy >= 5 || gestureState.vx > 5);
},
}));
switch (type) {
case 'native':
return (
<View
testID={testID}
{...panResponder?.current.panHandlers}
>
<TouchableHighlight
{...props}
>
{children}
</TouchableHighlight>
</View>
);
case 'opacity':
return (
<TouchableOpacity
testID={testID}
{...props}
>
{children}
</TouchableOpacity>
);
default:
return (
<TouchableWithoutFeedback
testID={testID}
{...props}
>
{children}
</TouchableWithoutFeedback>
);
}
};
export default memo(TouchableWithFeedbackIOS);