crisp-im / crisp-sdk-ios

:package: Crisp iOS SDK, add a chat in any iOS app and communicate with your users.
https://docs.crisp.chat/guides/chatbox-sdks/ios-sdk/
Other
45 stars 19 forks source link

ChatViewController crashes when supporting dark/light mode #85

Closed juusokos closed 1 year ago

juusokos commented 1 year ago

The Crisp ChatViewController crashes every time when opened within an app that support Dark/Light mode color theming.

Key to the crash is supporting SwiftUI ligh/dark mode:

  1. Have ´Global Accent Color Name´ setting for target in default ´AccentColor´ state
  2. Add Colors to Assets
  3. Try to open Crisp chat

Here’s a simple isolated example project you can use that replicates the crash.

https://github.com/juusokos/Crisp-theme-crash

nesium commented 1 year ago

Hey @juusokos. Thank you for putting together an example project! We'll look into the problem.

nesium commented 1 year ago

So, it looks like the crash isn't related to the Crisp SDK at all.

I've noticed that the color property of the AccentColor is set to resolve to tintColor but only for light mode which is why this crash doesn't happen in dark mode.

Screenshot 2023-06-22 at 16 17 06

If we look at the documentation of UIColor.tintColor, we'll find this:

A color value that resolves at runtime based on the current tint color of the app or trait hierarchy.

You can even reduce the test case to the following which crashes in light mode:

struct ContentView: View {
    var body: some View {
      Text("Hello World").foregroundColor(.accentColor)
    }
}

What happens is an infinite recursion where when accessing Color.accentColor it tries to resolve to UIColor.tintColor which tries to resolve to Color.accentColor which tries to resolve to… (you get the point).

Here's a part of the stack:

Screenshot 2023-06-22 at 16 27 11

In any event, you don't have to wrap the ChatViewController to use it in Swift but can (and should) use our provided ChatView for SwiftUI.