[英]React Native Touchable Opacity Issue
I am trying to create a Button/Icon Component updates icon image based on the url I am linking the user to. 我正在尝试基于将用户链接到的URL创建按钮/图标组件更新图标图像。 For example I have a movie object and I want to link users to imdb and rotten tomatoes.
例如,我有一个电影对象,我想将用户链接到imdb和烂番茄。 I want that component to show the icon for rotten tomatoes when linking the rotten tomatoes deep link and the imdb icon when linking imdb url.
我希望该组件在链接烂番茄深链接时显示烂番茄图标,而在链接imdb url时显示imdb图标。
I am rendering the data from an array. 我正在从数组渲染数据。 For example:
例如:
const Movie = [
{ key: 1,
tile: Good Will Hunting
icon1:'./images/imdb.png',
url1: 'http://www.imdb.com/title/tt0119217/?ref_=nv_sr_1',
icon2:'./images/rottentomatoes'
url2: 'https://www.rottentomatoes.com/m/good_will_hunting'
<View>
<TouchableOpacity onPress={this._handleOpenWithLinkingUrlOne}>
<Image
source={require("url one icon")}
style={styles.ImageIconStyle}
/>
</TouchableOpacity>
<TouchableOpacity onPress={this._handleOpenWithLinkingUrlTwo}>
<Image
source={require("url two icon")}
style={styles.ImageIconStyle}
/>
</TouchableOpacity>
</View>
_handleOpenWithLinkingUrlOne = () => {
Linking.openURL("data from url two");
};
_handleOpenWithLinkingUrlTwo = () => {
Linking.openURL("data from url two");
};
How can I pull the data from the object to both so it renders the data? 如何将数据从对象中拉到两者,以便它呈现数据?
您可以将数据设置为状态,然后在图像组件上使用source={{uri: this.state.movie.uri1}}
或source={{uri: this.state.movie.uri2}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.