NativeObjectUtils allows you to interact with objects native to the mobile platform. More...
Import Statement: | import Felgo 4.0 |
Since: | Felgo 3.3.0 |
This singleton type offers additional utility methods for dealing with NativeObjects. NativeObjectUtils is currently supported on Android and iOS.
You can obtain an instance to any native class with getClass().
On Android, you can access the app's Context with getContext(). You can also access the currently running Activity and/or Service with getActivity() and getService(). These methods can only be called on Android builds.
NativeObject getActivity() |
Returns a NativeObject instance representing the current Android Activity. If this method is called from a Service instead of an Activity, it will return null.
This method only exists on the Android platform. You can use the Qt global object to find out the currently running platform at runtime:
if(Qt.platform.os === "android") { var activity = NativeObjectUtils.getActivity() }
You can also use this property from within your NativeView::androidBinding implementation.
See also getContext() and getActivity().
NativeClass getClass(string className) |
Returns a NativeClass instance representing the Class className
of the native platform.
Note: On Android, separate packages in class names with "/"
. Separate nested classes with "$"
.
Example usage:
// get OnClickListener class on Android var javaObject = NativeObjectUtils.getClass("android/view/View$OnClickListener") // get UIView class on iOS var nsObject = NativeObjectUtils.getClass("UIView")
See also NativeObject::getClass().
NativeObject getContext() |
Returns a NativeObject instance representing the current Android Context.
This method only exists on the Android platform. You can use the Qt global object to find out the currently running platform at runtime:
if(Qt.platform.os === "android") { var context = NativeObjectUtils.getContext() }
You can also use this property from within your NativeView::androidBinding implementation.
See also getActivity() and getService().
NativeObject getService() |
Returns a NativeObject instance representing the current Android Service. If this method is called from an app without a Service, it will return null.
This method only exists on the Android platform. You can use the Qt global object to find out the currently running platform at runtime:
if(Qt.platform.os === "android") { var service = NativeObjectUtils.getService() }
You can also use this property from within your NativeView::androidBinding implementation.
See also getContext() and getService().
NativeObject wrap(var value) |
Wraps a JavaScript function or map of functions as a NativeObject.
The wrapped object can represent any native interface or prototocol. See the section about interfaces and protocols for more information.
This can use the QML engine to store a strong reference to that object. Assign it to any property for as long as it is used. The engine's garbage collector manages removing the reference afterwards.
Note: It is only useful to call this method on iOS. Objective C uses manual reference counting for its native objects. Java uses a garbage collector, thus there is no need for manual references.
Usage example:
Item { // Store strong reference to UIScrollViewDelegate for UIScrollView.delegate: readonly property NativeObject scrollViewDelegate: NativeObjectUtils.wrap({ "scrollViewWillBeginDragging:": function(scrollView) { console.log("begin dragging") }, // ...other delegate methods here }) }
See also NativeObject.