React Native 点击图片变大,查看图片

Index.js:

javascript 复制代码
import React from 'react'
import {
  View,
  Text,
  ScrollView,
  Image,
  Modal,
  TouchableWithoutFeedback,
} from 'react-native'
import useList from './useList'
import moment from 'moment'
import { Icon } from '../../../../component/light'
import ImageViewer from 'react-native-image-zoom-viewer'
import styles from './styles'

export default function Home(props) {
  const {
    userInfo,
    isModelVisible,
    handleShowModel,
    handleHideModel,
    handleJumpPage,
    handleQuit,
  } = useList(props)
  return (
    <ScrollView style={styles.mMeScrollView}>
      <View style={styles.mMeWrap}>
        <TouchableWithoutFeedback onPress={() => handleJumpPage('1')}>
          <View style={styles.mMeUserInfoWrap}>
            <View style={styles.mMeUserInfoMain}>
              <TouchableWithoutFeedback onPress={() => handleShowModel()}>
                <Image
                  source={{ uri: userInfo.avatarCdn }}
                  style={styles.mMeAvatar}
                  resizeMode="stretch"
                ></Image>
              </TouchableWithoutFeedback>
              <View style={styles.mMeUserInfoMainInfo}>
                <View style={styles.mMeNicknameWrap}>
                  <Text
                    style={styles.mMeNickname}
                    ellipsizeMode="tail"
                    numberOfLines={1}
                  >
                    {userInfo.nickname}
                  </Text>
                  {userInfo.isVipStatus ? (
                    <Icon name="vip" style={styles.mMeVipIcon}></Icon>
                  ) : null}
                </View>
                <View style={styles.mMeUsernameWrap}>
                  <Text
                    style={styles.mMeUsername}
                    ellipsizeMode="tail"
                    numberOfLines={1}
                  >
                    账号:{userInfo.username}
                  </Text>
                </View>
              </View>
              <View style={styles.mMeArrowIconWrap}>
                <Icon name="arrow" style={styles.mMeArrowIcon}></Icon>
              </View>
            </View>
            <View style={styles.mMeDueDateWrap}>
              {userInfo.isVipStatus === true ? (
                <Text style={styles.mMeDueDate}>
                  有效期至{moment(userInfo.dueDate - 0).format('YYYY-MM-DD')}
                </Text>
              ) : userInfo.isVipStatus === false ? (
                <Text style={styles.mMeDueDate}>VIP已经过期</Text>
              ) : null}
            </View>
          </View>
        </TouchableWithoutFeedback>
        <TouchableWithoutFeedback onPress={handleQuit}>
          <View style={styles.mMeQuitWrap}>
            <Text style={styles.mMeQuitText}>退出登录</Text>
          </View>
        </TouchableWithoutFeedback>
      </View>
      <Modal visible={isModelVisible} transparent={true}>
        <ImageViewer
          imageUrls={[
            {
              url: userInfo.avatarCdn,
            },
          ]}
          onClick={() => handleHideModel()}
        />
      </Modal>
    </ScrollView>
  )
}
javascript 复制代码
import { useState, useEffect } from 'react'
import { useNavigation } from '@react-navigation/native'
import Api from '../../../../api'

export default function useList() {
  const navigation = useNavigation()
  const [userInfo, setUserInfo] = useState({})
  const [isModelVisible, setIsModelVisible] = useState(false)

  const handleGetUserInfo = () => {
    Api.h5.userGetInfo({ isLoading: false }).then((res) => {
      if (res.code === 200) {
        let userInfo = res.data
        setUserInfo(userInfo)
        console.log(userInfo)
      }
    })
  }

  const handleShowModel = () => {
    setIsModelVisible(true)
  }
  const handleHideModel = () => {
    setIsModelVisible(false)
  }

  //跳转
  const handleJumpPage = (path) => {
    console.log(path)
  }

  const handleQuit = () => {
    navigation.navigate('Login')
  }

  useEffect(() => {
    handleGetUserInfo()
    // eslint-disable-next-line
  }, [])

  return {
    userInfo,
    isModelVisible,
    handleShowModel,
    handleHideModel,
    handleJumpPage,
    handleQuit,
  }
}

参考链接:

https://www.npmjs.com/package/react-native-image-zoom-viewer

https://chat.xutongbao.top/

相关推荐
2301_82104652几秒前
Python的深度学习
开发语言·javascript·ecmascript
小高00710 分钟前
🤔函数柯里化:化繁为简的艺术与实践
前端·javascript·面试
却尘13 分钟前
React useMemo 依赖陷阱:组件重挂载,状态无限复原
前端·javascript·react.js
Asort17 分钟前
JavaScript 从零开始(三):浏览器控制台与VS Code协同工作环境搭建详解
前端·javascript
葡萄城技术团队38 分钟前
浏览器为啥要对 JavaScript 定时器“踩刹车”?
javascript
m0_616188491 小时前
el-table的隔行变色不影响row-class-name的背景色
前端·javascript·vue.js
zheshiyangyang1 小时前
Vue3组件数据双向绑定
前端·javascript·vue.js
大翻哥哥2 小时前
Python上下文管理器进阶指南:不仅仅是with语句
前端·javascript·python
诚实可靠王大锤2 小时前
react-native项目通过华为OBS预签名url实现前端直传
前端·react native·华为
Monly212 小时前
Vue:下拉框多选影响行高
前端·javascript·vue.js