Skip to content

Android: no text selection possible with useHybridComposition and long webview #722

Description

@robert-virkus

Environment

Technology Version
Flutter version 2.0.2
Plugin version 5.1.0+4
Android version • android-arm64 • Android 9 (API 28) / • Android 11 (API 30) (emulator)
iOS version n/a
Xcode version n/a

Device information:
• BlackView/A80Pro (mobile) A80DK017EEA0070119
• Pixel 2 (emulator) sdk gphone x86 (mobile)

Description

When I enable the hybrid mode with AndroidInAppWebViewOptions( useHybridComposition: true ), then I cannot select text when setting the webview's height at the same time.

In a simple reproduction project I can reduce the height to a seemingly device specific value and then I can select text again. In a more complex setup I was not able to get selection to work by reducing the height, so the height might not be the deciding factor.

Expected behavior:
Text selection via the long press gesture should still be possible.

Current behavior:
Text selection does not work in InAppWebView from a certain height onward.

Steps to reproduce

  1. Put the InAppWebView in a SizedBox and let it load a long webpage.
  2. After loading measure the height (I'm using document.body.scrollHeight as this seems to work better than getContentHeight()) and apply the measured height in the SizedBox
  3. Try to select some text

Sample code (without null-safety):

double webviewHeight;
  @override
  Widget build(BuildContext context) {
     return Scaffold(
      appBar: AppBar(
        title: Text('Select Text'),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [
            Text('header'),
            SizedBox(
              height: webviewHeight ?? MediaQuery.of(context).size.height,
              child: InAppWebView(
                initialUrlRequest: URLRequest(url: Uri.parse(url)),
                initialOptions: InAppWebViewGroupOptions(
                  crossPlatform: InAppWebViewOptions(
                    useShouldOverrideUrlLoading: true,
                    verticalScrollBarEnabled: false,
                  ),
                  android: AndroidInAppWebViewOptions(
                    useWideViewPort: false,
                    loadWithOverviewMode: true,
                    useHybridComposition: true,
                  ),
                ),
                
                onLoadStop: (controller, url) async {
                  int scrollHeight = await controller.evaluateJavascript(
                      source: 'document.body.scrollHeight');
                  if (scrollHeight != null) {
                    setState(() {
                      webviewHeight = scrollHeight + 30.0;
                    });
                  }
                },
              ),
            ),
          ],
        ),
      ),
    );
  }

Possibly related to #704

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions