Juanpe / SkeletonView

☠️ An elegant way to show users that something is happening and also prepare them to which contents they are awaiting
MIT License
12.53k stars 1.1k forks source link

Skeleton displays in device's selected theme for fraction of second #392

Open KrishnaKaira opened 3 years ago

KrishnaKaira commented 3 years ago

Description

We have custom implementation of dark theme, and user can select theme from inside the application setting. Now, when user either uses system theme, or same theme as device, skeleton color shows smoothly. But lets say if user selects 'Dark' theme in application setting, and user's device is in 'Light' mode, the skeleton displays in light mode for a fraction of second before it switches to dark color, and vice versa. Seems like some how skeleton is picking device's theme before it switches to application's theme. We are overriding the theme using overrideUserInterfaceStyle = style //.dark, .light OR .unspecified in viewDidLoad() before adding skeleton to the view.

What type of issue is this? (place an x in one of the [ ])

Requirements (place an x in each of the [ ])


Bug Report

We are overriding the UIViewController's property inside viewDidLoad based on user's preference from inside app setting: overrideUserInterfaceStyle = style //.dark, .light OR .unspecified Now, added skeleton view as subview and setting the color for skeleton as: view.showAnimatedGradientSkeleton(usingGradient: SkeletonGradient(baseColor: UIColor.appColor(.gray6)))

UIColor.appColor(.gray6) -> returns adaptive color equals to UIColor.systemGray6

We have tried to set fix color also, but still it shows in device's theme first before setting the color properly.

SkeletonView Environment:

SkeletonView version: 1.8.6 Xcode version: 12.4 Swift version: 4.x

Steps to reproduce:

Please replace this with the steps to reproduce the behavior.

  1. Add this to viewDidLoad: overrideUserInterfaceStyle = .dark
  2. Now add skeleton view as subview on viewController's view
  3. keep your device in light mode (disable dark mode)
  4. show Skeleton using view.showAnimatedGradientSkeleton(usingGradient: SkeletonGradient(baseColor: UIColor.systemGray6))

Expected result:

Skeletons color should always show in provided color.

Actual result:

Skeleton color was displaying in device's theme for fraction of second before displaying the accurate color.

Attachments:

https://user-images.githubusercontent.com/4772362/117786114-cfeeb980-b262-11eb-8724-33964d11317e.mp4

KrishnaKaira commented 3 years ago

@Juanpe Did you get any chance to look into it? I would like to drag your attention here. Is there any way that we could override user interface style for skeleton view? It is somehow picking system's selected style for fraction of second.

Juanpe commented 3 years ago

Hi @KrishnaKaira,

TBH, I could check this issue yet. I'm going to try to check it asap. :)

diogot commented 2 years ago

I'm observing similar behaviour. I override overrideUserInterfaceStyle for all app windows and the skeletons always follow the system style instead of the window one (that's inherited by it's subviews). I did some investigation and I think that happens because the layers are created unattached from the view/layer hierarchy (SkeletonType.layer), so when the colors are set CALayer+Tint.swift:20 the layer will infer the style from the system because it can't get it from the parent layer.

But I don't how to fix this.

colincavil112 commented 2 years ago

I am also experiencing this issue.

chetankasundra commented 1 year ago

I am also experiencing this issue. Let me know if this issue is fixed now.

rahulVermaSimpplr commented 4 months ago

@Juanpe did you get any chance to look into this issue, actually now in latest release it's not just flickering but it picks the system theme only and ignore apps theme.

Simulator Screenshot - iPhone 15 Pro - 2024-03-05 at 12 56 42 Here in attached screenshot, my app's theme is dark and device theme is light, so the skeleton automatically picks the light colour which is for light app theme.