Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #60 from MXCzkEVM/android_clipboard_fix
Browse files Browse the repository at this point in the history
fix: Handled clipboard bug in special cases
  • Loading branch information
reasje authored Sep 19, 2023
2 parents eea464d + ad1fce2 commit 43799bb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
12 changes: 6 additions & 6 deletions lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class OpenAppPage extends HookConsumerWidget {
initialUrlRequest: URLRequest(
url: Uri.parse(url),
),
onLoadStop: (controller, url) {
presenter.injectCopyHandling();
},
onLoadError: (controller, url, code, message) =>
collectLog('onLoadError: $code: $message'),
onLoadHttpError: (controller, url, statusCode, description) =>
Expand Down Expand Up @@ -101,12 +104,10 @@ class OpenAppPage extends HookConsumerWidget {
break;
}
},

initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
useShouldOverrideUrlLoading: true,
mediaPlaybackRequiresUserGesture: false
),
useShouldOverrideUrlLoading: true,
mediaPlaybackRequiresUserGesture: false),
android: AndroidInAppWebViewOptions(
useWideViewPort: true,
geolocationEnabled: true,
Expand All @@ -128,8 +129,7 @@ class OpenAppPage extends HookConsumerWidget {
action: PermissionRequestResponseAction.GRANT,
);
},
androidOnGeolocationPermissionsHidePrompt: (controller) {
},
androidOnGeolocationPermissionsHidePrompt: (controller) {},
androidOnGeolocationPermissionsShowPrompt:
(InAppWebViewController controller, String origin) async {
return GeolocationPermissionShowPromptResponse(
Expand Down
25 changes: 23 additions & 2 deletions lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ class OpenDAppPresenter extends CompletePresenter<OpenDAppState> {
return super.dispose();
}

void onWebViewCreated(InAppWebViewController controller) =>
notify(() => state.webviewController = controller);
void onWebViewCreated(InAppWebViewController controller) {
notify(() => state.webviewController = controller);
}

Future<EstimatedGasFee?> _estimatedFee(
String from,
Expand Down Expand Up @@ -219,4 +220,24 @@ class OpenDAppPresenter extends CompletePresenter<OpenDAppState> {
}
}""";
}

void copy(List<dynamic> params) {
Clipboard.setData(ClipboardData(text: params[0]));
}

Future<String> paste(List<dynamic> params) async {
return (await Clipboard.getData('text/plain'))?.text.toString() ?? '';
}

void injectCopyHandling() {
state.webviewController!.evaluateJavascript(
source:
'javascript:navigator.clipboard.writeText = (msg) => { return window.flutter_inappwebview?.callHandler("axs-wallet-copy-clipboard", msg); }');
state.webviewController!.addJavaScriptHandler(
handlerName: 'axs-wallet-copy-clipboard',
callback: (args) {
copy(args);
},
);
}
}

0 comments on commit 43799bb

Please sign in to comment.