11import React , {
2- createContext ,
32 FunctionComponent ,
43 useEffect ,
54 useRef ,
65 useState ,
6+ createContext ,
7+ useMemo ,
78} from 'react'
8- import Taro , { createSelectorQuery , nextTick } from '@tarojs/taro'
9-
10- import { ScrollView , View } from '@tarojs/components'
9+ import Taro , { nextTick , createSelectorQuery } from '@tarojs/taro'
10+ import { ScrollView , View , Text } from '@tarojs/components'
1111import classNames from 'classnames'
1212import { BasicComponent , ComponentDefaults } from '@/utils/typings'
13+ import { harmony } from '@/utils/platform-taro'
1314import useUuid from '@/utils/use-uuid'
1415
1516export const elevatorContext = createContext ( { } as ElevatorData )
@@ -148,8 +149,7 @@ export const Elevator: FunctionComponent<
148149 touchState . current . y2 = firstTouch . pageY
149150 const delta =
150151 ( touchState . current . y2 - touchState . current . y1 ) / spaceHeight || 0
151- const cacheIndex = state . current . anchorIndex + Math . floor ( delta )
152-
152+ const cacheIndex = state . current . anchorIndex + Math . round ( delta )
153153 setCodeIndex ( cacheIndex )
154154 scrollTo ( cacheIndex )
155155 }
@@ -213,6 +213,12 @@ export const Elevator: FunctionComponent<
213213 }
214214 }
215215
216+ const getWrapStyle = useMemo ( ( ) => {
217+ const calcHeight = Number . isNaN ( + height ) ? height : `${ height } px`
218+
219+ return { height : harmony ( ) ? Number ( height ) : calcHeight }
220+ } , [ height ] )
221+
216222 useEffect ( ( ) => {
217223 if ( listview . current ) {
218224 nextTick ( ( ) => {
@@ -227,10 +233,7 @@ export const Elevator: FunctionComponent<
227233 style = { style }
228234 { ...rest }
229235 >
230- < View
231- className = { `${ classPrefix } -list` }
232- style = { { height : Number . isNaN ( + height ) ? height : `${ height } px` } }
233- >
236+ < View className = { `${ classPrefix } -list` } style = { getWrapStyle } >
234237 < ScrollView
235238 scrollTop = { scrollTop }
236239 scrollY
@@ -297,13 +300,7 @@ export const Elevator: FunctionComponent<
297300 </ View >
298301 ) : null }
299302 < View className = { `${ classPrefix } -bars` } >
300- < View
301- className = { `${ classPrefix } -bars-inner` }
302- onTouchStart = { ( event ) => touchStart ( event as any ) }
303- onTouchMove = { ( event ) => touchMove ( event as any ) }
304- onTouchEnd = { touchEnd }
305- style = { { touchAction : 'pan-y' } }
306- >
303+ < View className = { `${ classPrefix } -bars-inner` } >
307304 { list . map ( ( item : any , index : number ) => {
308305 return (
309306 < View
@@ -315,6 +312,10 @@ export const Elevator: FunctionComponent<
315312 data-index = { index }
316313 key = { index }
317314 onClick = { ( ) => handleClickIndex ( item [ floorKey ] ) }
315+ onTouchStart = { ( event ) => touchStart ( event as any ) }
316+ onTouchMove = { ( event ) => touchMove ( event as any ) }
317+ onTouchEnd = { touchEnd }
318+ style = { { touchAction : 'pan-y' } }
318319 >
319320 { item [ floorKey ] }
320321 </ View >
@@ -326,9 +327,9 @@ export const Elevator: FunctionComponent<
326327 ) : null }
327328 { sticky && scrollY > 0 ? (
328329 < View className = { `${ classPrefix } -list-fixed` } >
329- < span className = { `${ classPrefix } -list-fixed-title` } >
330+ < Text className = { `${ classPrefix } -list-fixed-title` } >
330331 { list [ codeIndex ] [ floorKey ] }
331- </ span >
332+ </ Text >
332333 </ View >
333334 ) : null }
334335 </ div >
0 commit comments