This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/app/initializers/webview-background.js
2020-12-01 15:31:26 -03:00

27 lines
748 B
JavaScript

import { isAppWebview, postRNWebviewMessage } from "discourse/lib/utilities";
import { later } from "@ember/runloop";
// Send bg color to webview so iOS status bar matches site theme
export default {
name: "webview-background",
after: "inject-objects",
initialize() {
if (isAppWebview()) {
window
.matchMedia("(prefers-color-scheme: dark)")
.addListener(this.updateAppBackground);
this.updateAppBackground();
}
},
updateAppBackground() {
later(() => {
const header = document.querySelector(".d-header-wrap .d-header");
if (header) {
const styles = window.getComputedStyle(header);
postRNWebviewMessage("headerBg", styles.backgroundColor);
}
}, 500);
},
};