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

Add ExpandingVC Timeout + Explicitly Call updateScrollViewHeight on main thread #182

Merged
merged 8 commits into from
Sep 3, 2024

Conversation

NicoHinderling
Copy link
Collaborator

No description provided.

@NicoHinderling NicoHinderling force-pushed the height-expansion-new-logic branch 2 times, most recently from 40e4a1c to c04a7a8 Compare August 26, 2024 15:23
@NicoHinderling NicoHinderling force-pushed the height-expansion-new-logic branch from c04a7a8 to 9ac6fd6 Compare August 26, 2024 15:32
@NicoHinderling NicoHinderling force-pushed the height-expansion-new-logic branch from 7e6bb8b to aecba58 Compare August 26, 2024 15:36

func startTimer() {
if self.timer == nil {
self.startTime = Date()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we eliminate all the self. that aren't necessary? I noticed they aren't used in other functions like "stopAndResetTimer", we shouldn't have them here either

NSLog("ExpandingViewController: Expanding Scroll View timed out. Current height is \(scrollView?.visibleContentHeight ?? -1)")

// Setting anchors back to full
let fittingSize = self.sizeThatFits(in: UIScreen.main.bounds.size)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry a bit about this sizeThatFits call only because it has to run on the main thread, and could take time/cause other layout changes. What is the reason for setting the anchors here rather than just calling runCallback?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because in our discussion last week, I recall you saying if we time out, we should ensure that the size of the snapshot reverts back to "default" aka just the full screen

is that no longer the case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary/not sure why it would be helpful

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if we did need to change the size might make more sense to use the full screen like you said, but this would use a variable height right? Either way I don't think we should touch the heightAnchor once we decide it's going to be an error

// Timeout limit
if timer == nil {
startTimer()
} else if elapsedTime >= HeightExpansionTimeLimitInSeconds {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have this here and when the timer fires? Shouldn't we only need it when the timer fires? If we do need it in both places, can we pull out the common handling code into a function + add a comment about why it's called from both places?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I was on the fence about this. I will remove this so it's only in the location of the timer callback

// MARK: - Timer

func startTimer() {
if timer == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly more swifty to make this a guard

func startTimer() {
if timer == nil {
startTime = Date()
timer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { [weak self] _ in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this time interval should be higher to prevent it from firing a bunch of times without doing anything?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for sure, i changed this to 1 second rather than 0.1

guard let self else {
return
}
if let start = startTime {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move this into the above guard

public var expansionSettled: ((EmergeRenderingMode?, Float?, Bool?) -> Void)? {
private var startTime: Date?
private var timer: Timer?
private var elapsedTime: TimeInterval = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we delete this and just make it a local var in the timeout handler? It doesn't seem to be used outside of that

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes mb, not anymore. good call

Copy link
Member

@noahsmartin noahsmartin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if this could be done in a platform agnostic way to work with Mac too, but this seems good for now

NSLog("ExpandingViewController: Expanding Scroll View timed out. Current height is \(firstScrollView?.visibleContentHeight ?? -1)")
runCallback(timeoutError)
}
print("Timer scheduled")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we delete this log? Seems like we don't need it in prod?

@NicoHinderling NicoHinderling merged commit 15737c9 into main Sep 3, 2024
7 checks passed
@NicoHinderling NicoHinderling deleted the height-expansion-new-logic branch September 3, 2024 21:48
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

Successfully merging this pull request may close these issues.

2 participants