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
feat: add support for dark mode images and semantic colors #11097
Conversation
|
iphone/Classes/TiUIiOSProxy.m
Outdated
if ([TiUtils isIOSVersionOrGreater:@"11.0"]) { | ||
return [[TiColor alloc] initWithColor:[UIColor colorNamed:color] name:nil]; | ||
} else { | ||
return [[TiColor alloc] initWithColor:UIColor.blackColor name:@"black"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this is undocumented, it's still callable by a user. So I kept the fallback to black like in the darkmode plugin/module by Hans.
} else { | ||
if (!colorset) { | ||
try { | ||
colorset = require('/semantic.colors.json'); // eslint-disable-line import/no-absolute-path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we load the JSON file like we do in the link below, then we won't run into a require()
error when running via Android Studio, Xcode, or Visual Studio. This way the native dev team here can debug via our IDEs without issue.
https://github.com/appcelerator/titanium_mobile/blob/master/common/Resources/ti.internal/bootstrap.loader.js#L31
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iOS works fine after 08a592f, I'm also able to build from Android Studio just fine after updating the ti.main.js
file in TitaniumTest to one from this PR. I believe as long as rollup is configured correctly it shouldn't be an issue
For color it is working perfect in iOS. I'll check for image |
@ewanharris While testing for images -
|
I think what @ewanharris is shooting for is that we should also have an "event" that gets fired when the OS' dark/light theme has changed. The theme event listener can then call the |
@jquick-axway Nope, images and colors are automatically changed by iOS if the appearance is changed - at least it does so natively. But I've added a |
I get that, but this PR's I can see in the |
So on iOS 13+, it returns a TiColor object (how do we even document that?), which will handle the dark mode setting change for a user. In every other situation, the user will get the string from the JSON object they gave us. I totally overlooked that the UI wont refresh on anything other than iOS 13, but I'm not sure how we'd even achieve that? @vijaysingh-axway For your point 2, are you thinking about a function that returns the correct image for a given dark mode setting? I think in theory that should just be prefixing |
Okay. That's fine. We just need to document this, because this is not the behavior I would have expected. Perhaps document that it returns an undocumented color I say this because Android and Windows do not have an equivalent. On those platforms, you set literal color values. (On Android, we could theoretically create our own custom |
Android Q supports dark mode as well (btw, it went to final beta today). Natively, it's managed by themes, on Titanium: Dunno. Maybe by listing to the change event and re-tint internally? I hope there is a better native way on Android. |
@ewanharris For color we have made it easy for developers, just add a resource file semantic-color.json and use it. It will work perfect for iOS < 12. Can we make a similar file for image resources, which have attribute for dark and light similar to colors. @ewanharris For my point 3 in previous comment, I was say a wiki page for explanation of how developer can implement dark mode in there project. |
@vijaysingh-axway I don't think an additional file for images is necessary. IMHO adhering to a specific naming pattern is easier than having an additional mapping file to maintain which only has the benefit of being able to configure the image names. I mean how likely is it that two different light mode images have the same dark mode image? |
Same here, we should go with naming conventions to eave the development process. For us, we have 130+ unique images and no issues with the images using the |
30e1cfd
to
a3738ec
Compare
@vijaysingh-axway, I agree with the others, I think promoting a convention like file naming is preferable to configuration via a json file, I do agree that it isn't as easy to transfer cross-platform as the json file though. |
a3738ec
to
1ee734c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
@vijaysingh-axway, on the docs I started drafting something this week which I'll aim to finish next week. I'll adapt to the repo a thttps://github.com/ewanharris/darkmode-example into something we can move to the appcelerator-developer-relations org and see about updating KitchenSink too |
1ee734c
to
546da4a
Compare
546da4a
to
c06408b
Compare
Implements part of TIMOB-27126
This adds a cross platfom method for loading semanitc colors, on iOS 11+ we will use the native Ti.UI.iOS.fetchSemanticColor to load the right color, in all other cases we use the Ti.UI.semanticColorType and the provided json file to obtain the correct value Fixes TIMOB-27126
Due to the way Ti.UI works on Android we cant reliably track the changes, by implementing the property with the get/set syntax we can track the property changes ourselves and reliably return the correct result
c06408b
to
aa739e5
Compare
FR Passed.SemanticColor is supported.fetches color and displayed based on dark mode/light mode selected on 13 device. images displayed correctly for dark and light mode. |
JIRA: https://jira.appcelerator.org/browse/TIMOB-27126
This introduces support for iOS 13's dark mode. There's two parts to the PR
-dark
suffix to a an image name (but before the retina@2x/@3x
).Ti.UI.semanticColorType
https://github.com/ewanharris/darkmode-example can be used as a test/example