ListViewGrid Not Scrolling
Hello. I've come across an issue that's more than likely user error, as I am new to RN, but perhaps someone could help me.
I am receiving images from a user's phone to display in a ListView. Let's say the user has 25 images, and I'm fetching all 25. The users display only allows 12 images to be displayed, so they must scroll to view more. My issue is the ListView will not scroll.
If I rotate the phone from portrait to landscape, the ListView will suddenly start to work as I'd expect (allows the user to scroll up and down). Likewise, if I switch back to portrait, the scrolling functionality is still properly working. Upon reload, it will be broken again.
I've tried creating a fresh project and adding more objects to the dataObjects in ListViewGridExample to simulate 25 images, but the same issue above occurs. The ListView will not scroll unless I change the phone's orientation. What am I missing here?
Testing on Android
Ignite
Version: 1.5.0
Node
Version: v6.3.1
NPM
Version: 3.9.2
Yeoman
Version: 1.8.4
React Native CLI
Version: 1.0.0
App
React Native Version: 0.31.0
Can you paste your ListView code and related styles here?
Sure. I don't believe I've edited these other than adding more to dataObjects. To add on, I've tested this on a freshly generated base and same issue occurs.
ListView code: http://pastebin.com/7rLcTzCp ListView styles: http://pastebin.com/rBBe2qrR
@NotoriousV2 This might do something, this might not...but could you try to add
width: Metrics.screenWidth
to your listContent style and see if that does the trick?
@fvonhoven Adding width: Metrics.screenWidth to listContent did not do anything; however, I tried adding height: Metrics.screenHeight instead, and it did indeed do something.
While it's not properly functioning, perhaps height has something to do with it which is why screen orientation changes has an effect?
I've recorded what is happening with height: Metrics.screenHeight added to listContent: https://youtu.be/uEv5NMNBVyA
Very interesting. I came across an issue with horizontal ListView that setting an explicit width/height prop fixed. The scrolling works on iPhone and it looks like it's working on your android emulator. When you say it's not properly functioning, do you mean that the cells are not all rendered on the screen initially?
On Aug 19, 2016, at 5:21 PM, Cole Pizzarella [email protected] wrote:
@fvonhoven Adding width: Metrics.screenWidth to listContent did not do anything; however, I tried adding height: Metrics.screenHeight instead, and it did indeed do something.
While it's not properly functioning, perhaps height has something to do with it which is why screen orientation changes has an effect?
I've recorded what is happening with height: Metrics.screenHeight added to listContent: https://youtu.be/uEv5NMNBVyA
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
@fvonhoven That is correct. When adding the height to the listContent style, the scrolling functionality seems to work, but not all cells are rendered initially. In the video example, 18 or so cells should be initially on screen due to the screen size, and more should load when scrolling.
Perhaps I am misunderstanding how this should work. Any suggestions?
Totes. In your ListView, set the prop initialListSize={25}
See if that gives you what you're looking for 😄
Great, that's exactly what I was looking for. It seems simply setting an initialListSize that will fill up the screen and cause it to overflow will allow the scrolling to happen. I had thought this would happen automatically without having to set an initial size if your dataObjects has enough rows to do so. This must not be the case?
I am wondering then if a user's display is large enough to hold 25 cells without overflowing (and the dataObjects has over 25 cells... 75 for example), then the scrolling functionality will be broken again?
If I set the initialListSize to 10 to simulate this, I am back to having a non-scrolling list. Is this just how the ListView functions? You must set the initialListSize manually to fill up the screen?
as a heads up, sometimes a flex:1 on the container view is bad. I found this out the other day. Not really a rule I can apply here without some investigation, but just surprised to see this change in 0.31.0 RN.
I might take a look at this issue over the weekend.
RN ListViews like to have fixed heights otherwise scrolling will not work. This has bitten me a time or two. That is where having flex: 1 set on a container can cause issues. Also, the content height has to exceed the ListView height before it will scroll. So no matter what, if the height of the ListView is taller than the content inside of it, it will not scroll until the content extends past the bottom. Well, it will scroll, but it will just bounce back.
initialListSize is for making sure the first screen worth of data is rendered all at once instead of possibly across multiple frames. If you have enough data to fill the screen, this should not be required unless you are worried about rendering. Without it, if it's a large screen and there isn't enough data to fill it, it won't scroll because it won't need to.
Maybe try leaving the container styles as is without a height and just styling the ListView itself with a height.
// ListView
<ListView
style={styles.listView}
...
/>
// Styles
listView: {
height: Metrics.screenHeight - Metrics.navBarHeight
}
@carlinisaacson Thank you for the clarification on initialListSize. It seems no matter what I try, I cannot get the initial render to display more than 11 cells (unless I set it via initialListSize), which causes it to not scroll. If I flip the orientation, those initial 11 cells now extend past the bottom, which then allows the list to scroll and load more cells like it should.
I've tried your suggestion, along with a few variations like removing flex: 1 on the container and some other tinkering to see if I could get it to load more than 11 cells, but without explicitly setting with initialListSize, I've had no luck.
I have enough data to fill the screen, but it's not loading enough to extend past the bottom. In this case, it loads 11 cells when it needs 18 or so to fill the device's screen and extend to allow scrolling.
Try flex: 1 on everything down to the <ListView> including <ListView style={...}> but excluding <ListView contentContainerStyle={...}>. In fact, just delete that contentContainerStyle entirely for a moment.
flex: 1 means "grow to my parent but share with my siblings". Without it, you grow to the size of your children. And I think that's what's happening to your list.
@skellock Hey. So I've tried a few things. First, I tried your suggestion with passing flex: 1 to everything but the contentContainerStyle with no luck. I then removed the contentContainerStyle which caused my cells to change from the row-wrap to a column. This causes the cells to extend passed the bottom, which allows scrolling to function as it should. But for my case, I need the cells to display in a row-wrap.
I then tried removing the top-most <View> and leaving just the <ListView> which still resolves in the same issue.
After trying all this, I then attempted the same suggestions on a newly generated Ignite project which also resolved in the same issue. I don't believe my current project differs from the freshly generated one as I've basically reset everything to default trying to figure this out, but I thought I'd test just in case.
I do not have access to an iOS device, so I've been trying all these suggestions on an Android device. I am unsure if this has anything to do with it.
I have same issue
Step 1: Create new project ignite new MyApplication Step 2: Edit file ListviewExample.js something like below
const dataObjects = [
{title: 'First Title', description: 'First Description'},
{title: 'Second Title', description: 'Second Description'},
{title: 'Third Title', description: 'Third Description'},
{title: 'Fourth Title', description: 'Fourth Description'},
{title: 'Fifth Title', description: 'Fifth Description'},
{title: 'Sixth Title', description: 'Sixth Description'},
{title: 'Seventh Title', description: 'Seventh Description'},
{title: 'First Title', description: 'First Description'},
{title: 'Second Title', description: 'Second Description'},
{title: 'Third Title', description: 'Third Description'},
{title: 'Fourth Title', description: 'Fourth Description'},
{title: 'Fifth Title', description: 'Fifth Description'},
{title: 'Sixth Title', description: 'Sixth Description'},
{title: 'Seventh Title', description: 'Seventh Description'},
{title: 'First Title', description: 'First Description'},
{title: 'Second Title', description: 'Second Description'},
{title: 'Third Title', description: 'Third Description'},
{title: 'Fourth Title', description: 'Fourth Description'},
{title: 'Fifth Title', description: 'Fifth Description'},
{title: 'Sixth Title', description: 'Sixth Description'},
{title: 'Seventh Title', description: 'Seventh Description'}
]
Fixed by remove flex: 1
listContent: {
//flex: 1,
marginTop: Metrics.baseMargin
}
ListView Not Scrolling only on Android. Tested on Adroid simulator and device
@tk1cntt Hello, it looks like your fix works for the ListViewExample. Do you run into the same issue when using the ListViewGridExample?
This will be updated and work correctly in 1.6.2, should be released today.