This commit is contained in:
@@ -38,6 +38,7 @@
|
|||||||
"expo-font",
|
"expo-font",
|
||||||
"expo-location",
|
"expo-location",
|
||||||
"expo-updates",
|
"expo-updates",
|
||||||
|
"./plugins/withRecentsLogo",
|
||||||
[
|
[
|
||||||
"expo-build-properties",
|
"expo-build-properties",
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
const { withMainActivity } = require("expo/config-plugins");
|
||||||
|
|
||||||
|
const IMPORTS = [
|
||||||
|
"android.graphics.Color",
|
||||||
|
"android.view.Gravity",
|
||||||
|
"android.view.ViewGroup",
|
||||||
|
"android.widget.FrameLayout",
|
||||||
|
"android.widget.ImageView",
|
||||||
|
];
|
||||||
|
|
||||||
|
const MEMBERS = `
|
||||||
|
// Affiche le logo à la place de l'écran dans la vue des apps ouvertes
|
||||||
|
private var recentsLogoOverlay: FrameLayout? = null
|
||||||
|
|
||||||
|
private fun showRecentsLogo() {
|
||||||
|
if (recentsLogoOverlay != null) return
|
||||||
|
val logoSize = (160 * resources.displayMetrics.density).toInt()
|
||||||
|
val overlay = FrameLayout(this).apply {
|
||||||
|
setBackgroundColor(Color.BLACK)
|
||||||
|
addView(
|
||||||
|
ImageView(this@MainActivity).apply { setImageResource(R.mipmap.ic_launcher) },
|
||||||
|
FrameLayout.LayoutParams(logoSize, logoSize, Gravity.CENTER)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
(window.decorView as ViewGroup).addView(
|
||||||
|
overlay,
|
||||||
|
ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
|
||||||
|
)
|
||||||
|
recentsLogoOverlay = overlay
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hideRecentsLogo() {
|
||||||
|
recentsLogoOverlay?.let { (it.parent as? ViewGroup)?.removeView(it) }
|
||||||
|
recentsLogoOverlay = null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onUserLeaveHint() {
|
||||||
|
super.onUserLeaveHint()
|
||||||
|
showRecentsLogo()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
showRecentsLogo()
|
||||||
|
super.onPause()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
hideRecentsLogo()
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
module.exports = (config) =>
|
||||||
|
withMainActivity(config, (cfg) => {
|
||||||
|
let src = cfg.modResults.contents;
|
||||||
|
if (cfg.modResults.language !== "kt") {
|
||||||
|
throw new Error("withRecentsLogo: MainActivity Kotlin attendue");
|
||||||
|
}
|
||||||
|
if (src.includes("recentsLogoOverlay")) return cfg;
|
||||||
|
|
||||||
|
const classDecl = /class MainActivity\s*:\s*ReactActivity\(\)\s*\{/;
|
||||||
|
if (!classDecl.test(src)) {
|
||||||
|
throw new Error("withRecentsLogo: déclaration MainActivity introuvable");
|
||||||
|
}
|
||||||
|
const missing = IMPORTS.filter((i) => !src.includes(`import ${i}\n`))
|
||||||
|
.map((i) => `import ${i}`)
|
||||||
|
.join("\n");
|
||||||
|
src = src.replace(/^(package .+\n)/m, `$1\n${missing}\n`);
|
||||||
|
src = src.replace(classDecl, (m) => `${m}${MEMBERS}`);
|
||||||
|
|
||||||
|
cfg.modResults.contents = src;
|
||||||
|
return cfg;
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user