Fix automatic day/night switching #2881
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
withTimer.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.