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): softwareRendering property for WebView #14172

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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 @@ -244,6 +244,25 @@ public HashMap getRequestHeaders()
return new HashMap<String, String>();
}

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

@Kroll.getProperty
public boolean getSoftwareMode()
{
TiUIWebView currWebView = getWebView();
if (currWebView != null) {
return currWebView.softwareMode;
}
return false;
}

@Kroll.setProperty
public void setRequestHeaders(HashMap params)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public class TiUIWebView extends TiUIView
private float zoomLevel = TiApplication.getInstance().getResources().getDisplayMetrics().density;
private float initScale = zoomLevel;

public boolean softwareMode = false;

public static final int PLUGIN_STATE_OFF = 0;
public static final int PLUGIN_STATE_ON = 1;
public static final int PLUGIN_STATE_ON_DEMAND = 2;
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_SOFTWARE_MODE)) {
setSoftwareMode(TiConvert.toBoolean(d, TiC.PROPERTY_SOFTWARE_MODE));
}
}

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

public void setSoftwareMode(Boolean value)
{
WebView webView = getWebView();
if (webView != null) {
softwareMode = value;
if (value) {
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
} else {
webView.setLayerType(View.LAYER_TYPE_HARDWARE, 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_SOFTWARE_MODE = "softwareMode";

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

- name: softwareMode
summary: A Boolean value indicating the render mode of the WebView
description: |
Set to `true` (software rendering) if you use `Ti.Media.takeScreensho()` 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: Boolean
default: false
platforms: [android]
since: {android: "12.7.0"}

- name: enableZoomControls
summary: If `true`, zoom controls are enabled.
type: Boolean
Expand Down
Loading