//App.js
import React, { useState } from 'react';
import { View,TouchableOpacity,Text,Vibration,StyleSheet} from 'react-native';
const App = () => {
const [vibrating, setVibrating] = useState(false);
const startCustomVibration = () => {
setVibrating(true);
// Short, short, short, long, long, long
const pattern = [200, 100, 200, 100, 200, 1000];
// Repeat the pattern
Vibration.vibrate(pattern, true);
};
const stopVibration = () => {
setVibrating(false);
Vibration.cancel();
};
return (
<View style={styles.container}>
<Text style={styles.heading}>
Geeksforgeeks!
</Text>
<TouchableOpacity
style={[styles.button, vibrating &&
styles.disabledButton]}
onPress={startCustomVibration}
disabled={vibrating}
>
<Text style={styles.buttonText}>
Start Custom Vibration
</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.button, !vibrating &&
styles.disabledButton]}
onPress={stopVibration}
disabled={!vibrating}
>
<Text style={styles.buttonText}>
Stop Vibration
</Text>
</TouchableOpacity>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#f5f5f5',
},
heading: {
color: 'green',
fontSize: 30,
fontWeight: 'bold',
marginBottom: 20,
},
button: {
backgroundColor: '#3498db',
paddingVertical: 15,
paddingHorizontal: 30,
borderRadius: 5,
marginVertical: 10,
},
disabledButton: {
backgroundColor: '#bdc3c7',
},
buttonText: {
color: 'white',
fontSize: 16,
fontWeight: 'bold',
},
});
export default App;