/**
* Created by anjar on 12/15/16.
*/
import React from "react";
import {
Platform,
TouchableHighlight,
TouchableNativeFeedback,
TouchableOpacity,
View,
} from "react-native";
import debounce from "lodash/debounce";
import PropTypes from "prop-types";
import { FlipColors } from "@flip.id/ui-kit";
import { TimeConstant } from "../../constants";
import { AppUtils } from "../../utils";
const DEFAULT_THRESHOLD_INTERVAL_CLICK = TimeConstant.SECOND.TWO;
const Touchable = ({ accessible = true, ...props }) => {
const zero_padding = {
padding: 0,
paddingLeft: 0,
paddingRight: 0,
paddingTop: 0,
paddingBottom: 0,
paddingHorizontal: 0,
paddingVertical: 0,
};
const zero_margin = {
margin: 0,
marginLeft: 0,
marginRight: 0,
marginTop: 0,
marginBottom: 0,
marginHorizontal: 0,
marginVertical: 0,
};
const container_style = {
...zero_padding,
overflow: "hidden",
flexDirection: "row",
borderWidth: 0,
};
const component_style = {
...zero_margin,
flex: 1,
};
const debouncedOnPress = () => {
props.onPress?.();
};
const onPress = props.preventFastClick
? debounce(
debouncedOnPress,
props.fastClickInterval ?? DEFAULT_THRESHOLD_INTERVAL_CLICK,
{ leading: true, trailing: false }
)
: props.onPress;
const isHighlightProps =
props.feedback === "highlight" ||
(AppUtils.isIOS() && props.iosFeedback === "highlight") ||
(AppUtils.isAndroid() && props.androidFeedback === "highlight");
if (isHighlightProps) {
return (
{props.children}
);
}
const version = Platform.Version;
if (version >= 21 && Platform.OS === "android") {
if (props.is_prevent_ripple_overflow) {
return (
{props.children}
);
} else {
return (
{props.children}
);
}
} else {
return (
{props.children}
);
}
};
Touchable.propTypes = {
is_prevent_ripple_overflow: PropTypes.bool,
onPress: PropTypes.func,
onPressOut: PropTypes.func,
preventFastClick: PropTypes.bool,
feedback: PropTypes.string,
iosFeedback: PropTypes.string,
androidFeedback: PropTypes.string,
};
export default Touchable;