Anders Lassen wrote:
Hi,
The best way would be to create the event handler in JavaScript. Then create a NativeModule
in Uno, requiring that into JS, and calling that from your JS event handler.
Hi Anders,
So it’s working if I call the uno module from the UX, using embedded Javascript, but I cannot manage to make it work if I put the javascript call in another .js file (the require seems not to be finding the .uno):
Project structure:
- Data
- Context.js : global js file containing the call to the CameraExtended.uno method
- Preview
- Camera
- CameraExtended.uno : contains the method to call
- other camera panel files
- CameraStream.unoproj
- PreviewPage.ux : instanciates a camera preview and calls singleTap through Context.js
- MainView.ux : imports the global Context.js and instanciates a PreviewPage.ux
- MyProject.unoproj : imports CameraStream.unoproj as project
MyProject.unoproj:
{
"RootNamespace":"",
"Packages": [
"Fuse",
"FuseJS",
"Fuse.Maps",
"Fuse.GeoLocation",
"Fuse.Controls",
"Android",
"Fuse.Camera",
"Uno.Permissions"
],
"Includes": [
"*",
"**.js:Bundle",
"Data/*.js:Bundle"
],
"Projects":[
"Preview/Camera/CameraStream.unoproj"
]
}
CameraExtended.uno:
using Uno;
using Fuse;
using Fuse.Scripting;
using Fuse.Reactive;
using Uno.Threading;
using Uno.IO;
using Uno.UX;
[UXGlobalModule]
public class CameraExtended : NativeModule
{
public Camera Camera { get; set; }
public CameraExtended()
{
AddMember(new NativeFunction("singleTap", (NativeCallback)this.SingleTap));
}
object SingleTap(Context c, object[] args)
{
debug_log "single tap JS";
Camera.SingleTap();
return null;
}
CameraStream.unoproj:
{
"RootNamespace":"",
"Packages": [
"Fuse",
"FuseJS",
... other permissions
],
"Includes": [
"./*.uno",
... other includes
]
}
MainView.ux:
...
<JavaScript File="Data/Context.js" />
...
<PreviewPage ... />
...
Context.js:
var cameraExt = require("../Preview/Camera/CameraExtended");
...
function singleTap () {
cameraExt
.singleTap()
.then(function (file) { })
.catch(function (e) {
debug_log(e);
});
}
...singleTap is exported...
PreviewPage.ux:
...
<CameraStream>
<CameraVisual Camera="cam" Facing="Front" ux:Name="myCam">
<Clicked >
<Callback Handler="{singleTap}" />
...
Thanks in advance for your help!