Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Recent update broke cells auto-sizing and updating. #113

Closed
alexeyprimechaev opened this issue Mar 12, 2020 · 19 comments
Closed

Recent update broke cells auto-sizing and updating. #113

alexeyprimechaev opened this issue Mar 12, 2020 · 19 comments

Comments

@alexeyprimechaev
Copy link

Describe the bug
A recent update (not sure which one, but I've switched from the dev branch (now non-existent) to the master branch) completely and utterly destroyed my layout (I'm using the layout from the TagsScreen Demo). Now cells not only flicker and are of incorrect sizes, but also not interactable while updating. Context menus (awesome menus tho) also do not work.

I'm attaching videos of behavior before the update and after.

I'm currently building an application that heavily relies on your wonderful library, so it would be very sad if I was unable to continue using it.

Love your work ❤️❤️❤️

To Reproduce
I could send you my project if you're interested.

Expected behaviour
Everything working gracefully.

Screenshots
https://imgur.com/a/fppwCwn

Xcode Version:
11.4 Beta

Simulator, Device, Both?
Both

@apptekstudios
Copy link
Owner

That is some strange behaviour indeed! I would appreciate a project that exhibits the issue as I couldn't manage to reproduce it to investigate.

@apptekstudios
Copy link
Owner

An unrelated suggestion: look into using a monospaced font for your timers, it's an easy way to avoid them changing size as the numbers change :)

@1234igor
Copy link

Got the same problem after update 🙁

@apptekstudios
Copy link
Owner

@1234igor also using a flowLayout?

@alexeyprimechaev
Copy link
Author

alexeyprimechaev commented Mar 13, 2020

@apptekstudios Hey! Regarding the monospaced font suggestion, I already dealt with that. Well, kinda. Inside every timer cell there is an invisible Text View with “88:88”, so that the width of the view doesn’t change every second :)

@alexeyprimechaev
Copy link
Author

@apptekstudios How could I send you my project privately?

@apptekstudios
Copy link
Owner

Please see my email 👍

@apptekstudios
Copy link
Owner

@alexeyprimechaev Has everything been working with the latest version + changes I sent through?

@alexeyprimechaev
Copy link
Author

alexeyprimechaev commented Mar 20, 2020

@apptekstudios not really.
Once I got rid of the monospaced font (which unfortunately ruins the whole aesthetic of the app) and implemented back my method for cells to not resize every frame (which definitely worked in the dev branch of this library), the flickering returned.

https://imgur.com/a/r20a8Qw

(you can see that the width of the cells doesn't actually change and yet they flicker like hell)

@apptekstudios
Copy link
Owner

@alexeyprimechaev I’ve made some further changes in V1.4 (which is now released) that I’m hopeful will resolve this.

@alexeyprimechaev
Copy link
Author

alexeyprimechaev commented Mar 29, 2020

@apptekstudios Yes, now layout behaves as expected and cells only resize whenever necessary!

However, (this one is probably specific to my project) when timers are run in default loop, scrolling works, but the views pause updating (while dragging) and the ASCV autoscrolls back to top on every redraw (I presume).

When timers are run on the main thread the individual views do update, but scrolling is fundamentally broken as when even while dragging views are updating, and ASCV is attempting to scroll to the top.

Both cases: https://imgur.com/a/ahFnTat

❤️❤️❤️

@apptekstudios
Copy link
Owner

I’m working on moving the diffing (UICollectionViewDiffableDataSource) to a background thread, this should improve performance and hopefully mean updates are less susceptible to other things blocking the main thread.

Regarding the scrolling to top, I’m not sure why this would be happening and will investigate later today :)

An app I’m currently working on also has a timer view that needs regular updating, and I’ve found that (even without ASCollectionView) SwiftUI is struggling to keep up and is sometimes blocking user interaction. I’ve come up with a solution to ensure only the timer label is being refreshed (vs the entire view) and will aim to share ASAP 👍

@apptekstudios
Copy link
Owner

apptekstudios commented Mar 31, 2020

The views not updating while scrolling is actually a known UIKit quirk. UIScrollView blocks the main runloop so timers aren't called.

Schedule your timer specifically setting the .common mode:

	let newTimer = Timer(timeInterval: 0.1, repeats: true, block: step)
	RunLoop.current.add(newTimer, forMode: .common)
	timer = newTimer

https://stackoverflow.com/questions/5377914/uilabel-updating-stops-during-scrolling-uiscrollview

@apptekstudios
Copy link
Owner

I have identified the cause of scrolling to the top, turns out that setting certain UICollectionView properties resets the scroll position, even if they are unchanged. I will release an update shortly to address that 👍

@apptekstudios
Copy link
Owner

@alexeyprimechaev Another recommendation regarding your code would be to decouple the coreData model from your actual timer class. Currently whenever the currentTimeStored of one timer is being updated it is triggering the entire FetchRequest to refresh (try putting a breakpoint in your ContentView.body when a timer is running). This means that your entire content view is being recalculated 10 times a second → this is why swiftUI is sometimes not allowing user interaction

@apptekstudios
Copy link
Owner

V1.4.1 should resolve the issue with scrolling back to the top 🎉

@alexeyprimechaev
Copy link
Author

@apptekstudios checked out the update — yup, scrolling now works, and almost perfectly.

I only have a couple of minor complaints with your otherwise beautiful library.

https://imgur.com/a/8VQevCX

@alexeyprimechaev
Copy link
Author

@

@alexeyprimechaev Another recommendation regarding your code would be to decouple the coreData model from your actual timer class. Currently whenever the currentTimeStored of one timer is being updated it is triggering the entire FetchRequest to refresh (try putting a breakpoint in your ContentView.body when a timer is running). This means that your entire content view is being recalculated 10 times a second → this is why swiftUI is sometimes not allowing user interaction

will definitely work on that 👍

@apptekstudios
Copy link
Owner

Regarding lack of animations, try wrapping your state change in a withAnimation block

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

No branches or pull requests

3 participants