Skip to content

Commit 2463d53

Browse files
committed
chore(Picker): Update Readme 优化onLayout 事件
1 parent b6602cd commit 2463d53

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

packages/core/src/Picker/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Picker 选择器
33

44
解决 ios 与 android 和用户交互方式不同问题.
55

6-
> 避免出现样式错乱问题, 请尽量使用统一数字高度
6+
> 避免出现样式错乱问题, 请尽量使用统一整数数字高度
77
> 激活状态尽量不要改变高度, 只是修改颜色作为标记。
88
<!--rehype:style=border-left: 8px solid #ffe564;background-color: #ffe56440;padding: 12px 16px;-->
99

packages/core/src/Picker/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ const Picker = (props: PickerProps) => {
9292
containerHeight,
9393
};
9494
}, [containerStyle, textStyle]);
95-
const getItemHeight = (event: LayoutChangeEvent) => {
95+
const getItemHeight = (event: LayoutChangeEvent, index: number) => {
9696
const { height } = event.nativeEvent.layout;
9797
const round = Math.round(height);
98-
ItemHeights?.push(round * ItemHeights.length + round);
98+
ItemHeights[index] = round * ItemHeights.length + round;
9999
};
100100

101101
const location = (scrollY: number, index: number) => {
@@ -158,7 +158,7 @@ const Picker = (props: PickerProps) => {
158158
>
159159
{date.map((item, index) => (
160160
<Pressable
161-
onLayout={getItemHeight}
161+
onLayout={(event: LayoutChangeEvent) => getItemHeight(event, index)}
162162
key={index}
163163
onPressOut={Platform.OS === 'android' ? onTouchEnd : undefined}
164164
onPress={() => {

0 commit comments

Comments
 (0)