- Create Components folder under src folder
- Add TouchableOpacityEXP1.js file and add below Code
import React from "react";
import { TouchableOpacity, View, Text ,StyleSheet} from "react-native";
const callFun = () => {
alert("Clicked on Touchable Opacity Button!!!");
};
const TouchableOpacityEXP1 = () => {
return (
<View>
<Text> TouchableOpacity with Single Line text example</Text>
<TouchableOpacity onPress={callFun} style={styles.myStyle}>
<Text>Touchable Opacity Button</Text>
</TouchableOpacity>
</View>
);
};
export default TouchableOpacityEXP1;
const styles = StyleSheet.create({
myStyle: {
textAlign: "center",
fontWeight: "bold",
fontSize: 30,
backgroundColor:'#ff0000',
padding:20
}
});
- Open App.js file and update code as below
import React from 'react';
import { View,StyleSheet } from 'react-native';
import TouchableOpacityEXP1 from './src/Component/TouchableOpacityEXP1'
const App=()=> {
return (
<View style={styles.container}>
<TouchableOpacityEXP1/>
</View>
);
}
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
paddingTop:80
},
});
No comments:
Post a Comment