UNPKG

@bezlepkin/nativescript-ar

Version:

NativeScript Augmented Reality plugin. ARKit on iOS and (with the help of Sceneform) ARCore on Android.

50 lines (49 loc) 2.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ARUIView = void 0; const core_1 = require("@nativescript/core"); const arcommon_1 = require("./arcommon"); class ARUIView extends arcommon_1.ARCommonNode { static create(options, fragment) { return new Promise(async (resolve, reject) => { const node = arcommon_1.ARCommonNode.createNode(options, fragment); const context = core_1.Utils.ad.getApplicationContext(); const container = new android.widget.LinearLayout(context); container.setOrientation(android.widget.LinearLayout.VERTICAL); const view = options.view; if (!view) { const label = new android.widget.TextView(context); label.setText("Hello World"); label.setShadowLayer(4, 0, 0, android.graphics.Color.WHITE); label.setTextColor(android.graphics.Color.BLACK); container.addView(label); } else { if (view.android && view.android.getParent()) { view.android.getParent().removeView(view.android); } if (!view.android) { view._setupUI(context); view.loadView(view); view.requestLayout(); } container.addView(view.android); } const customUI = com.google.ar.sceneform.rendering.ViewRenderable.builder() .setView(context, container) .build() .thenAccept(new java.util.function.Consumer({ accept: renderable => { console.log(">> accepted2, renderable: " + renderable); renderable.setVerticalAlignment(com.google.ar.sceneform.rendering.ViewRenderable.VerticalAlignment.BOTTOM); node.setRenderable(renderable); resolve(new ARUIView(options, node)); } })) .exceptionally(new java.util.function.Function({ apply: error => reject(error) })); }); } } exports.ARUIView = ARUIView;