daohoangson / flutter_widget_from_html

Flutter package to render html as widgets that supports hyperlink, image, audio, video, iframe and many other tags.
https://pub.dev/packages/flutter_widget_from_html
MIT License
635 stars 235 forks source link

Improve `WebView` auto resize logic #1139

Closed daohoangson closed 5 months ago

daohoangson commented 9 months ago

We are using timers to perform size evaluations and resize the web view. For slow web pages, it is not reliable / slow to react. It would be better if we can use JavaScript channel and listen to the window resize event.

Should wait for #1138 to stabilize the test executions before attempting this.

See:

DFelten commented 9 months ago

We already use something like this in our controller. Maybe that will help.

static const String _javaScriptChannel = 'ContentHeight';

static const String _sizeReportingJavaScript = '''
const resizeObserver = new ResizeObserver(entries => 
  $_javaScriptChannel.postMessage(entries[0].target.scrollHeight)
)

resizeObserver.observe(document.documentElement)
''';
controller.addJavaScriptChannel(
  _javaScriptChannel,
  onMessageReceived: _setContentHeight,
);
daohoangson commented 9 months ago

Thank you for the suggestion, @DFelten. I think the implementation will look very similar to that.

daohoangson commented 4 months ago

Just FYI, the latest version (v0.15.1) has been released with the new auto resize logic.