Skip to content
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

FlatList items are disappeared after pinching zoom #33705

Closed
vinsongeo opened this issue Apr 24, 2022 · 2 comments
Closed

FlatList items are disappeared after pinching zoom #33705

vinsongeo opened this issue Apr 24, 2022 · 2 comments

Comments

@vinsongeo
Copy link

Description

When I was using FlatList to display a large list over 500 items in it, I faced a bug like problem. Pinching zoom the list will work fine, but if I scroll the list to the center when zoomScale was 2, then the items in the viewport ware disappeared. I'v guessed that the problem occurred while calculate clipped subviews without adding zoomScale. Is there every one else has another solution to resolve this problem? BTW I have set removeclippedsubviews false and implemented getItemLayout and it still not work fine. orz.

code are below

export default class TestView extends Component{
itemHeight = 600; data = Array.from({length: 500}, () => "#"+Math.floor(Math.random()*16777215).toString(16));
render() {
return <><TouchableOpacity style={{marginTop:100}} onPress={()=>{this.props.navigation.goBack()}}>Close
<FlatList data={this.data} keyExtractor={(item, index) => index.toString()}
renderItem={({ item }) => ( <View style={{height:this.itemHeight,width:"100%",backgroundColor:item}} />)}
contentContainerStyle={{height:this.data.length * this.itemHeight}}
maximumZoomScale={2} minimumZoomScale={1} bouncesZoom={false}/></>
}
}

Version

0.64.3

Output of npx react-native info

System:
OS: macOS 12.3.1
CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
Memory: 195.21 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.7.0 - /usr/local/bin/node
Yarn: 1.22.18 - /usr/local/bin/yarn
npm: 7.24.0 - /usr/local/bin/npm
Watchman: 2021.08.02.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 8.5
Android SDK:
API Levels: 30, 31
Build Tools: 29.0.2, 31.0.0
Android NDK: Not Found
IDEs:
Android Studio: 2020.3 AI-203.7717.56.2031.7583922
Xcode: 13.3.1/13E500a - /usr/bin/xcodebuild
Languages:
Java: Not Found
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.1 => 17.0.1
react-native: 0.64.3 => 0.64.3
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

export default class TestView extends Component{
itemHeight = 600; data = Array.from({length: 500}, () => "#"+Math.floor(Math.random()*16777215).toString(16));
render() {
return <><TouchableOpacity style={{marginTop:100}} onPress={()=>{this.props.navigation.goBack()}}>Close
<FlatList data={this.data} keyExtractor={(item, index) => index.toString()}
renderItem={({ item }) => ( <View style={{height:this.itemHeight,width:"100%",backgroundColor:item}} />)}
contentContainerStyle={{height:this.data.length * this.itemHeight}}
maximumZoomScale={2} minimumZoomScale={1} bouncesZoom={false}/></>
}
}

Snack, code example, screenshot, or link to a repository

No response

@vinsongeo
Copy link
Author

Finally, I know this bug can be fixed by adding [/ e.nativeEvent.zoomScale;] into _onScroll of VirtualizedList.js

let offset = this._selectOffset(e.nativeEvent.contentOffset) / e.nativeEvent.zoomScale;

I hope this problem could be fixed by next version.

@vinsongeo
Copy link
Author

onScroll={(event) => { event.nativeEvent.contentOffset.y = event.nativeEvent.contentOffset.y / event.nativeEvent.zoomScale; }}

facebook-github-bot pushed a commit that referenced this issue May 6, 2022
Summary:
fix #33705
Fixed the disappearance of items when scrolling after zooming VirtualizedList.
example https://github.com/islandryu/zoomVirtualizedList

Before modification

https://user-images.githubusercontent.com/65934663/166849127-9fc3ba84-5172-4ae1-bd44-dd6312f283ec.mov

After modification

https://user-images.githubusercontent.com/65934663/166868632-2f78e118-f705-442d-b94e-ff165bed26c7.mov

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[General] [Fixed] - Fixed the disappearance of items when scrolling after zooming VirtualizedList.

Pull Request resolved: #33765

Test Plan:
Make the VirtualizedList zoomable with a prop such as maximumZoomScale.
Apply the patch and make sure that items in the VirtualizedList do not disappear when you scroll after zooming the VirtualizedList.

Or apply the patch from this repository and check it.
https://github.com/islandryu/zoomVirtualizedList

Reviewed By: javache

Differential Revision: D36169686

Pulled By: yungsters

fbshipit-source-id: 0f86255c2864be13f6d2dc5a58af1d11c9eedac3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants