From ac91df03322b1a67a4b7b26a151ad6387af20b19 Mon Sep 17 00:00:00 2001 From: aidewoode Date: Wed, 20 Mar 2024 13:04:02 +0800 Subject: [PATCH] Add android native bridge to update theme on android app --- app/javascript/helper.js | 7 ++++++- app/javascript/native_bridge.js | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/javascript/helper.js b/app/javascript/helper.js index 0cc8c54a..8ece2577 100644 --- a/app/javascript/helper.js +++ b/app/javascript/helper.js @@ -37,8 +37,12 @@ function isiOSApp () { return !!(window.webkit && window.webkit.messageHandlers) } +function isAndroidApp () { + return !!(window.NativeBridge) +} + function isNativeApp () { - return isiOSApp() + return isiOSApp() || isAndroidApp() } export { @@ -47,5 +51,6 @@ export { fetchRequest, dispatchEvent, isiOSApp, + isAndroidApp, isNativeApp } diff --git a/app/javascript/native_bridge.js b/app/javascript/native_bridge.js index e35787d6..5bce0d83 100644 --- a/app/javascript/native_bridge.js +++ b/app/javascript/native_bridge.js @@ -1,4 +1,4 @@ -import { isiOSApp } from './helper' +import { isAndroidApp, isiOSApp } from './helper' class NativeBridge { playAll (resourceType, resourceId) { @@ -49,6 +49,10 @@ class NativeBridge { theme }) } + + if (isAndroidApp()) { + window.NativeBridge.updateTheme(theme) + } } showFlashMessage (message) {