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

Visibility problem #127

Closed
MFlisar opened this issue Oct 9, 2015 · 9 comments
Closed

Visibility problem #127

MFlisar opened this issue Oct 9, 2015 · 9 comments

Comments

@MFlisar
Copy link

MFlisar commented Oct 9, 2015

I was using version 3.2.0 and never had problems, now with 3.4.0 I experience following problem:

Sometimes I have to scale the image with my fingers before it's shown... onReady is called, but the screen stays empty until I do a scale gesture, this makes the image visible

The other thing is, that in my ViewPager using a FragmentStatePagerAdapter the views to the left/right sometimes to load the images as well until I swipe to them. The fragments are created but onReady of the image does not get called. Touching the current page does help and results in onReady for the left and right image to get called...

@MFlisar MFlisar changed the title Showing problem Visibility problem Oct 9, 2015
@davemorrissey
Copy link
Owner

I can't reproduce this. There's a possibility that release 3.4.1 has fixed it, please try that and let me know if you're still seeing this problem. Please also include the code you're using to set up the view.

@MFlisar
Copy link
Author

MFlisar commented Oct 14, 2015

I can post the adapter if you want, but I think I've found something:

  • I'm using activity transitions, if I disable them, it works fine... onReady/onImageLoaded seems to work always now as I can see, just the image stays empty until i swipe a bit on it...
  • it happens more often with big images (4000x4000 and upwards)

Any ideas on that?

I want to change this anyway to use a preview image on top of your view for the transitions. This may solve this problem as the transitions won't mess around with your views visibility...

@inorichi
Copy link

I'm also facing the problem with the ViewPager, the image of a fragment is empty until a bit of swiping is done to that fragment.
I have tried with a big offScreenPageLimit, but it still happens. Fragments already cached (when going back) doesn't have this issue.

I thought it was related to #117, but I'm not using previews. I've also tried setting image dimensions.

Disabling tiling fixes it, but I would like to keep it enabled. The images used are around ~1000x1600

@davemorrissey
Copy link
Owner

I still can't reproduce anything like this, with or without custom page transitions, and with small or large images. With tiling enabled, it's normal for the image to not be displayed immediately when you start the swipe to the next page, because it has to load. It can't be loaded until the view's dimensions are known, and the dimensions may not be known until the view is partly on screen.

I have never seen the view get to calling onReady without displaying the image, or need extra touch gestures to prompt the image to be displayed.

@MFlisar
Copy link
Author

MFlisar commented Nov 7, 2015

Actually, the second thing is not reproducable anymore... So I would say that was something different. Probably something with transitions, I'm not sure anymore.

If the other thing can't be solved currently, I would suggest something like following: a constructor for the image that takes a size as well, so the image could be loaded before the view is rendered? Or something similar

@davemorrissey
Copy link
Owner

It's the view size that's needed, not the image size. I'm considering an option to override the default handling and assume the view will be full screen then subsample the image accordingly, but misuse of this flag would cause crashes and it adds yet another loading path to the many already present.

@MFlisar
Copy link
Author

MFlisar commented Nov 7, 2015

Of course, the view size... But in a gallery app for example, the view size normally is full screen and therefore is already known, so this would probably be quite useful for many people

@inorichi
Copy link

With these changes I was able to load the initial tile before a fragment is partially visible. The view dimensions of non visible fragments from the viewpager are known beforehand (getWidth() and getHeight() return the view size), but the initial tile isn't loaded until the first onDraw call.

The problem is that we lose access to the canvas when initializing outside onDraw, so getMaximumBitmapWidth and getMaximumBitmapHeight can't be used.

That's the reason I added the setMaxDimensions method. Then in the onCreate of the activity I stored the value obtained from this method (the activity is declared hardware accelerated in the manifest) and assign that value to every image view with setMaxDimensions.

In my tablet and phone the method returns 4096 instead of the 16384 returned by the canvas method, but I haven't tried with bigger images so I don't know if there will be any issue.

I'm also not sure if this causes any other problem in the library, but it works fine in my case.

Are these changes safe enough @davemorrissey ?

@davemorrissey
Copy link
Owner

I've implemented @inorichi's suggestion and it works well. The next image in a view pager is loaded while off screen.

I'm not certain whether this was the cause of the original issue, which I never reproduced, but will close this now. Please reopen if there are other cases where the image is not loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants