Nessuna descrizione

PicAndTextImageSwiperViewController.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * Created by zack on 2018/5/22.
  3. */
  4. import {
  5. View,
  6. Text,
  7. StyleSheet,
  8. Platform,
  9. ScrollView,
  10. Image,
  11. TouchableOpacity
  12. } from 'react-native'
  13. import React, {Component} from 'react'
  14. import {NavigationBarHeight, TabBarHeight, ScreenDimensions} from '../../../utils/DimensionsTools'
  15. import ImageLoader from 'react-native-smart-image-loader'
  16. import {CachedImage} from 'react-native-img-cache'
  17. export default class PicAndTextImageSwiperViewController extends Component {
  18. constructor(props) {
  19. super(props)
  20. this.state = {
  21. imageUrls: props.imageUrls,
  22. currentPage: 0
  23. }
  24. }
  25. onAnimationEnd(e){
  26. // 求出水平方向上的偏移量
  27. const offSetX = e.nativeEvent.contentOffset.x
  28. // 计算当前页码
  29. const currentPage = offSetX / (ScreenDimensions.width)
  30. // 重新绘制UI
  31. this.setState({currentPage: currentPage})
  32. }
  33. renderImageListViews() {
  34. let imageViews = []
  35. for (let i = 0; i < this.state.imageUrls.length; i ++) {
  36. const imageUrl = this.state.imageUrls[i]
  37. let imageView = (
  38. <CachedImage key= {i} source={{uri: imageUrl}} style={styles.ImageView} resizeMode={'contain'}/>
  39. )
  40. imageViews.push(imageView)
  41. }
  42. return imageViews
  43. }
  44. render() {
  45. return(
  46. <View style={styles.View}>
  47. <ScrollView onMomentumScrollEnd={(e) => this.onAnimationEnd(e)} style= {styles.View} pagingEnabled={true} horizontal={true}>
  48. {this.renderImageListViews()}
  49. </ScrollView>
  50. <TouchableOpacity onPress={() => {
  51. this.props.navigator.pop()
  52. }} style= {styles.BackButton}>
  53. <Image source={require('../../../resources/images/left.png')}/>
  54. </TouchableOpacity>
  55. <Text style={styles.ProgressText}>{this.state.currentPage + '/' + this.state.imageUrls.length}</Text>
  56. <TouchableOpacity style = {styles.SaveButton}>
  57. <Text style = {styles.SaveButtonText}>{'保存'}</Text>
  58. </TouchableOpacity>
  59. </View>
  60. )
  61. }
  62. }
  63. const styles = StyleSheet.create({
  64. View: {
  65. width: ScreenDimensions.width,
  66. height: ScreenDimensions.height,
  67. backgroundColor: '#000000',
  68. },
  69. ImageView: {
  70. marginTop: NavigationBarHeight.height,
  71. width: ScreenDimensions.width,
  72. height: ScreenDimensions.height - NavigationBarHeight.height - 50,
  73. // backgroundColor: '#000000'
  74. },
  75. BackButton: {
  76. position: 'absolute',
  77. left: 12,
  78. top: 28,
  79. width: 30,
  80. height: 30,
  81. justifyContent: 'center',
  82. alignItems: 'center',
  83. },
  84. ProgressText: {
  85. fontSize: 15,
  86. color: '#ffffff',
  87. left: 22,
  88. position: 'absolute',
  89. bottom: 44,
  90. },
  91. SaveButton: {
  92. right: 22,
  93. position: 'absolute',
  94. bottom: 44,
  95. },
  96. SaveButtonText: {
  97. fontSize: 15,
  98. color: '#ffffff'
  99. }
  100. })