Skip to content

Commit da05ccb

Browse files
authored
fix wheelpicker in android (#2558)
* fix wheelpicker in android * Removed initialNumToRender, removed style * removed itemLength variable * opt-out * added flatListProps to wheelPicker.api * added note to the api.json file * refactor the nore * fixed note * minor fix
1 parent 07f6077 commit da05ccb

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/components/WheelPicker/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ const WheelPicker = ({
146146
const prevIndex = useRef(currentIndex);
147147
const [flatListWidth, setFlatListWidth] = useState(0);
148148
const keyExtractor = useCallback((item: ItemProps, index: number) => `${item}.${index}`, []);
149+
const androidFlatListProps = useMemo(() => {
150+
if (Constants.isAndroid) {
151+
return {
152+
maxToRenderPerBatch: items.length
153+
};
154+
}
155+
}, [items]);
149156

150157
useEffect(() => {
151158
// This effect making sure to reset index if initialValue has changed
@@ -323,6 +330,7 @@ const WheelPicker = ({
323330
<View row centerH>
324331
<View flexG>
325332
<AnimatedFlatList
333+
{...androidFlatListProps}
326334
{...flatListProps}
327335
testID={`${testID}.list`}
328336
listKey={`${testID}.flatList`}

src/components/WheelPicker/wheelPicker.api.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "WheelPicker",
33
"category": "form",
44
"description": "A customizable WheelPicker component",
5+
"note": "When using Android by default the FlatList will have <code>maxToRenderPerBatch</code> prop set to <code>items.length</code> to solve FlatList bug on Android, you can override it by passing your own <code>flatListProps</code> with <code>maxToRenderPerBatch</code> prop.<br/>See the RN FlatList issue for more info: https://github.com/facebook/react-native/issues/15990",
56
"example": "https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/WheelPickerScreen.tsx",
67
"images": [],
78
"props": [
@@ -33,7 +34,12 @@
3334
"default": "center"
3435
},
3536
{"name": "separatorsStyle", "type": "ViewStyle", "description": "Extra style for the separators"},
36-
{"name": "testID", "type": "string", "description": "test identifier"}
37+
{"name": "testID", "type": "string", "description": "test identifier"},
38+
{
39+
"name": "flatListProps",
40+
"type": "FlatListProps",
41+
"description": "Props to be sent to the FlatList."
42+
}
3743
],
3844
"snippet": [
3945
"<WheelPicker",

0 commit comments

Comments
 (0)