verdnatura-chat/app/utils/touch.tsx

51 lines
1.1 KiB
TypeScript
Raw Normal View History

2019-12-04 16:39:53 +00:00
import React from 'react';
2022-04-28 20:10:31 +00:00
import { RectButton, RectButtonProps, TouchableOpacity } from 'react-native-gesture-handler';
2019-12-04 16:39:53 +00:00
import { TSupportedThemes } from '../theme';
import { themes } from '../lib/constants';
2019-12-04 16:39:53 +00:00
interface ITouchProps extends RectButtonProps {
children: React.ReactNode;
theme: TSupportedThemes;
accessibilityLabel?: string;
testID?: string;
2022-04-28 20:10:31 +00:00
touchable?: boolean;
}
class Touch extends React.Component<ITouchProps> {
private ref: any;
setNativeProps(props: ITouchProps): void {
2019-12-04 16:39:53 +00:00
this.ref.setNativeProps(props);
}
getRef = (ref: RectButton): void => {
2019-12-04 16:39:53 +00:00
this.ref = ref;
};
render(): JSX.Element {
2022-04-28 20:10:31 +00:00
const { children, onPress, theme, underlayColor, touchable, ...props } = this.props;
if (touchable) {
return (
<TouchableOpacity onPress={onPress as () => void} {...(props as any)}>
{children}
</TouchableOpacity>
);
}
2019-12-04 16:39:53 +00:00
return (
<RectButton
ref={this.getRef}
onPress={onPress}
activeOpacity={1}
underlayColor={underlayColor || themes[theme].bannerBackground}
2019-12-04 16:39:53 +00:00
rippleColor={themes[theme].bannerBackground}
{...props}>
2019-12-04 16:39:53 +00:00
{children}
</RectButton>
);
}
}
export default Touch;