Skip to content

Commit

Permalink
Merge pull request #247 from humhub/f-internal-45-long-press-copy
Browse files Browse the repository at this point in the history
Possibility to select and copy links with a long press
  • Loading branch information
luke- authored Oct 14, 2024
2 parents 9d5fda6 + b9d5e43 commit 7bf9257
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
1 change: 1 addition & 0 deletions lib/flavored/web_view.f.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class FlavoredWebViewState extends ConsumerState<WebViewF> {
onReceivedError: _onLoadError,
onProgressChanged: _onProgressChanged,
onDownloadStartRequest: _onDownloadStartRequest,
onLongPressHitTestResult: WebViewGlobalController.onLongPressHitTestResult,
),
),
),
Expand Down
40 changes: 21 additions & 19 deletions lib/pages/web_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,27 @@ class WebViewAppState extends ConsumerState<WebView> {
key: _scaffoldKey,
backgroundColor: HexColor(_manifest.themeColor),
body: SafeArea(
bottom: false,
// ignore: deprecated_member_use
child: WillPopScope(
onWillPop: () => exitApp(context, ref),
child: InAppWebView(
initialUrlRequest: _initialRequest,
initialSettings: WebViewGlobalController.settings,
pullToRefreshController: _pullToRefreshController,
shouldOverrideUrlLoading: _shouldOverrideUrlLoading,
onWebViewCreated: _onWebViewCreated,
shouldInterceptFetchRequest: _shouldInterceptFetchRequest,
onCreateWindow: _onCreateWindow,
onLoadStop: _onLoadStop,
onLoadStart: _onLoadStart,
onProgressChanged: _onProgressChanged,
onReceivedError: _onReceivedError,
onDownloadStartRequest: _onDownloadStartRequest,
),
)),
bottom: false,
// ignore: deprecated_member_use
child: WillPopScope(
onWillPop: () => exitApp(context, ref),
child: InAppWebView(
initialUrlRequest: _initialRequest,
initialSettings: WebViewGlobalController.settings,
pullToRefreshController: _pullToRefreshController,
shouldOverrideUrlLoading: _shouldOverrideUrlLoading,
onWebViewCreated: _onWebViewCreated,
shouldInterceptFetchRequest: _shouldInterceptFetchRequest,
onCreateWindow: _onCreateWindow,
onLoadStop: _onLoadStop,
onLoadStart: _onLoadStart,
onProgressChanged: _onProgressChanged,
onReceivedError: _onReceivedError,
onDownloadStartRequest: _onDownloadStartRequest,
onLongPressHitTestResult: WebViewGlobalController.onLongPressHitTestResult,
),
),
),
);
}

Expand Down
11 changes: 11 additions & 0 deletions lib/util/web_view_global_controller.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:humhub/models/manifest.dart';

Expand Down Expand Up @@ -50,6 +51,16 @@ class WebViewGlobalController {
value?.evaluateJavascript(source: jsCode);
}

static void onLongPressHitTestResult(InAppWebViewController controller, InAppWebViewHitTestResult hitResult) async {
if (hitResult.extra != null &&
([InAppWebViewHitTestResultType.SRC_ANCHOR_TYPE, InAppWebViewHitTestResultType.EMAIL_TYPE]
.contains(hitResult.type))) {
Clipboard.setData(
ClipboardData(text: hitResult.extra!),
);
}
}

static InAppWebViewSettings get settings => InAppWebViewSettings(
useShouldOverrideUrlLoading: true,
useShouldInterceptFetchRequest: true,
Expand Down

0 comments on commit 7bf9257

Please sign in to comment.