This app shows a blue box that is invisible at first. When you press the button, the box fades in smoothly. This makes the app feel polished and interactive.
import React from 'react';
import { View, Text, StyleSheet, TouchableOpacity, Animated } from 'react-native';
export default function AdvancedUIExample() {
const animation = React.useRef(new Animated.Value(0)).current;
const startAnimation = () => {
Animated.timing(animation, {
toValue: 1,
duration: 500,
useNativeDriver: true,
}).start();
};
return (
<View style={styles.container}>
<Animated.View style={[styles.box, {opacity: animation}]} />
<TouchableOpacity onPress={startAnimation} style={styles.button} accessibilityLabel="Start animation button">
<Text style={styles.buttonText}>Start Animation</Text>
</TouchableOpacity>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#f0f0f0',
},
box: {
width: 100,
height: 100,
backgroundColor: '#4a90e2',
marginBottom: 20,
borderRadius: 10,
},
button: {
backgroundColor: '#007aff',
paddingVertical: 10,
paddingHorizontal: 20,
borderRadius: 5,
},
buttonText: {
color: 'white',
fontWeight: 'bold',
fontSize: 16,
},
});