Add checks to prevent invalid context error. #63

Closed
opened 2025-10-14 15:58:23 -06:00 by navan · 0 comments
Owner

Originally created by @GetToSet on 5/2/2020

I found a weird error log regarding invalid CGContext when using this framework.
Error regarding invalid context

After some investigation, I found its cause:

CompletionButton is redrawing its background image at traitCollectionDidChange, which is called before layoutSubviews. At early initialization stage, the button may have empty frame with both height and width set to 0, resulting "invalid context error" when drawing background image.

This commit adds extra check to prevent creating context when frame is empty, delaying the creation of background image to layoutSubviews call.

*Originally created by @GetToSet on 5/2/2020* I found a weird error log regarding invalid `CGContext` when using this framework. ![Error regarding invalid context](https://user-images.githubusercontent.com/8158163/80859242-aa16f800-8c91-11ea-8f42-76e6cfe2d023.png) After some investigation, I found its cause: `CompletionButton` is redrawing its background image at `traitCollectionDidChange`, which is called before `layoutSubviews`. At early initialization stage, the button may have empty frame with both height and width set to 0, resulting "invalid context error" when drawing background image. This commit adds extra check to prevent creating context when frame is empty, delaying the creation of background image to `layoutSubviews` call.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github/WhatsNewKit#63
No description provided.