如何安装tracker(封装Picker组件)
如何安装tracker(封装Picker组件)
2024-11-05 06:25:59  作者:囬忆好美  网址:https://m.xinb2b.cn/life/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-06江浙沪贴秋膘宁波进入十月中旬,随着多地大范围降温,“包邮区”已集体入秋菊黄蟹肥,烟云高起,江浙沪的秋季汇集了美食和美景,爆膏流金的阳澄湖大闸蟹、馥郁绵软的南京桂花糖芋艿、肉质鲜美的宁波梭子蟹、上海街边随处可见的桂花糖。
  • 黄旭华造核潜艇花几年时间(原创话剧深海北京上演)
  • 2024-11-06原创话剧深海北京上演11月20日至21日,以“中国核潜艇之父”黄旭华为故事原型的大型话剧《深海》在北京上演该剧以核潜艇深潜为叙事主轴,不仅展现了步步惊心的下潜情景,更以黄旭华内心世界为聚焦点,回溯了这位中国核潜艇的开创者。
  • 兰花的花芽分化期是几月几日(兰花为什么不开花)
  • 2024-11-06兰花为什么不开花对大多数国兰而言,冬天都是孕育花苞的好时间,只有经历了“苦寒”才能迎来“幽香”所以很多花友的兰花这个时候都已经有了花苞,只待寒冬过去,兰花就能吐香但也有花友的兰花迟迟不见花芽,多少让人有些失望想让兰花。
  • 唐朝国都为什么迁往洛阳(细说国都六陷天子九迁)
  • 2024-11-06细说国都六陷天子九迁#我的宝藏作者#唐朝虽然是我国历史上最为强盛的朝代之一,但从李隆基天宝年间开始,由于内乱频发和藩镇割据,唐王朝的统治已经是摇摇欲坠,不仅都城长安先后六次被攻陷,皇帝更是先后九次弃城而逃,这便是所谓的“。
  • 港汇恒隆广场入驻了哪些奢侈品店(上海恒隆广场复业)
  • 2024-11-06上海恒隆广场复业记者|楼婍沁黄姗编辑|许悦5月29日,奢侈品购物中心上海恒隆广场恢复线下营业界面时尚从上海恒隆广场方面了解到,当天该商场主要定向邀请了部分商场会员及已开店品牌VIP客人到店购物依据计划,5月30日,上。
  • 学习强国四人赛解析之151(学习强国四人赛解析之151)
  • 2024-11-06学习强国四人赛解析之151本期专题解析新更的“应急管理”等24道题目新题会陆续解析,一道题都不会少放松心态,快乐学习21.地方党政主要负责人是本地区安全生产第一责任人____A.正确B.错误正确答案:正确解析:《地方党政领导干。
  • 中植系万亿(逾1亿货款遭中植系)
  • 2024-11-06逾1亿货款遭中植系(图片来源:全景图片)经济观察网见习记者张斌因拖欠逾1亿元货款,“中植系“旗下公司早先被吉利集团控股的钱江摩托(000913.SZ)告上法庭然而,时隔4个月之后,事件现却发生反转,钱江摩托反被诉钱江摩。
  • 从哪个故事可以看出袭人尽忠职守(深受曹公偏爱的花袭人)
  • 2024-11-06深受曹公偏爱的花袭人在太虚幻境的薄命册里,花袭人位居又副册的第二位,无疑是个薄命人但是,在第六十三回的“占花名”里,花袭人占到的却是代表“武陵别景”的桃花,而且还有一句热闹且吉祥的谶语:“桃红又是一年春”这都表明,花袭人。
  • 南怀瑾 修行六个阶段(修道先要了解的事和基础知识)
  • 2024-11-06修道先要了解的事和基础知识我说参同契上1许冬婷1第二讲想成仙的大人物们刚才讲到王阳明这个理学家,他也学过佛,学过道,打坐功夫很好学佛走的是天台宗止观这个路线,修道家走的是哪一派的丹法没有资料可查有一点在他的传记里记载,当时有一。