How does the Gmail app for Android do the magic of webview-header-overlay overlay for viewing mail?

Using hierarchyviewer in a Gmail conversation view shows an interesting and unusual layout hierarchy:

  • All messages in one session are displayed in one WebView (in particular, com.google.android.gm.CustomWebView , see left). Only the message body is displayed - the spaces in which the headers are placed remain empty .
  • At the top of the WebView is superimposed com.google.android.gm.MessageHeaderScrollView (see right), which uses the HybridConversationScrollContainer to place a MessageHeaderView in the correct position for each message in the conversation view.

CustomwebviewMessageHeaderScrollView

So how (and why) is this achieved? Is this something that an Android developer could and should strive to recreate in its applications?

Obviously, the likely cause is performance. WebView uses WebKit's own fast visualization of the message body, and one WebView is probably more efficient than a separate WebView for each message. If anyone saw a good blog post about the performance benefits of this, I would be interested.

However, there is obvious difficulty for this approach (against the naive use of an ExpandableListView with some text elements inside it or something else) - the HybridConversationScrollContainer must somehow figure out where the message headers should go through the web rendering in order to correctly position its MessageHeaderViews . I would like to know how this works:

+3
source share
1 answer

By the way, the only approach I can think of is based on javascript - use javascript in WebView to collect the coordinates of the header, and then use WebView.addJavascriptInterface() to transfer these coordinates to Java and HybridConversationScrollContainer . I have not tried to do this myself, although I am not sure if this can really work.

The Android Developers Blog has a short post on the addJavascriptInterface() method:

http://android-developers.blogspot.com/2008/09/using-webviews.html

It would be great if MessageHeaderScrollView could be released as an open source library - I would use it! - but, seeing that the Gmail application is closed, it seems that this is hardly possible.

+1
source

Source: https://habr.com/ru/post/979577/


All Articles