This is a sample implementation of TouchableOpacity, which turns a view such as an image into a button in ReactNative.
Tap on an image of Kabigon to get an alert.
react-native: 0.56.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component} from 'react'; | |
import {AppRegistry} from 'react-native'; | |
import { | |
StyleSheet, | |
Button, | |
TouchableOpacity, | |
View, | |
Alert, | |
Image | |
} from 'react-native'; | |
import {name as appName} from './app.json'; | |
export class App extends Component { | |
render() { | |
return ( | |
<View style={styles.container}> | |
<TouchableOpacity | |
onPress={() => Alert.alert('Hello')}> | |
<Image | |
style={styles.image} | |
source={require('./image/kabigon.png')} | |
/> | |
</TouchableOpacity> | |
</View> | |
); | |
} | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
}, | |
image: { | |
width: 250, | |
height: 250, | |
} | |
}); | |
AppRegistry.registerComponent(appName, () => App); | |