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

Index.js:

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>
  )
}
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/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

徐同保

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值