NativeClass represents a platform-native class. More...
Import Statement: | import Felgo 4.0 |
Since: | Felgo 3.3.0 |
Inherits: |
A NativeClass object is a specialization of NativeObject that always represents a native class object.
On Android, the native object is an instance of java.lang.Class
. On iOS, it is an instance of Class
.
This type adds additional methods that only make sense on Class objects. You can call static methods and get and set static properties of the underlying class. You can also create new instances of the class.
You can obtain a reference to any NativeClass with NativeObjectUtils::getClass(). You can obtain a reference to a NativeObject's class with NativeObject::getClass().
var callStaticMethod(string methodName, var parameters, enumeration threadType, function resultHandler) |
Calls the static method methodName
on the native class represented by this item.
On Android, it considers all overloads of this method. It converts the supplied parameters according to Data Type Conversions between QML and Native Code. If any overload fits the converted parameters, it calls that overload.
On iOS, the methodName
is the full selector of the method you want to call, including the colons. Example: "addTarget:action:forControlEvents:"
for UIButton
actions.
You can supply parameters to the method call with the optional parameter parameters
. It can be either a single parameter object or a JavaScript array of parameters.
You can specify which thread to call the method on with the optional parameter threadType
. Use one of these enumeration values with it:
NativeObject.CurrentThread
- Calls the method directly on the QML thread.NativeObject.UiThread
- Calls the method in the platform's native UI thread.
Note: When calling methods of View objects, this thread type should usually be preferred.
Note: On iOS, QML applications run directly on the UI thread. This means CurrentThread
and UiThread
will result in the same behavior.
NativeObject.BackgroundThread
- Calls the method asynchronously in a background thread.You can use the optional parameter resultHandler
to obtain the method return value asynchronously.
You can supply a JavaScript function for resultHandler
. callMethod()
then immediately returns an undefined value. It then calls the resultHandler
function after the method call has
finished. It supplies the method return value as the first parameter to the function.
You can also omit resultHandler
. In this case, callMethod()
returns the method return value directly. If the call is executed on another thread, this means the QML thread will be blocked during
that time.
See also NativeObject::callMethod().
Get the static property propertyName
from the native class represented by this item.
On Android, this reads a static field in the native class. If no field with this name exists or the field is not public, it logs a warning message and returns an undefined value.
On iOS, this reads a static Objective C property in the native class. If no property with this name exists, it logs a warning message and returns an undefined value.
See also setStaticProperty() and NativeObject::getProperty().
NativeObject newInstance(var parameters, string constructorName, enumeration threadType, function resultHandler) |
Creates and returns a new instance of the underlying native class.
You can supply parameters to the constructor call with the optional parameter parameters
. It can be either a single parameter object or a JavaScript array of parameters.
On iOS, Objective C constructors are regular methods. They are usually called initWith...
Use the optional parameter constructorName
to specify which constructor to call on iOS. This parameter is
unused on Android.
You can specify which thread to call the constructor on with the optional parameter threadType
. Use one of these enumeration values with it:
NativeObject.CurrentThread
- Calls the method directly on the QML thread.NativeObject.UiThread
- Calls the method in the platform's native UI thread.
Note: When calling methods of View objects, this thread type should usually be preferred.
Note: On iOS, QML applications run directly on the UI thread. This means, CurrentThread
and UiThread
will result in the same behavior.
NativeObject.BackgroundThread
- Calls the method asynchronously in a background thread.You can use the optional parameter resultHandler
to obtain the method return value asynchronously.
You can supply a JavaScript function for resultHandler
. newInstance()
then immediately returns an undefined value. It then calls the resultHandler
function after the constructor call
has finished. It supplies the method return value as first parameter to the function.
You can also omit resultHandler
. In this case, newInstance()
returns the new instance directly. If the call is executed on another thread, this means the QML thread will be blocked during that
time.
Set the static property propertyName
from the native class represented by this item to value
.
On Android, this sets a static field in the native class. If no field with this name exists or the field is not public, it logs a warning message and does nothing.
On iOS, this sets a static Objective C property in the native class. If no property with this name exists, it logs a warning message and does nothing.
See also getStaticProperty() and NativeObject::setProperty().