Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic iOS and Web color theme #714

Conversation

alexzhirkevich
Copy link

@alexzhirkevich alexzhirkevich commented Jul 27, 2023

Proposed Changes

  • Added LocalUITraitCollectionState to allow observing trait collection changes in composition
  • Added dynamic dark/light theme switching for iOS and web.
  • Added isSystemInDarkTheme support for iOS < 13 (actually i'm not sure if Compose works on iOS < 13 but a nice bonus)

Testing

Test: try to switch color theme while running mpp app

Issues Fixed

Fixes: JetBrains/compose-multiplatform#3213

@alexzhirkevich alexzhirkevich changed the title Dynamic iOS color theme Dynamic iOS and Web color theme Jul 27, 2023
Copy link
Member

@MatkovIvan MatkovIvan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

That's not complete review, just a few comments

/**
* Composition local for [UITraitCollection]
*/
val LocalUITraitCollectionState = staticCompositionLocalOf<State<UITraitCollection>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't expose platform.UIKit.* to public compose API

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LocalUIViewController is already exposed 👉👈

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right... 🤔 and it cannot be internal because of usage from other module

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be annotated with @InternalComposeUiApi. But i found it useful because it is the only way of getting an updated value of it without костылей in Compose-only projects

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This local and uiviewcontroller local too will be useful for community library developers. Not hide it by internal please.
View controller was changed to public by my request to implement valid logic in moko-permissions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to expose just userInterfaceStyle instead of entire collection then?
@dima-avdeev-jb what do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also have an interface idiom property that can be useful. Not sure if It can update at runtime

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think - it is fine to have it as a public val LocalUITraitCollectionState.
Compose for iOS is still in alpha overall - and we can change this decision in the future.

But, maybe annotation @InternalComposeUiApi can also be helpfull. Library authors can also at it to their code.

Comment on lines 27 to 28
return LocalUITraitCollectionState.current.value
.userInterfaceStyle == UIUserInterfaceStyleDark
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added isSystemInDarkTheme support for iOS < 13

I fixed a crash on iOS 12 recently and wrote that comment you mentioned. So if we're speaking about current state of support - it's not crashing now 😅
EDIT: System dark mode was introduced in iOS 13, so the current state is fine here

actually i'm not sure if Compose works on iOS < 13

Yes, it does. UIUserInterfaceStyleDark exists since iOS 12, so it should be fine (I'm not totally sure that minimal iOS version is properly documented at the moment)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UIUserInterfaceStyleDark exists since iOS 12

It should be a check for iOS 12 here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually adding support for ios 12 wasn't valuable because dark mode was introduced in iOS 13 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be a check for iOS 12 here?

Compose won't work on iOS < 12 because of skia, so this check is not required

@dima-avdeev-jb
Copy link

Hello! Thanks!

But, first can you please sign the Google Contributor’s License Agreement at https://cla.developers.google.com/.
This is needed since we synchronise most of the code with Google’s AOSP repository. Signing this agreement allows us to synchronise code from your Pull Requests as well.

As a referece, you can look at screenshots in this PR: #699

And can you please post a screenshot of the signed agreement here as a comment?

@alexzhirkevich
Copy link
Author

Yep, i have already signed it
image
It doesn't show the date for some reason

@alexzhirkevich
Copy link
Author

Made 2nd PR with probably better api - #715 - without exposing UIKit and creating different actuals

@dima-avdeev-jb
Copy link

Thanks!

If second approach will works as a current PR on iOS side, - then I think it is better to close current PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants