react-native#TouchableWithoutFeedbackProps JavaScript Examples

The following examples show how to use react-native#TouchableWithoutFeedbackProps. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScaleButton.js    From react-native-component-kits with MIT License 5 votes vote down vote up
ScaleButton = ({
    children,
    style,
    scaleSize = 0.8,
    onPress = () => {},
    ...rest
}: TouchableWithoutFeedbackProps) => {
    const scale = useRef(new Animated.Value(1)).current;

    const onPressIn = () => {
        scale.stopAnimation(() => {
            Animated.spring(scale, {
                toValue: scaleSize,
                useNativeDriver: true,
                friction: 1000,
            }).start();
        });
    };
    const onPressOut = () => {
        scale.stopAnimation(() => {
            Animated.spring(scale, {
                toValue: 1,
                useNativeDriver: true,
                friction: 1000,
            }).start();
        });
    };

    const onPressButton = () => {
        requestAnimationFrame(onPress);
    };

    return (
        <TouchableWithoutFeedbackAnimation
            style={{ transform: [{ scale }] }}
            onPressIn={onPressIn}
            onPressOut={onPressOut}
            {...rest}
            onPress={onPressButton}>
            {children}
        </TouchableWithoutFeedbackAnimation>
    );
}