Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): layerType property for WebView #14172

Merged
merged 7 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.print.PrintDocumentAdapter;
import android.print.PrintManager;
import android.util.DisplayMetrics;
import android.view.View;
import android.webkit.ValueCallback;
import android.webkit.WebView;

Expand Down Expand Up @@ -76,6 +77,13 @@ public class WebViewProxy extends ViewProxy implements Handler.Callback, OnLifec
PrintManager printManager;
private Message postCreateMessage;

@Kroll.constant
public static final int LAYER_TYPE_NONE = View.LAYER_TYPE_NONE;
@Kroll.constant
public static final int LAYER_TYPE_SOFTWARE = View.LAYER_TYPE_SOFTWARE;
@Kroll.constant
public static final int LAYER_TYPE_HARDWARE = View.LAYER_TYPE_HARDWARE;

public WebViewProxy()
{
super();
Expand Down Expand Up @@ -244,6 +252,25 @@ public HashMap getRequestHeaders()
return new HashMap<String, String>();
}

@Kroll.setProperty
public void setLayerType(int value)
{
TiUIWebView currWebView = getWebView();
if (currWebView != null) {
currWebView.setLayerType(value);
}
}

@Kroll.getProperty
public int getLayerType()
{
TiUIWebView currWebView = getWebView();
if (currWebView != null) {
return currWebView.layerType;
}
return 0;
}

@Kroll.setProperty
public void setRequestHeaders(HashMap params)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public class TiUIWebView extends TiUIView
@Kroll.constant
public static final int PDF_PAGE_AUTO = 5;

public int layerType = WebViewProxy.LAYER_TYPE_NONE;

private static enum reloadTypes { DEFAULT, DATA, HTML, URL }

private reloadTypes reloadMethod = reloadTypes.DEFAULT;
Expand Down Expand Up @@ -466,6 +468,10 @@ public void processProperties(KrollDict d)
webView.setHorizontalScrollBarEnabled(scrollbarValue == AndroidModule.WEBVIEW_SCROLLBARS_DEFAULT
|| scrollbarValue == AndroidModule.WEBVIEW_SCROLLBARS_HIDE_VERTICAL);
}

if (d.containsKeyAndNotNull(TiC.PROPERTY_LAYER_TYPE)) {
setLayerType(TiConvert.toInt(d, TiC.PROPERTY_LAYER_TYPE));
}
}

@Override
Expand Down Expand Up @@ -1070,4 +1076,14 @@ protected void disableHWAcceleration()
{
Log.d(TAG, "Do not disable HW acceleration for WebView.", Log.DEBUG_MODE);
}

public void setLayerType(int value)
{
WebView webView = getWebView();
if (webView != null) {
layerType = value;
webView.setLayerType(value, null);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ public class TiC
public static final String PROPERTY_DEPARTMENT = "department";
public static final String PROPERTY_FIXED_SIZE = "fixedSize";
public static final String PROPERTY_UI_FLAGS = "uiFlags";
public static final String PROPERTY_LAYER_TYPE = "layerType";

public static final String SIZE_AUTO = "auto";
public static final String URL_APP_PREFIX = "app://";
Expand Down
32 changes: 32 additions & 0 deletions apidoc/Titanium/UI/WebView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,17 @@ properties:
platforms: [iphone, ipad, macos]
since: {iphone: "2.0.0", ipad: "2.0.0", macos: "9.2.0"}

- name: layerType
summary: A value indicating the render mode of the WebView
description: |
Set to Ti.UI.WebView.LAYER_TYPE_SOFTWARE (software rendering) if you use `Ti.Media.takeScreenshot()` or `toImage()` and the WebView contains local HTML files.
Otherwise the WebView might be empty in the screenshot/image. If you change the setting you will have to assing the HTML content again.
type: Number
constants: Titanium.UI.WebView.LAYER_TYPE_*
default: <Titanium.UI.WebView.LAYER_TYPE_NONE>
platforms: [android]
since: {android: "12.7.0"}

- name: enableZoomControls
summary: If `true`, zoom controls are enabled.
type: Boolean
Expand Down Expand Up @@ -1196,6 +1207,27 @@ properties:
since: {iphone: "8.0.0", ipad: "8.0.0", macos: "9.2.0"}
permission: read-only

- name: LAYER_TYPE_NONE
summary: Default rendering mode
type: Number
platforms: [android]
permission: read-only
since: "12.7.0"

- name: LAYER_TYPE_SOFTWARE
summary: Software rendering mode
type: Number
platforms: [android]
permission: read-only
since: "12.7.0"

- name: LAYER_TYPE_HARDWARE
summary: Hardware rendering mode
type: Number
platforms: [android]
permission: read-only
since: "12.7.0"

- name: PDF_PAGE_DIN_A5
summary: PDF paper size
type: Number
Expand Down
Loading