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

Fix automatic day/night switching #2881

Merged
merged 2 commits into from Mar 29, 2021
Merged

Conversation

azarovalex
Copy link
Member

@azarovalex azarovalex commented Mar 23, 2021

Description

Fixes #2766.

Implementation

Currently, automatic day/night switching doesn't work at all, because we don't add timeOfDayTimer inside of the RunLoop, therefore it never fires. I fixed this issue by replacing plain Timer.init with Timer.scheduledTimer. The latest one, according to the documentation schedules timer on the current RunLoop. After this fix, StyleManager works as expected, but the sample app crashes inside of the VanishingRouteLine because it saves an outdated style internally. I fixed this by adding a guard statement inside of VanishingRouteLine.swift. I also verified that the performance wasn't affected using os_signpost and Instruments on a real iPhone with Release build.

There is also a minor change in StyleManager.applyStyle function, where we iterate through all styles and search for the right one. In my opinion, we can break the cycle after finding a first suitable theme, because right now we continue to iterate and do unnecessary work applying other styles as well. My fix however can break the existing behavior for our customers, but for me, this particular case looks minor enough. If you don't agree, we still can optimize this code by iterating the collection backward and breaking after the first match.

@azarovalex azarovalex added the bug Something isn’t working label Mar 23, 2021
@azarovalex azarovalex self-assigned this Mar 23, 2021
@azarovalex azarovalex requested a review from a team March 23, 2021 12:53
@azarovalex azarovalex merged commit 18b8db0 into main Mar 29, 2021
@azarovalex azarovalex deleted the azarovalex/fix-day-night-switching branch March 29, 2021 10:17
@MaximAlien MaximAlien mentioned this pull request May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn’t working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Navigation can stop when transitioning between night and day
2 participants