flowkey / UIKit-cross-platform

Cross-platform Swift implementation of UIKit, mostly for Android
MIT License
594 stars 40 forks source link

Cache screen scale to prevent crashes #367

Closed ephemer closed 2 years ago

ephemer commented 2 years ago

Fixes crashes when accessing a deinited UIScreen

Type of change: Bug fix

Motivation (current vs expected behavior)

Sometimes application code will init objects that inadvertently access UIScreen.main, usually for UIScreen.main.scale. Since we never update the screen scale after init, we can cache the last known value and use it internally for our calculations. This will reduce the number of crashes we see without affecting behaviour.

Please check if the PR fulfills these requirements