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

feat(android): semantic colors and night mode #11301

Closed
wants to merge 1 commit into from

Conversation

drauggres
Copy link
Contributor

@drauggres drauggres commented Oct 29, 2019

  • generate color resources from semantic.colors.json
  • add Ti.UI.Android.nightModeStatus API
  • add Ti.UI.Android.MODE_NIGHT_* constants

JIRA: https://jira.appcelerator.org/browse/TIMOB-27501

Sample app:
ewanharris/darkmode-example#1

if (OS_ANDROID) {
	const mode = Ti.UI.Android.nightModeStatus;
	if (mode === Ti.UI.Android.MODE_NIGHT_YES) {
		Ti.UI.semanticColorType = Ti.UI.SEMANTIC_COLOR_TYPE_DARK;
	} else {
		Ti.UI.semanticColorType = Ti.UI.SEMANTIC_COLOR_TYPE_LIGHT;
	}
}

@build
Copy link
Contributor

build commented Oct 29, 2019

Messages
📖

💾 Here's the generated SDK zipfile.

📖 🎉 Another contribution from our awesome community member, drauggres! Thanks again for helping us make Titanium SDK better. 👍
📖 ✊ The commits in this PR match our conventions! Feel free to Rebase and Merge this PR when ready.
📖

✅ All tests are passing
Nice one! All 6554 tests are passing.
(There are 700 skipped tests not included in that total)

Generated by 🚫 dangerJS against b281e24

@drauggres drauggres force-pushed the TIMOB-27501 branch 3 times, most recently from 4ab4f4b to 8a52141 Compare October 29, 2019 14:44
@Kroll.constant
public static final int MODE_NIGHT_YES = Configuration.UI_MODE_NIGHT_YES;
@Kroll.constant
public static final int MODE_NIGHT_UNDEFINED = Configuration.UI_MODE_NIGHT_UNDEFINED;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you map nightModeStatus to the existing https://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI-property-semanticColorType property and it's Ti.UI.SEMANTIC_COLOR_TYPE_DARK + SEMANTIC_COLOR_TYPE_LIGHT type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those constants are used as values of Ti.UI.Android.nightModeStatus which is an Android analogue of Titanium.App.iOS.userInterfaceStyle.
I believe Titanium.App.iOS.userInterfaceStyle does not return SEMANTIC_COLOR_TYPE_DARK or SEMANTIC_COLOR_TYPE_LIGHT, does it (never checked, docs says it is String[]`)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It returns a Number (USER_INTERFACE_STYLE_UNSPECIFIED = 0, USER_INTERFACE_STYLE_LIGHT = 1, USER_INTERFACE_STYLE_DARK = 2). So if you change the docs, it should be all set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

USER_INTERFACE_STYLE_* constants are defined in Ti.App.iOS namespace.

@@ -3554,6 +3555,96 @@ AndroidBuilder.prototype.generateI18N = function generateI18N(next) {
next();
};

AndroidBuilder.prototype.generateSemanticColors = function generateSemanticColors(next) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this also allow the UI to "refresh" automatically? Otherwise I wonder whats the benefit over using the existing one. Thx!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method generates two resource-files with colors defined in them:

  • /res/values/semantic.colors.xml
  • /res/values-night/semantic.colors.xml

The goal is to be able to reuse these color in custom theme without defining them again.

Automatic "refresh" will require to restart activity (all of them), AFAIK we never do this in Titanium.

@jquick-axway
Copy link
Contributor

FYI: We're feature freezing Titanium 8.3.0. The plan is to release 8.3.0 in the very near future.

Our current focus is "gradle" support in Titanium 9.0.0 and we don't really want any more changes that will cause merge conflicts at the moment.

Also, I think it's important that we line-up the dark/light mode handling between Android and iOS as much as possible. That may mean moving our Ti.App.iOS APIs/constants to Ti.App. The Day/Night feature is a different animal and we may need to play around with the Theme.AppCompat.DayNight style, although I'm pretty sure this can only work by having the activity destroy/recreate itself like Sergey said.

@jquick-axway jquick-axway modified the milestones: 8.3.0, 9.0.0 Oct 29, 2019
@hansemannn
Copy link
Collaborator

@jquick-axway At least for the constants, I think it's a pretty lightweight change for parity. Right now, it's already on the parity namespace (Ti.UI.*) but hardcoded to light mode on Android. If it could actually get the "real" values on the getter, it would be a quick win. @ewanharris is also into the topic.

@m1ga
Copy link
Contributor

m1ga commented Jan 7, 2020

guess this won't make it into 9.0.0? Would be nice to have parity for the dark-mode that is already working on iOS

@hansemannn
Copy link
Collaborator

@m1ga It works well without these changes (we're not using it and have night mode support live in production).

@m1ga
Copy link
Contributor

m1ga commented Jan 7, 2020

@hansemannn interesting. For me Ti.UI.semanticColorType is always light so I only get the light colors in fetchSemanticColor.

@hansemannn
Copy link
Collaborator

Oh, we made an own module for that (to stay SDK independent). I'll send it to you tomorrow!

@drauggres drauggres force-pushed the TIMOB-27501 branch 2 times, most recently from 20e4b1d to 9500e22 Compare January 9, 2020 15:37
@drauggres
Copy link
Contributor Author

Conflicts resolved.
Branch rebased onto master.

One of the features provided by this PR is:

generate color resources from semantic.colors.json

So you will be able to use the same colors in custom theme.xml without defining them again.

- generate color resources from semantic.colors.json
- add Ti.UI.Android.nightModeStatus API
- add Ti.UI.Android.MODE_NIGHT_* constants

refs TIMOB-27501
@sgtcoolguy
Copy link
Contributor

Closed in favor of now-merged #11457

Thanks again @drauggres !

@sgtcoolguy sgtcoolguy closed this May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants