Skip to content

fix wheelpicker in android #2558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/components/WheelPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ const WheelPicker = ({
const prevIndex = useRef(currentIndex);
const [flatListWidth, setFlatListWidth] = useState(0);
const keyExtractor = useCallback((item: ItemProps, index: number) => `${item}.${index}`, []);
const androidFlatListProps = useMemo(() => {
if (Constants.isAndroid) {
return {
maxToRenderPerBatch: items.length
};
}
}, [items]);

useEffect(() => {
// This effect making sure to reset index if initialValue has changed
Expand Down Expand Up @@ -323,6 +330,7 @@ const WheelPicker = ({
<View row centerH>
<View flexG>
<AnimatedFlatList
{...androidFlatListProps}
{...flatListProps}
testID={`${testID}.list`}
listKey={`${testID}.flatList`}
Expand Down
8 changes: 7 additions & 1 deletion src/components/WheelPicker/wheelPicker.api.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "WheelPicker",
"category": "form",
"description": "A customizable WheelPicker component",
"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",
"example": "https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/WheelPickerScreen.tsx",
"images": [],
"props": [
Expand Down Expand Up @@ -33,7 +34,12 @@
"default": "center"
},
{"name": "separatorsStyle", "type": "ViewStyle", "description": "Extra style for the separators"},
{"name": "testID", "type": "string", "description": "test identifier"}
{"name": "testID", "type": "string", "description": "test identifier"},
{
"name": "flatListProps",
"type": "FlatListProps",
"description": "Props to be sent to the FlatList."
}
],
"snippet": [
"<WheelPicker",
Expand Down