From 4f5f40c27f572d219853126bbae8a4b0f52c83b6 Mon Sep 17 00:00:00 2001 From: dagmawig Date: Fri, 9 Feb 2024 13:39:14 -0600 Subject: [PATCH 1/2] feat: add postMessage method to send message to react native webview --- src/components/App.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/components/App.js b/src/components/App.js index 86948b36..bc214c8c 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -72,10 +72,7 @@ function MapComponent() { async function handleClickTree(tree) { log.warn('click tree:', tree); - if (window.parent) { - log.warn('DEMO:ok message parent'); - window.parent.postMessage(JSON.stringify(tree), '*'); - } + window.ReactNativeWebView?.postMessage(JSON.stringify(tree)); const wholeTree = await getTreeById(tree.id).catch((err) => log.warn(err)); const result = pathResolver.getPathWhenClickTree( From 85af407433c31a7f7917240a23d908e2d7b9ee41 Mon Sep 17 00:00:00 2001 From: dadiorchen Date: Sun, 11 Feb 2024 09:37:04 +0800 Subject: [PATCH 2/2] chore: some log --- src/components/App.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/App.js b/src/components/App.js index bc214c8c..b8317a08 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -72,7 +72,14 @@ function MapComponent() { async function handleClickTree(tree) { log.warn('click tree:', tree); - window.ReactNativeWebView?.postMessage(JSON.stringify(tree)); + if (window.ReactNativeWebView) { + log.debug('react native'); + window.ReactNativeWebView?.postMessage(JSON.stringify(tree)); + } + if (window.parent) { + log.debug('window.parent'); + window.parent.postMessage(JSON.stringify(tree), '*'); + } const wholeTree = await getTreeById(tree.id).catch((err) => log.warn(err)); const result = pathResolver.getPathWhenClickTree(