/** * 官方的列表是采用全列表渲染的 * 如果数据量较多,很影响渲染 * 现在改为VirtualList实现,性能极大优化 */ import React, {PureComponent, useEffect} from 'react'; import { Text, View } from '@tarojs/components' import { CommonEvent } from '@tarojs/components/types/common' import {AtRadioProps, RadioOption} from "taro-ui/types/radio"; import VirtualList from '@tarojs/components/virtual-list'; import './index.scss'; interface IProps extends AtRadioProps{ customStyle?: string; className?: string; /** * 列表的高度,单位为px,需要自己转换 * 默认为330px */ height?: number; } export default class Index extends PureComponent { public static defaultProps: AtRadioProps public static propTypes: any handleClick = (option: RadioOption, event: CommonEvent) => { if (option.disabled) return; this.props.onClick&&this.props.onClick(option.value, event); } public render(): JSX.Element { const { customStyle, className, options, value, height } = this.props; return ( { React.memo(({index, style, data}: {index: number; style: any; data: Array;})=>{ const option = data[index]; return ( ); }) } ) } } function RadioItem({disabled, label, value, desc, checked, style, handleClick}) { return ( handleClick({ disabled, label, desc, value } as RadioOption, e)} style={style} className="yz-radio__option" > {label} ); } Index.defaultProps = { customStyle: '', className: '', value: '', options: [], onClick: () => {} }