Showing posts with label TouchableOpacity. Show all posts
Showing posts with label TouchableOpacity. Show all posts

10 February 2020

TouchableOpacity with image example in react native

  • Create Components folder under src folder
  • Add TouchableOpacitywithImage.js file and add below Code
import React from "react";
import { TouchableOpacity, View, Text, Image } from "react-native";

const callFun = () => {
  alert("Clicked on Touchable Opacity with Image Button!!!");
};
let Image_Http_URL = {
  uri:
    "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgACm31aFPgZwjcGKe50tWTegyxzgNfYG94Jp2ZO48mE6RKXEFNZnkyODDqiEuGq8fevZe8oZn5gmDR_vQNmsKQ0nZ5y_ipkkRyZ203gpMXYv1hqTTxataPt5JWKuVM4w9GBMCQHOkGZV4/s1600/logo.png"
};

const TouchableOpacitywithImage = () => {
  return (
    <View>
      <Text> TouchableOpacity with Image example</Text>
      <TouchableOpacity onPress={callFun}>
        <Image
          style={{ height: 200, width: 350, resizeMode: "stretch" }}
          source={Image_Http_URL}
        />
      </TouchableOpacity>
    </View>
  );
};
export default TouchableOpacitywithImage;
  • Open App.js file and update code as below


import React from 'react';
import { View,StyleSheet } from 'react-native';
import TouchableOpacitywithImage from './src/Component/TouchableOpacitywithImage'

 const  App=()=> {
  return (
    <View style={styles.container}>
      <TouchableOpacitywithImage/>
    </View>
  );
}
export default App;

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    paddingTop:80
  },
});

Output:

TouchableOpacity with multiLine example in react native

  • Create Components folder under src folder
  • Add TouchableOpacitywithMultiLine.js file and add below Code
import React from "react";
import { TouchableOpacity, View, Text } from "react-native";

const callFun = () => {
  alert("Clicked on Touchable Opacity Multiple Line Text Button!!!");
};

const TouchableOpacitywithMultiLine = () => {
  return (
    <View>
      <Text> TouchableOpacity with Multiple Line text example</Text>
      <TouchableOpacity onPress={callFun} style={styles.myStyle}>
        <Text>Touchable Opacity Button Line1</Text>
        <Text>Touchable Opacity Button Line2</Text>
        <Text>Touchable Opacity Button Line3</Text>
        <Text>Touchable Opacity Button Line4</Text>
      </TouchableOpacity>
    </View>
  );
};
export default TouchableOpacitywithMultiLine;
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 TouchableOpacitywithMultiLine from './src/Component/TouchableOpacitywithMultiLine'

 const  App=()=> {
  return (
    <View style={styles.container}>
      <TouchableOpacitywithMultiLine/>
    </View>
  );
}
export default App;

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    paddingTop:80
  },
});

Output:

TouchableOpacity example in react native

  • 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
  },
});


Output: