/* eslint-disable react/no-access-state-in-setstate */ import React, { Component } from 'react' import { View, Modal } from 'react-native' import ImageCropPicker from 'react-native-image-crop-picker' import ImageViewer from 'react-native-image-zoom-viewer' import { ImagePicker, WingBlank, WhiteSpace } from '@sishuguojixuefu/antd-mobile-rn' import ErrorTip from './helper/ErrorTip' import getFieldDecorator from '../utils/getFieldDecorator' import Label from './helper/Label' import { ImagePickerProps } from '../utils/PropTypes' export class SsImagePickerView extends Component { constructor(props) { super(props) this.state = { value: [], modalVisible: false, } } componentDidMount() { this.setState({ value: this.props.initialValue.map(item => { return { url: item, } }), }) } setModalVisible = (visible: boolean) => { this.setState({ modalVisible: visible }) } private _onChange = value => { const { onChange } = this.props this.setState({ value }) onChange(value) } private _clickImgItem = (index?: number) => { this.setState({ curIndex: index }) this.setModalVisible(true) } private _onAddImageClick = async () => { const { value } = this.state const { onChange } = this.props try { const images = await ImageCropPicker.openPicker({ multiple: true, waitAnimationEnd: false, includeExif: true, forceJpg: true, maxFiles: 9 - value.length, compressImageQuality: 0.5, }) let files: any = [] if (Array.isArray(images)) { files = images.map((item, index) => ({ url: item.path, id: index, meta: { ...item }, })) } else { files = [ { url: images.path, id: 1, meta: { ...images }, }, ] } this.setState({ value: this.state.value.concat(files) }) onChange(this.state.value) } catch (error) { console.log(error) } } render() { const { value, curIndex } = this.state const { label, required } = this.props return ( ) } } export default class SsImagePicker extends Component { private fieldDecorator: any componentWillMount() { const { form, id, initialValue, rules } = this.props this.fieldDecorator = getFieldDecorator(form, id, initialValue, rules) } render() { const { label, required, form, id, onChange, initialValue } = this.props return ( {this.fieldDecorator( )} ) } }