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

Night mode status in Card #6567

Merged
merged 1 commit into from
Jun 29, 2020
Merged

Conversation

krmanik
Copy link
Member

@krmanik krmanik commented Jun 28, 2020

Pull Request template

Purpose / Description

While developing card we may need to know AnkiDroid night mode status so we can switch css class property according to night mode status.

Fixes

Fixes Link to the issues.

Approach

Return the value isInNightMode()

How Has This Been Tested?

Tested on emulator

  1. Add to front/back side of card
var isNightMode = AnkiDroidJS.ankiIsInNightMode();
console.log(isNightMode);

Learning (optional, can help others)

Checklist

Please, go through these checks before submitting the PR.

  • [ x ] You have not changed whitespace unnecessarily (it makes diffs hard to read)
  • [ x ] You have a descriptive commit message with a short title (first line, max 50 chars).
  • [ x ] Your code follows the style of the project (e.g. never omit braces in if statements)
  • [ x ] You have commented your code, particularly in hard-to-understand areas
  • [ x ] You have performed a self-review of your own code

@krmanik
Copy link
Member Author

krmanik commented Jun 28, 2020

nightmode

Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

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

LGTM @infinyte7

@mikehardy mikehardy added this to the 2.12 release milestone Jun 28, 2020
@mikehardy mikehardy added the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Jun 28, 2020
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

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

LGTM

@Arthur-Milchior
Copy link
Member

LGTM

I would have expected javascript to look whether the css class nightMode or night_mode is set in the card content. Because that is a property JS can easily access, that exists in anki (and I assume in IOS since I can't imagine DAE's adding something in anki and not in IOS)
But I've certainly got no objection here

@mikehardy
Copy link
Member

True - as I hit the approve button myself I also thought "can Javascript inspect the CSS classess? I think it can" which would make any consumers of this API more cross platform as we already have the CSS in sync between desktop and AnkiDroid, but likewise I have no problem with this, in general I think exposing any of the AbstractFlashcardViewer state to the WebView is fine, so javascript authors are on a level playing field with regard to constructing a viewing experience

@mikehardy mikehardy merged commit 0672067 into ankidroid:master Jun 29, 2020
@krmanik
Copy link
Member Author

krmanik commented Jun 29, 2020

I have found one solution that may not need this.
In style.css

.card {
  --text-color1: black;
}

.card.night_mode {
  --text-color1: white;
}

.title {
   color: var(--text-color1);
}

Now turning on night mode automatically change the text color. But in my anki deck xiehanzi, the stroke color, outline color should be updated in JavaScript. So following are steps for that.

.card {
--stroke-color: #555;
}

.card.night_mode {
--stroke-color: #fff;
}

.stroke {
   color: var(--stroke-color);
}

Now in JavaScript (Front/Back side of card)

 <!-- include this as empty -->

<div class = "stroke"></div>

<script>

var stroke_color = getComputedStyle(document.querySelector(".stroke")).color;

console.log(stroke_color);

</script>

Above may be work on AnkiDesktop and AnkiMobile also.

@krmanik krmanik deleted the night-mode-status branch June 29, 2020 17:05
@mikehardy mikehardy removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Jul 5, 2020
@krmanik krmanik restored the night-mode-status branch July 25, 2020 13:41
@krmanik krmanik deleted the night-mode-status branch July 25, 2020 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants