如何安装tracker(封装Picker组件)
如何安装tracker(封装Picker组件)
2024-11-08 03:53:50  作者:囬忆好美  网址:https://m.xinb2b.cn/tech/bxv207939.html

import { View, Text, TouchableWithoutFeedback, TouchableOpacity, FlatList,} from 'react-native'import React,{ PureComponent, Component,} from 'react'import _ from 'lodash'import styleSheet, {getThemeColor} from '../utils/styleSheet'import {Callback} from "modern/types/lang";import Modal from './Modal'import {getScreenHeight, getScreenWidth} from "modern/consts/ui-common";const styles = styleSheet.create({ container:{ flex:1, backgroundColor: 0x00000074, alignItems: 'center', justifyContent: 'flex-end', }, contentView:{ flexDirection:'row', justifyContent: 'space-around', backgroundColor: 'white' }, stage:{ top:0, bottom:0, left:0, right:0, position:'absolute', zIndex:10, flexDirection:'row', justifyContent: 'space-around', }, maskView:{ left:0, right:0, position:'absolute', top:0, bottom:0, zIndex:0, justifyContent:'space-between' }, emptyView:{ height:50, flexDirection:'row', justifyContent:'space-between', paddingHorizontal:20, backgroundColor: 'white', }, maskStyle:{ width:'100%', // backgroundColor:'rgba(232,232,232,0.9)', borderColor:"rgba(232,232,232,0.9)", backgroundColor:'white' }, midMaskStyle:{ backgroundColor:'#f9f9f9' }, headerBtnView:{ height:50,justifyContent: 'center' }, cancelText:{ fontSize:16,color:'gray' }})function DefaultView (){ return ( <View style={{flex:1,justifyContent:'center',alignItems: 'center'}}> <Text>暂无数据</Text> </View> )}interface ISHeadProps { customHead:any, confirm:Callback, hide:Callback, headOptions:any}const Head:React.FC<ISHeadProps> = React.memo(({customHead,confirm,hide,headOptions})=>{ if(customHead && _.isFunction(customHead)){ return customHead(confirm,hide) } const { cancelTextStyle={}, cancelBtnView={}, confirmBtnView={}, confirmTextStyle={}, leftText='取消', rightText='确定', headerContainView={}, } = headOptions return <View style={[styles.emptyView,headerContainView]}> <TouchableOpacity style={[styles.headerBtnView,cancelBtnView]} onPress={hide}> <Text style={[styles.cancelText,cancelTextStyle]}>{leftText}</Text> </TouchableOpacity> <TouchableOpacity onPress={confirm} style={[styles.headerBtnView,confirmBtnView]}> <Text style={[{color:getThemeColor(),fontSize:16},confirmTextStyle]}>{rightText}</Text> </TouchableOpacity> </View>})interface ISEmpty { hide:Callback}const Empty:React.FC<ISEmpty> = React.memo(({hide})=>{ return <TouchableWithoutFeedback onPress={hide}> <View style={{flex:1,width:getScreenWidth()}} /> </TouchableWithoutFeedback>})interface ISMaskView { maxLength:number, itemHeihght:number, maskOptions:any,}const MaskView:React.FC<ISMaskView> = React.memo(({maxLength,itemHeihght,maskOptions={}})=>{ const { upMaskView, bottomMaskView, midMaskView } = maskOptions const mid = Math.floor(maxLength/2) return <View style={[styles.maskView]}> <View style={[styles.maskStyle,{height:itemHeihght*mid,borderBottomWidth:0.5,},upMaskView]}/> <View style={[styles.midMaskStyle,{height:itemHeihght},midMaskView]} /> <View style={[styles.maskStyle,{height:itemHeihght*mid,borderTopWidth:0.5,},bottomMaskView]}/> </View>})interface ISourceType { id:string, name:string, sub?:ISourceType[] [propname:string]:any,}interface ISitemOptons { itemHeihght?:number, maxLength?:5 | 7 | 9, ActiveTextStyle?:any, normalTextStyle?:any,}interface ISProps { sourceData:ISourceType[], cancel?:Callback, confirm:Callback, selectData:ISourceType[], pickerType:'scroll' | 'click' | 'all', customHead:any, headOptions:any, maskOptions:any, itemOptons:ISitemOptons, isLinkage:boolean, renderListEmptyComponent:Callback, emptyOptions:any, wrapOptions:any, EmptyView:any}interface ISState { visible:boolean, floor:number,}function WithHeadAndMethod(WrapComponent:any){ return class PickerAlertView extends PureComponent<ISProps,ISState>{ public selectedData:ISourceType[] =[] public static defaultProps = { itemOptons:{}, selectData:[], headOptions:{}, pickerType:'all', maskOptions:{}, isLinkage:false, emptyOptions:{}, wrapOptions:{ stageView:{} } } constructor(props:ISProps) { super(props); this.state = { visible:false, floor:this.getMaxFloor(), } } public getMaxFloor = ()=>{ const { sourceData,isLinkage } = this.props if(_.isEmpty(sourceData)) return 0 if(isLinkage) return sourceData.length let floor:number = 1 function treeData(arr:any){ const sub:any = arr.find((item:any)=>item?.sub?.length > 0) if(sub){ floor = floor 1 let arr2:any = [] arr.forEach((item:any)=>{ if(item?.sub?.length>0){ arr2 = arr2.concat(item.sub) } }) treeData(arr2) } } treeData(sourceData) return floor } public show = ()=>{ this.setState({visible:true}) } public confirm = ()=>{ const { confirm=_.noop } = this.props this.hide() confirm(this.selectedData) } public hide = ()=>{ const { cancel=_.noop } = this.props cancel() this.setState({visible:false}) } public getSelected = ()=>this.selectedData private setSelected = (item:ISourceType,floor:number)=>{ this.selectedData[floor] = item } public componentDidUpdate(preProps,prevState,snapshot){ if(!_.isEqual(this.props.sourceData,preProps.sourceData)){ this.setState({ floor:this.getMaxFloor() }) } } public render(){ const { visible, floor, } = this.state const { selectData, sourceData, pickerType, customHead, headOptions, maskOptions, itemOptons, isLinkage, renderListEmptyComponent, emptyOptions, wrapOptions, EmptyView = DefaultView } = this.props const { stageView } = wrapOptions if(!visible) return null const { maxLength=9, itemHeihght=50, ActiveTextStyle={}, normalTextStyle={} } = itemOptons return ( <Modal visible={visible} animationType="slide" transparent={true} > <View style={styles.container} > <Empty hide={this.hide}/> <View style={{ width:getScreenWidth()}}> <Head headOptions={headOptions} hide={this.hide} confirm={this.confirm} customHead={customHead} /> <View style={[{height:itemHeihght*maxLength},styles.contentView]}> <View style={[styles.stage,stageView]}>{ _.isEmpty(sourceData) ?<EmptyView/>: <WrapComponent sourceList={sourceData} setSelect={this.setSelected} floor={floor} currentFloor={0} maxLength={maxLength} defaultSelected = {selectData} itemHeihght={itemHeihght} ActiveTextStyle={ActiveTextStyle} normalTextStyle={normalTextStyle} pickerType={pickerType} originData={sourceData} isLinkage={isLinkage} renderListEmptyComponent={renderListEmptyComponent} emptyOptions={emptyOptions} />} </View> <MaskViewmaxLength={maxLength}itemHeihght={itemHeihght}maskOptions={maskOptions} /> </View> </View> </View> </Modal> ) } }}interface ISItemProps { sourceList:ISourceType[], setSelect:Callback, floor:number, currentFloor:number, maxLength: 5 | 7 | 9, defaultSelected:ISourceType[], itemHeihght:number, ActiveTextStyle:any, normalTextStyle:any, pickerType:string, isLinkage:boolean, originData:any, renderListEmptyComponent:Callback, emptyOptions:any}interface ISItemState { nextData:ISourceType[], currentChoose:ISourceType, initialScrollIndex:number, renderList:any[], surerefresh:any}class PickerAlertViewItem extends PureComponent<ISItemProps,ISItemState> { public scrollView:any public flatEl:any public currentItem:any public itemEL:any public config:any = { waitForInteraction: false, itemVisiblePercentThreshold:100, } public constructor(props:ISItemProps) { super(props); this.state = { nextData:this.defaultRenderList(), currentChoose:this.getDefaultChoose(), initialScrollIndex:this.getInitialScrollIndex(), renderList:this.flatListData(), surerefresh:null, } } public getInitialScrollIndex = ()=>{ const {defaultSelected,currentFloor,sourceList } = this.props if(_.isEmpty(defaultSelected)) return 0 const initIndex = sourceList.findIndex(item=>String(item.id) === String(defaultSelected[currentFloor]?.id)) return initIndex<0?0:initIndex } public defaultRenderList = ()=>{ const { currentFloor, floor, defaultSelected, sourceList,isLinkage,originData} = this.props if(isLinkage){ return originData[currentFloor 1] } const getNoFefault = ()=>this.props.sourceList?.[0]?.sub || [] const getDefaultList = ()=>{ if(currentFloor 1 === floor ) return [] return sourceList.find(value=>value.id === defaultSelected[currentFloor].id)?.sub || getNoFefault() } return _.isEmpty(defaultSelected)?getNoFefault():getDefaultList() } public getDefaultChoose = ()=>{ const { defaultSelected, currentFloor, sourceList } = this.props return _.isEmpty(defaultSelected)?sourceList?.[0]:(sourceList.find(item=>item.id === defaultSelected?.[currentFloor]?.id) || sourceList?.[0]) } public mid = ()=>{ const { maxLength } = this.props return Math.floor(maxLength/2) } public flatListData = (nextData:any[])=>{ const { sourceList,currentFloor,originData ,isLinkage} = this.props const mid = this.mid() const arr = Array(mid).fill({id:'',name:'',sub:[]}) let currentData = nextData?nextData:sourceList if(isLinkage){ currentData = originData[currentFloor] } if(currentData.length === 0 || !currentData) return [] return [...arr,...currentData,...arr] } public getItemLayout = (data:any,index:any) =>{ const { itemHeihght } = this.props return {length: itemHeihght, offset: itemHeihght * index, index} } public renderItem = ({item,index,separators}:any)=>{ const { itemHeihght ,ActiveTextStyle,normalTextStyle,pickerType} = this.props const {currentChoose} = this.state const itemPress = (pickerType === 'scroll' || item.id === currentChoose?.id)?_.noop:this.clickItem return <TouchableWithoutFeedback onPress={()=>itemPress(item,index)}> <Text numberOfLines={1} style={[ {height:itemHeihght,textAlign:'center',lineHeight:itemHeihght,opacity:0.8,paddingHorizontal: 10, }, item.id === currentChoose?.id?ActiveTextStyle:normalTextStyle ]} >{item.name}</Text> </TouchableWithoutFeedback> } public clickItem =(item:ISourceType,index:any)=>{ const mid = this.mid() if(index<mid) return if(!item) return this.scrollToIndex(index) this.chooseItem(index,item) } public scrollToIndex = (index:any)=>{ const { renderList } = this.state if(renderList.length === 0 || !renderList) return if(this.flatEl){ this.flatEl.scrollToIndex({ index, viewPosition:0.5, animated:true }) } } public chooseItem = (index:number,item:ISourceType)=>{ const { setSelect,currentFloor,isLinkage } = this.props setSelect(item,currentFloor) if(isLinkage) return this.setState({ currentChoose:item || {}, nextData:item?.sub || [] },()=>{ if(this.itemEL) this.itemEL.reduction() }) } public reduction=()=>{ const currentChoose = this.props.sourceList?.[0] || {} const nextData = currentChoose?.sub || [] const mid = this.mid() this.setState({ currentChoose, nextData, renderList:this.flatListData(), surerefresh:Date.now() Math.random(), }) } public componentDidMount(){ this.initSelected() } public componentDidUpdate(preProp:ISItemProps,preState:ISItemState){ const mid = this.mid() if(this.state.surerefresh !== preState.surerefresh){ _.delay(()=>this.clickItem(this.state.currentChoose,mid),100) } } public initSelected = ()=>{ const {setSelect,currentFloor } = this.props const { currentChoose } = this.state setSelect(currentChoose,currentFloor) if(this.flatEl) this.flatEl.recordInteraction() } public renderListEmptyComponent = (data:any)=>{ const {renderListEmptyComponent,itemHeihght,emptyOptions,maxLength} = this.props if(renderListEmptyComponent) return renderListEmptyComponent() return <View style={{height:itemHeihght*maxLength,justifyContent:'center',alignItems: 'center'}}> <Text numberOfLines={1} style={[ { height:itemHeihght, textAlign:'center', lineHeight:itemHeihght, opacity:0.8, paddingHorizontal: 10, } ]} >{emptyOptions.descText || '暂无数据'}</Text> </View> } public render(){ const { floor, currentFloor, setSelect, defaultSelected, maxLength, itemHeihght=50, ActiveTextStyle, normalTextStyle, pickerType, isLinkage, originData, emptyOptions, } = this.props const { nextData, initialScrollIndex, renderList, } = this.state const nextFloor = currentFloor 1 return ( <> <FlatList style={{flex:1}} ref={ref=>this.flatEl = ref} showsHorizontalScrollIndicator={false} showsVerticalScrollIndicator={false} keyExtractor={(item: object, index: number) => String(index)} renderItem={this.renderItem} viewabilityConfig={this.config} data={renderList} getItemLayout={this.getItemLayout} initialScrollIndex={initialScrollIndex} onMomentumScrollEnd={this._moveEnd} scrollEnabled={pickerType === 'click'?false:true} ListEmptyComponent={this.renderListEmptyComponent} /> { floor > nextFloor ? <PickerAlertViewItem ref={ref=>this.itemEL = ref} sourceList={nextData} floor={floor} setSelect={setSelect} currentFloor={nextFloor} defaultSelected={defaultSelected} maxLength={maxLength} itemHeihght={itemHeihght} ActiveTextStyle={ActiveTextStyle} normalTextStyle={normalTextStyle} pickerType={pickerType} isLinkage={isLinkage} originData={originData} emptyOptions={emptyOptions} />: null } </> ) } private _moveEnd=(e)=>{ const {itemHeihght} = this.props const { renderList } = this.state const contentOffset = e.nativeEvent.contentOffset.y; const mid = this.mid() const index = Math.round(contentOffset/itemHeihght) mid this.clickItem(renderList[index],index) }}export default WithHeadAndMethod(PickerAlertViewItem),今天小编就来说说关于如何安装tracker?下面更多详细答案一起来看看吧!


如何安装tracker

import { View, Text, TouchableWithoutFeedback, TouchableOpacity, FlatList,} from 'react-native'import React,{ PureComponent, Component,} from 'react'import _ from 'lodash'import styleSheet, {getThemeColor} from '../utils/styleSheet'import {Callback} from "modern/types/lang";import Modal from './Modal'import {getScreenHeight, getScreenWidth} from "modern/consts/ui-common";const styles = styleSheet.create({ container:{ flex:1, backgroundColor: 0x00000074, alignItems: 'center', justifyContent: 'flex-end', }, contentView:{ flexDirection:'row', justifyContent: 'space-around', backgroundColor: 'white' }, stage:{ top:0, bottom:0, left:0, right:0, position:'absolute', zIndex:10, flexDirection:'row', justifyContent: 'space-around', }, maskView:{ left:0, right:0, position:'absolute', top:0, bottom:0, zIndex:0, justifyContent:'space-between' }, emptyView:{ height:50, flexDirection:'row', justifyContent:'space-between', paddingHorizontal:20, backgroundColor: 'white', }, maskStyle:{ width:'100%', // backgroundColor:'rgba(232,232,232,0.9)', borderColor:"rgba(232,232,232,0.9)", backgroundColor:'white' }, midMaskStyle:{ backgroundColor:'#f9f9f9' }, headerBtnView:{ height:50,justifyContent: 'center' }, cancelText:{ fontSize:16,color:'gray' }})function DefaultView (){ return ( <View style={{flex:1,justifyContent:'center',alignItems: 'center'}}> <Text>暂无数据</Text> </View> )}interface ISHeadProps { customHead:any, confirm:Callback, hide:Callback, headOptions:any}const Head:React.FC<ISHeadProps> = React.memo(({customHead,confirm,hide,headOptions})=>{ if(customHead && _.isFunction(customHead)){ return customHead(confirm,hide) } const { cancelTextStyle={}, cancelBtnView={}, confirmBtnView={}, confirmTextStyle={}, leftText='取消', rightText='确定', headerContainView={}, } = headOptions return <View style={[styles.emptyView,headerContainView]}> <TouchableOpacity style={[styles.headerBtnView,cancelBtnView]} onPress={hide}> <Text style={[styles.cancelText,cancelTextStyle]}>{leftText}</Text> </TouchableOpacity> <TouchableOpacity onPress={confirm} style={[styles.headerBtnView,confirmBtnView]}> <Text style={[{color:getThemeColor(),fontSize:16},confirmTextStyle]}>{rightText}</Text> </TouchableOpacity> </View>})interface ISEmpty { hide:Callback}const Empty:React.FC<ISEmpty> = React.memo(({hide})=>{ return <TouchableWithoutFeedback onPress={hide}> <View style={{flex:1,width:getScreenWidth()}} /> </TouchableWithoutFeedback>})interface ISMaskView { maxLength:number, itemHeihght:number, maskOptions:any,}const MaskView:React.FC<ISMaskView> = React.memo(({maxLength,itemHeihght,maskOptions={}})=>{ const { upMaskView, bottomMaskView, midMaskView } = maskOptions const mid = Math.floor(maxLength/2) return <View style={[styles.maskView]}> <View style={[styles.maskStyle,{height:itemHeihght*mid,borderBottomWidth:0.5,},upMaskView]}/> <View style={[styles.midMaskStyle,{height:itemHeihght},midMaskView]} /> <View style={[styles.maskStyle,{height:itemHeihght*mid,borderTopWidth:0.5,},bottomMaskView]}/> </View>})interface ISourceType { id:string, name:string, sub?:ISourceType[] [propname:string]:any,}interface ISitemOptons { itemHeihght?:number, maxLength?:5 | 7 | 9, ActiveTextStyle?:any, normalTextStyle?:any,}interface ISProps { sourceData:ISourceType[], cancel?:Callback, confirm:Callback, selectData:ISourceType[], pickerType:'scroll' | 'click' | 'all', customHead:any, headOptions:any, maskOptions:any, itemOptons:ISitemOptons, isLinkage:boolean, renderListEmptyComponent:Callback, emptyOptions:any, wrapOptions:any, EmptyView:any}interface ISState { visible:boolean, floor:number,}function WithHeadAndMethod(WrapComponent:any){ return class PickerAlertView extends PureComponent<ISProps,ISState>{ public selectedData:ISourceType[] =[] public static defaultProps = { itemOptons:{}, selectData:[], headOptions:{}, pickerType:'all', maskOptions:{}, isLinkage:false, emptyOptions:{}, wrapOptions:{ stageView:{} } } constructor(props:ISProps) { super(props); this.state = { visible:false, floor:this.getMaxFloor(), } } public getMaxFloor = ()=>{ const { sourceData,isLinkage } = this.props if(_.isEmpty(sourceData)) return 0 if(isLinkage) return sourceData.length let floor:number = 1 function treeData(arr:any){ const sub:any = arr.find((item:any)=>item?.sub?.length > 0) if(sub){ floor = floor 1 let arr2:any = [] arr.forEach((item:any)=>{ if(item?.sub?.length>0){ arr2 = arr2.concat(item.sub) } }) treeData(arr2) } } treeData(sourceData) return floor } public show = ()=>{ this.setState({visible:true}) } public confirm = ()=>{ const { confirm=_.noop } = this.props this.hide() confirm(this.selectedData) } public hide = ()=>{ const { cancel=_.noop } = this.props cancel() this.setState({visible:false}) } public getSelected = ()=>this.selectedData private setSelected = (item:ISourceType,floor:number)=>{ this.selectedData[floor] = item } public componentDidUpdate(preProps,prevState,snapshot){ if(!_.isEqual(this.props.sourceData,preProps.sourceData)){ this.setState({ floor:this.getMaxFloor() }) } } public render(){ const { visible, floor, } = this.state const { selectData, sourceData, pickerType, customHead, headOptions, maskOptions, itemOptons, isLinkage, renderListEmptyComponent, emptyOptions, wrapOptions, EmptyView = DefaultView } = this.props const { stageView } = wrapOptions if(!visible) return null const { maxLength=9, itemHeihght=50, ActiveTextStyle={}, normalTextStyle={} } = itemOptons return ( <Modal visible={visible} animationType="slide" transparent={true} > <View style={styles.container} > <Empty hide={this.hide}/> <View style={{ width:getScreenWidth()}}> <Head headOptions={headOptions} hide={this.hide} confirm={this.confirm} customHead={customHead} /> <View style={[{height:itemHeihght*maxLength},styles.contentView]}> <View style={[styles.stage,stageView]}>{ _.isEmpty(sourceData) ?<EmptyView/>: <WrapComponent sourceList={sourceData} setSelect={this.setSelected} floor={floor} currentFloor={0} maxLength={maxLength} defaultSelected = {selectData} itemHeihght={itemHeihght} ActiveTextStyle={ActiveTextStyle} normalTextStyle={normalTextStyle} pickerType={pickerType} originData={sourceData} isLinkage={isLinkage} renderListEmptyComponent={renderListEmptyComponent} emptyOptions={emptyOptions} />} </View> <MaskViewmaxLength={maxLength}itemHeihght={itemHeihght}maskOptions={maskOptions} /> </View> </View> </View> </Modal> ) } }}interface ISItemProps { sourceList:ISourceType[], setSelect:Callback, floor:number, currentFloor:number, maxLength: 5 | 7 | 9, defaultSelected:ISourceType[], itemHeihght:number, ActiveTextStyle:any, normalTextStyle:any, pickerType:string, isLinkage:boolean, originData:any, renderListEmptyComponent:Callback, emptyOptions:any}interface ISItemState { nextData:ISourceType[], currentChoose:ISourceType, initialScrollIndex:number, renderList:any[], surerefresh:any}class PickerAlertViewItem extends PureComponent<ISItemProps,ISItemState> { public scrollView:any public flatEl:any public currentItem:any public itemEL:any public config:any = { waitForInteraction: false, itemVisiblePercentThreshold:100, } public constructor(props:ISItemProps) { super(props); this.state = { nextData:this.defaultRenderList(), currentChoose:this.getDefaultChoose(), initialScrollIndex:this.getInitialScrollIndex(), renderList:this.flatListData(), surerefresh:null, } } public getInitialScrollIndex = ()=>{ const {defaultSelected,currentFloor,sourceList } = this.props if(_.isEmpty(defaultSelected)) return 0 const initIndex = sourceList.findIndex(item=>String(item.id) === String(defaultSelected[currentFloor]?.id)) return initIndex<0?0:initIndex } public defaultRenderList = ()=>{ const { currentFloor, floor, defaultSelected, sourceList,isLinkage,originData} = this.props if(isLinkage){ return originData[currentFloor 1] } const getNoFefault = ()=>this.props.sourceList?.[0]?.sub || [] const getDefaultList = ()=>{ if(currentFloor 1 === floor ) return [] return sourceList.find(value=>value.id === defaultSelected[currentFloor].id)?.sub || getNoFefault() } return _.isEmpty(defaultSelected)?getNoFefault():getDefaultList() } public getDefaultChoose = ()=>{ const { defaultSelected, currentFloor, sourceList } = this.props return _.isEmpty(defaultSelected)?sourceList?.[0]:(sourceList.find(item=>item.id === defaultSelected?.[currentFloor]?.id) || sourceList?.[0]) } public mid = ()=>{ const { maxLength } = this.props return Math.floor(maxLength/2) } public flatListData = (nextData:any[])=>{ const { sourceList,currentFloor,originData ,isLinkage} = this.props const mid = this.mid() const arr = Array(mid).fill({id:'',name:'',sub:[]}) let currentData = nextData?nextData:sourceList if(isLinkage){ currentData = originData[currentFloor] } if(currentData.length === 0 || !currentData) return [] return [...arr,...currentData,...arr] } public getItemLayout = (data:any,index:any) =>{ const { itemHeihght } = this.props return {length: itemHeihght, offset: itemHeihght * index, index} } public renderItem = ({item,index,separators}:any)=>{ const { itemHeihght ,ActiveTextStyle,normalTextStyle,pickerType} = this.props const {currentChoose} = this.state const itemPress = (pickerType === 'scroll' || item.id === currentChoose?.id)?_.noop:this.clickItem return <TouchableWithoutFeedback onPress={()=>itemPress(item,index)}> <Text numberOfLines={1} style={[ {height:itemHeihght,textAlign:'center',lineHeight:itemHeihght,opacity:0.8,paddingHorizontal: 10, }, item.id === currentChoose?.id?ActiveTextStyle:normalTextStyle ]} >{item.name}</Text> </TouchableWithoutFeedback> } public clickItem =(item:ISourceType,index:any)=>{ const mid = this.mid() if(index<mid) return if(!item) return this.scrollToIndex(index) this.chooseItem(index,item) } public scrollToIndex = (index:any)=>{ const { renderList } = this.state if(renderList.length === 0 || !renderList) return if(this.flatEl){ this.flatEl.scrollToIndex({ index, viewPosition:0.5, animated:true }) } } public chooseItem = (index:number,item:ISourceType)=>{ const { setSelect,currentFloor,isLinkage } = this.props setSelect(item,currentFloor) if(isLinkage) return this.setState({ currentChoose:item || {}, nextData:item?.sub || [] },()=>{ if(this.itemEL) this.itemEL.reduction() }) } public reduction=()=>{ const currentChoose = this.props.sourceList?.[0] || {} const nextData = currentChoose?.sub || [] const mid = this.mid() this.setState({ currentChoose, nextData, renderList:this.flatListData(), surerefresh:Date.now() Math.random(), }) } public componentDidMount(){ this.initSelected() } public componentDidUpdate(preProp:ISItemProps,preState:ISItemState){ const mid = this.mid() if(this.state.surerefresh !== preState.surerefresh){ _.delay(()=>this.clickItem(this.state.currentChoose,mid),100) } } public initSelected = ()=>{ const {setSelect,currentFloor } = this.props const { currentChoose } = this.state setSelect(currentChoose,currentFloor) if(this.flatEl) this.flatEl.recordInteraction() } public renderListEmptyComponent = (data:any)=>{ const {renderListEmptyComponent,itemHeihght,emptyOptions,maxLength} = this.props if(renderListEmptyComponent) return renderListEmptyComponent() return <View style={{height:itemHeihght*maxLength,justifyContent:'center',alignItems: 'center'}}> <Text numberOfLines={1} style={[ { height:itemHeihght, textAlign:'center', lineHeight:itemHeihght, opacity:0.8, paddingHorizontal: 10, } ]} >{emptyOptions.descText || '暂无数据'}</Text> </View> } public render(){ const { floor, currentFloor, setSelect, defaultSelected, maxLength, itemHeihght=50, ActiveTextStyle, normalTextStyle, pickerType, isLinkage, originData, emptyOptions, } = this.props const { nextData, initialScrollIndex, renderList, } = this.state const nextFloor = currentFloor 1 return ( <> <FlatList style={{flex:1}} ref={ref=>this.flatEl = ref} showsHorizontalScrollIndicator={false} showsVerticalScrollIndicator={false} keyExtractor={(item: object, index: number) => String(index)} renderItem={this.renderItem} viewabilityConfig={this.config} data={renderList} getItemLayout={this.getItemLayout} initialScrollIndex={initialScrollIndex} onMomentumScrollEnd={this._moveEnd} scrollEnabled={pickerType === 'click'?false:true} ListEmptyComponent={this.renderListEmptyComponent} /> { floor > nextFloor ? <PickerAlertViewItem ref={ref=>this.itemEL = ref} sourceList={nextData} floor={floor} setSelect={setSelect} currentFloor={nextFloor} defaultSelected={defaultSelected} maxLength={maxLength} itemHeihght={itemHeihght} ActiveTextStyle={ActiveTextStyle} normalTextStyle={normalTextStyle} pickerType={pickerType} isLinkage={isLinkage} originData={originData} emptyOptions={emptyOptions} />: null } </> ) } private _moveEnd=(e)=>{ const {itemHeihght} = this.props const { renderList } = this.state const contentOffset = e.nativeEvent.contentOffset.y; const mid = this.mid() const index = Math.round(contentOffset/itemHeihght) mid this.clickItem(renderList[index],index) }}export default WithHeadAndMethod(PickerAlertViewItem)

接上一版 多级联动组件;增加了非联动组件;完善了配置;优化了使用过程中的小问题;

  • 如果女孩对你有好感(哪些位置是女生的敏感带)
  • 2024-11-08哪些位置是女生的敏感带每个人的敏感带都不同,真的不是只有那几个地方是性感带,每次都期待男友碰的地方他都偏偏忽略了,真的好想直接跟他说你的性感带在哪里的人赶快把文章发给你的男友看吧1.臀部下缘很多男生喜欢女生的臀部线条,臀部。
  • 学校开放日对学校的意见和建议(专家提供报考咨询)
  • 2024-11-08专家提供报考咨询2015年高考填报志愿即将开始,内蒙古大学为方便考生和家长更好了解招生政策、专业设置、就业前景等问题,连续第十二年举办“校园开放日”活动6月14日上午7:30,内蒙古大学第十二届“校园开放日”于内蒙古。
  • 提升气质的100个方法 提升自己气质的10个方法
  • 2024-11-08提升气质的100个方法 提升自己气质的10个方法好的习惯造就好的生活,好的习惯造就好的气质气质需要经年修炼才能显现,从小细节里慢慢养成气质,小积累给自己带来大不同1、运动这是一个非常明显能够提升气质的方法,找到自己喜欢的运动方式,并且把它当成自己的。
  • 祖玛变小怎么办(老奶奶千万别再叫)
  • 2024-11-08老奶奶千万别再叫在国内叫年纪大的奶奶一声:老奶奶很是尊重和亲切但在国外就算老奶奶已经白发满头也不能叫grandma这是很没礼貌的叫法!不同的文化,对人的称呼会有所不同!和小酱一起来学习吧老"奶奶"要如。
  • 孙子兵法第一计是什么(孙子兵法第一计资料)
  • 2024-11-08孙子兵法第一计资料孙子兵法第一计是“瞒天过海”,意思是“瞒住上天,偷渡大海”,比喻用谎言和伪装向别人隐瞒自己的真实意图,在背地里偷偷地行动,《孙子兵法》是中华民族悠久文化遗产之一《瞒天过海》选自《三十六计》,是指中国古。
  • 高自由度模拟人生的手游(养成类模拟人生手游推荐)
  • 2024-11-08养成类模拟人生手游推荐TechWeb原创文:潘达春节假期转瞬即逝,大家在这几天的假期中感受到了亲朋好友的问候以及家的温暖,但是我们即将回到各自的学校与工作岗位上接受社会的洗礼在社会上生活十分不易,而家是我们心中最安全的港湾。
  • 精灵宝可梦letsgo收服小火龙(精灵宝可梦Let39)
  • 2024-11-08精灵宝可梦Let39任天堂新作《精灵宝可梦Let'sGo!皮卡丘/伊布》今天公布了全新的预告片,本次视频给我们展示的是袋兽和暴鲤龙在进化之后的超级形态一起来了解一下吧!预告中除了为我们展示了袋兽和暴鲤龙进化前后的不同形态。
  • 薛洋的故事概括(薛洋的故事概括有哪些)
  • 2024-11-08薛洋的故事概括有哪些不喜欢被叫薛成美,成美是金光瑶为薛洋起的字,表示成人之美而薛洋似乎很讨厌薛成美这个名字,听到这个称呼都眉头一皱,不开心说到做到说要报断指之仇,然后栎阳常氏就被灭门说要挖宋岚的双眼,结果真的这么做了嘴里。
  • 圣斗士星矢2022豆瓣评分(影评下午茶之美人鱼)
  • 2024-11-08影评下午茶之美人鱼#影评下午茶#之《#美人鱼#》感觉周星驰已经陷入回忆的漩涡中爬不出来了电影的概念其实很虚,故事情节比较老套,美人计救族人,结果自己差点挂了1神吐槽感觉周星驰已经陷入年轻时回忆的漩涡中,爬不出来了电影的。
  • 相宜本草牡丹精华怎么样(平价又好用的5款)
  • 2024-11-08平价又好用的5款这几年国货的护肤品也越做越好,价格实惠而且效果也很不错想找到一款平价的国货精华,不是什么难题挑选的时候,可以重点关注一下口碑比较好的国产品牌,好的品牌所用的成分也不会差,有质量保证;其次可以看一下它的。
  • 高中各科学习方法技巧(高中各科应该怎样学习)
  • 2024-11-08高中各科应该怎样学习我用了不到100天时间,高考前从班级中游水平冲进年级前30!如果你还在疯狂刷题,成绩却不见什么起色不妨听听学长我作为过来人高考前的学习技巧和经验,吐血整理100%纯干货!建议点赞收藏!!!先说下我的情。