object:setNativeProperty()

Type Function
Object NativeDisplayObject
Library native.*
Return value none
Revision Release 2022.3683
Keywords native object, property accessors
See also object:getNativeProperty()

Overview

This function allows you to set properties of the underlying native object created by the native library. For example, if you create a WebView on iOS, you can set the Obj-C properties of the corresponding WKWebView or WKWebViewConfiguration if called before a request is made. Similarly on Android it can set properties of WebView or WebSettings

Syntax

object:setNativeProperty( property, value )
property (required)

String. The string name for the native property.

value (required)

The value to set the property to. Must be a Lua value compatible with Obj-C or Java. The following Lua values are converted to the corresponding values in Obj-C: boolean, string, array, table, and number. Java supported types are boolean, string and number.

Android also supports special pair of values for WebView: property "http.agent" and value "system" to set WebView user agent to system default.

Example

local webView = native.newWebView( 0, 0, display.contentWidth, display.contentHeight )
if system.getInfo("platform") == "android" then
    webView:setNativeProperty("http.agent", "system")
    webView:setNativeProperty("setBuiltInZoomControls", false)
else
    webView:setNativeProperty( "allowsInlineMediaPlayback", true )
end
webView:request( "https://www.solar2d.com" )