From 9c41cbf4104c0805163826df626509d77c8deb93 Mon Sep 17 00:00:00 2001 From: JunsuChoi Date: Tue, 18 Jun 2024 15:07:51 +0900 Subject: [PATCH 1/3] [webview_flutter_lwe] Supports multiple JavaScriptChannel method call Previously, javascript channel methods that are called before the webview is created are stored in the pending list.(based on name) Because of that, there was a problem with channels being missing when adding multiple channels. When the javascript channel method is called, it is stored differently depending on the name to prevent it from being missed. ```dart controller ..addJavaScriptChannel( 'method1',...) ..addJavaScriptChannel( 'method2',...); ``` --- packages/webview_flutter_lwe/CHANGELOG.md | 3 ++- packages/webview_flutter_lwe/README.md | 2 +- .../lib/src/lwe_webview.dart | 20 +++++++++++++++++-- packages/webview_flutter_lwe/pubspec.yaml | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/webview_flutter_lwe/CHANGELOG.md b/packages/webview_flutter_lwe/CHANGELOG.md index cd3a118f0..14b6648ee 100644 --- a/packages/webview_flutter_lwe/CHANGELOG.md +++ b/packages/webview_flutter_lwe/CHANGELOG.md @@ -1,7 +1,8 @@ -## NEXT +## 0.3.1 * Fix new lint warnings. * Update minimum Flutter and Dart version to 3.13 and 3.1. +* Supports multiple JavaScriptChannel method call. ## 0.3.0 diff --git a/packages/webview_flutter_lwe/README.md b/packages/webview_flutter_lwe/README.md index bea45df01..68d58b894 100644 --- a/packages/webview_flutter_lwe/README.md +++ b/packages/webview_flutter_lwe/README.md @@ -21,7 +21,7 @@ This package is not an _endorsed_ implementation of `webview_flutter`. Therefore ```yaml dependencies: webview_flutter: ^4.4.2 - webview_flutter_lwe: ^0.3.0 + webview_flutter_lwe: ^0.3.1 ``` ## Example diff --git a/packages/webview_flutter_lwe/lib/src/lwe_webview.dart b/packages/webview_flutter_lwe/lib/src/lwe_webview.dart index 7241fa8b5..f45659849 100644 --- a/packages/webview_flutter_lwe/lib/src/lwe_webview.dart +++ b/packages/webview_flutter_lwe/lib/src/lwe_webview.dart @@ -48,7 +48,13 @@ class LweWebView { Future _invokeChannelMethod(String method, [dynamic arguments]) async { if (!_isCreated) { - _pendingMethodCalls[method] = arguments; + if (method == 'addJavaScriptChannel' || + method == 'runJavaScript' || + method == 'runJavaScriptReturningResult') { + _pendingMethodCalls['${method}_$arguments'] = arguments; + } else { + _pendingMethodCalls[method] = arguments; + } return null; } @@ -73,7 +79,17 @@ class LweWebView { } _pendingMethodCalls.forEach((String method, dynamic arguments) { - _lweWebViewChannel.invokeMethod(method, arguments); + if (method.contains('addJavaScriptChannel_')) { + _lweWebViewChannel.invokeMethod( + 'addJavaScriptChannel', arguments); + } else if (method.contains('runJavaScript_')) { + _lweWebViewChannel.invokeMethod('runJavaScript', arguments); + } else if (method.contains('runJavaScriptReturningResult_')) { + _lweWebViewChannel.invokeMethod( + 'runJavaScriptReturningResult', arguments); + } else { + _lweWebViewChannel.invokeMethod(method, arguments); + } }); _pendingMethodCalls.clear(); } diff --git a/packages/webview_flutter_lwe/pubspec.yaml b/packages/webview_flutter_lwe/pubspec.yaml index 61e7470cb..96464d249 100644 --- a/packages/webview_flutter_lwe/pubspec.yaml +++ b/packages/webview_flutter_lwe/pubspec.yaml @@ -2,7 +2,7 @@ name: webview_flutter_lwe description: Tizen implementation of the webview_flutter plugin backed by Lightweight Web Engine. homepage: https://github.com/flutter-tizen/plugins repository: https://github.com/flutter-tizen/plugins/tree/master/packages/webview_flutter_lwe -version: 0.3.0 +version: 0.3.1 environment: sdk: ">=3.1.0 <4.0.0" From e9b3c9638365f24e5103884d8e68416f22395a8c Mon Sep 17 00:00:00 2001 From: JunsuChoi Date: Wed, 19 Jun 2024 18:07:15 +0900 Subject: [PATCH 2/3] Keep key value in pending method map --- .../lib/src/lwe_webview.dart | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/packages/webview_flutter_lwe/lib/src/lwe_webview.dart b/packages/webview_flutter_lwe/lib/src/lwe_webview.dart index f45659849..c8c694ed7 100644 --- a/packages/webview_flutter_lwe/lib/src/lwe_webview.dart +++ b/packages/webview_flutter_lwe/lib/src/lwe_webview.dart @@ -51,7 +51,14 @@ class LweWebView { if (method == 'addJavaScriptChannel' || method == 'runJavaScript' || method == 'runJavaScriptReturningResult') { - _pendingMethodCalls['${method}_$arguments'] = arguments; + if (_pendingMethodCalls[method] == null) { + _pendingMethodCalls[method] = []; + } + final List argumentsList = + _pendingMethodCalls[method] as List; + if (!argumentsList.contains('$arguments')) { + argumentsList.add('$arguments'); + } } else { _pendingMethodCalls[method] = arguments; } @@ -79,14 +86,18 @@ class LweWebView { } _pendingMethodCalls.forEach((String method, dynamic arguments) { - if (method.contains('addJavaScriptChannel_')) { - _lweWebViewChannel.invokeMethod( - 'addJavaScriptChannel', arguments); - } else if (method.contains('runJavaScript_')) { - _lweWebViewChannel.invokeMethod('runJavaScript', arguments); - } else if (method.contains('runJavaScriptReturningResult_')) { - _lweWebViewChannel.invokeMethod( - 'runJavaScriptReturningResult', arguments); + if (method == 'addJavaScriptChannel' || + method == 'runJavaScript' || + method == 'runJavaScriptReturningResult') { + if (_pendingMethodCalls[method] != null) { + final List argumentsList = + _pendingMethodCalls[method] as List; + for (final String javaScriptMethodArguments in argumentsList) { + _lweWebViewChannel.invokeMethod( + method, javaScriptMethodArguments); + } + argumentsList.clear(); + } } else { _lweWebViewChannel.invokeMethod(method, arguments); } From c955e83d80d39dbfb4b566b86008656795869b40 Mon Sep 17 00:00:00 2001 From: JunsuChoi Date: Thu, 20 Jun 2024 16:26:00 +0900 Subject: [PATCH 3/3] Apply review comment --- .../lib/src/lwe_webview.dart | 41 ++++--------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/packages/webview_flutter_lwe/lib/src/lwe_webview.dart b/packages/webview_flutter_lwe/lib/src/lwe_webview.dart index c8c694ed7..fe3747a00 100644 --- a/packages/webview_flutter_lwe/lib/src/lwe_webview.dart +++ b/packages/webview_flutter_lwe/lib/src/lwe_webview.dart @@ -24,7 +24,7 @@ class LweWebView { final Map _javaScriptChannelParams = {}; - final Map _pendingMethodCalls = {}; + final List<(String, dynamic)> _pendingMethodCalls = <(String, dynamic)>[]; Future _onMethodCall(MethodCall call) async { switch (call.method) { @@ -48,20 +48,7 @@ class LweWebView { Future _invokeChannelMethod(String method, [dynamic arguments]) async { if (!_isCreated) { - if (method == 'addJavaScriptChannel' || - method == 'runJavaScript' || - method == 'runJavaScriptReturningResult') { - if (_pendingMethodCalls[method] == null) { - _pendingMethodCalls[method] = []; - } - final List argumentsList = - _pendingMethodCalls[method] as List; - if (!argumentsList.contains('$arguments')) { - argumentsList.add('$arguments'); - } - } else { - _pendingMethodCalls[method] = arguments; - } + _pendingMethodCalls.add((method, arguments)); return null; } @@ -79,29 +66,15 @@ class LweWebView { } /// Applies the requested settings before [TizenView] is created. - void _callPendingMethodCalls() { + Future _callPendingMethodCalls() async { if (hasNavigationDelegate) { - _invokeChannelMethod( + await _invokeChannelMethod( 'hasNavigationDelegate', hasNavigationDelegate); } - _pendingMethodCalls.forEach((String method, dynamic arguments) { - if (method == 'addJavaScriptChannel' || - method == 'runJavaScript' || - method == 'runJavaScriptReturningResult') { - if (_pendingMethodCalls[method] != null) { - final List argumentsList = - _pendingMethodCalls[method] as List; - for (final String javaScriptMethodArguments in argumentsList) { - _lweWebViewChannel.invokeMethod( - method, javaScriptMethodArguments); - } - argumentsList.clear(); - } - } else { - _lweWebViewChannel.invokeMethod(method, arguments); - } - }); + for (final (String method, dynamic arguments) in _pendingMethodCalls) { + await _lweWebViewChannel.invokeMethod(method, arguments); + } _pendingMethodCalls.clear(); }