In this lesson, you will learn how to go beyond default button styles by crafting custom press effects that make your interface feel like high-end, responsive hardware.
When a user taps an element, they expect immediate physical confirmation. While basic components handle clicks, creating custom feedback involves orchestrating how an element responds visually the moment it is touched. By using state-driven interactions—a concept we mastered in lesson 25—we can manipulate the opacity or scale of a View to simulate the tactile sensation of a physical button being pressed.
Designing the Feedback Loop
To build a professional touch effect, you need to track the "pressed" state of your component. You can then use this state to conditionally apply styles. Think of it as a toggle: when the user holds their finger down, the component "dips" or fades; when they release, it pops back to its original state.
Here is how you can implement a simple scale-down effect to simulate pressure:
import React, { useState } from 'react';
import { Pressable, View, Text } from 'react-native';
const CustomButton = () => {
const [isPressed, setIsPressed] = useState(false);
return (
<Pressable
onPressIn={() => setIsPressed(true)}
onPressOut={() => setIsPressed(false)}
>
<View style={{
transform: [{ scale: isPressed ? 0.95 : 1 }],
backgroundColor: isPressed ? '#ddd' : '#007AFF',
padding: 20,
borderRadius: 10
}}>
<Text style={{ color: 'white' }}>Tap Me</Text>
</View>
</Pressable>
);
};
Why This Matters
By controlling the visual state through onPressIn and onPressOut, you stop relying on generic system defaults and start designing a cohesive brand experience. These small, fluid transitions reduce "touch latency" perception, making your app feel snappy and alive under the user’s fingertips. Even a slight scale reduction of 5% provides enough sensory feedback to reassure the user that their input was successfully registered by the device.
Key Takeaway: Custom touch feedback turns static interface elements into responsive components by linking visual state changes directly to the user's touch events.