如何在模块react-native-image-viewer中使用onSwipeDown道具时获取数组中图像的URL或索引,并显示console.log(图像的索引或URL)。谢谢!https://github.com/ascoders/react-native-image-viewer。
嗨,欢迎来到Stack Overflow!似乎该库未提供上述功能的API。因此,看起来您将需要维护一个状态,以使用onChange
组件的prop存储当前选定的索引,并且在onSwipeDown
调用该状态时,从该状态获取索引(和URL)。
import { Modal } from 'react-native';
import ImageViewer from 'react-native-image-zoom-viewer';
const images = [{
url: 'https://avatars2.githubusercontent.com/u/7970947?v=3&s=460',
}, {
url: 'https://avatars2.githubusercontent.com/u/7970947?v=3&s=460'
}, {
url: 'https://avatars2.githubusercontent.com/u/7970947?v=3&s=460'
}]
export default class App extends React.Component {
handleChange = (index) => {
this.setState({ currentIndex: index })
}
handleSwipeDown = (index) => {
const { currentIndex } = this.state;
const { url } = images[currentIndex];
// do whatever
}
render() {
return (
<Modal visible={true} transparent={true}>
<ImageViewer
imageUrls={images}
onChange={this.handleChange}
onSwipeDown={this.handleSwipeDown}
/>
</Modal>
)
}
}
参见docs。希望这可以帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句