单击React Native中的图像

发布于 2025-01-25 02:15:00 字数 276 浏览 1 评论 0原文

我正在使用一个使用图像的应用程序,当单击图像时,将显示一个新的随机图像。这是在React Native中。我不知道该怎么做或去哪里获取更多信息。这是代码。

      <Image
        style={{ 
          width: 300,
          height: 300,
        }}
        source={
          require('./cards/card.png')
        }
      />

I am working on an app that uses images and when the image is clicked, a new random image from a folder is to display. This is in React Native. I have no clue how to do it or where to go to get more information. Here is the code.

      <Image
        style={{ 
          width: 300,
          height: 300,
        }}
        source={
          require('./cards/card.png')
        }
      />

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

骑趴 2025-02-01 02:15:00

可压制是另一个选择。
您可以在此处查看React文档。
https://reaectnative.dev/docs/docs/pressable

<Pressable onPress={onPressFunction}>
      <Image
        style={{ 
          width: 300,
          height: 300,
        }}
        source={
          require('./cards/card.png')
        }
      />
</Pressable>

Pressable is another option.
You can check React documentation here.
https://reactnative.dev/docs/pressable

<Pressable onPress={onPressFunction}>
      <Image
        style={{ 
          width: 300,
          height: 300,
        }}
        source={
          require('./cards/card.png')
        }
      />
</Pressable>
苏别ゝ 2025-02-01 02:15:00

您可以用&lt; image/&gt;组件使用touchableOpacity其他touchable component。并使用道具或状态进行图像源动态。

例如:

您的状态

const [imageUri, setImageUri] = useState('')

const handlePress = () => {
   // some logic random the image
}

您的组件


<TouchableOpacity onPress={handlePress}>
    <Image source={{
          uri: imageUri
        }}/>
<TouchableOpacity>

参考: https://reaectnative.dev/dev/dev/docs/touchables/touchableopace

You can wrap your <Image /> component with TouchableOpacity other Touchable component. And make the image source dynamic using props or state.

For instance :

Your state

const [imageUri, setImageUri] = useState('')

const handlePress = () => {
   // some logic random the image
}

Your component


<TouchableOpacity onPress={handlePress}>
    <Image source={{
          uri: imageUri
        }}/>
<TouchableOpacity>

Reference: https://reactnative.dev/docs/touchableopacity

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文