首页 文章

Nativescript:TypeError:无法读取未定义的属性'LayoutParams'

提问于
浏览
0

我正在使用this Build 一个Camera组件

Html

<StackLayout exampleTitle toggleNavButtonrm>
    <ScrollView>
        <!-- >> camera-module-html -->
        <FlexboxLayout flexDirection="column-reverse">
            <Image [src]="imageTaken" flexGrow="3" class="img-rounded"></Image>  
            <Button text="Take Photo" class="btn btn-primary btn-active" (tap)="onTakePhoto()" flexGrow="1"></Button>
            <Button text="Request permissions" class="btn btn-primary btn-active" (tap)="onRequestPermissions()" flexGrow="1"></Button>         
        </FlexboxLayout>
        <!-- << camera-module-html -->
    </ScrollView>
</StackLayout>

component.ts

import { Component } from "@angular/core";
import { ImageAsset } from "image-asset";
import * as camera from "nativescript-camera";

@Component({
    selector: 'using-camera-component',
    templateUrl: 'pages/createexpense/expense-photo.html'
})

export class ExpensePhotoComponent {

    public imageTaken: ImageAsset;
    public saveToGallery: boolean = true;
    public keepAspectRatio: boolean = true;
    public width: number = 300;
    public height: number = 300;

    onTakePhoto() {
        var options = { width: this.width, height: this.height, keepAspectRatio: this.keepAspectRatio,  saveToGallery: this.saveToGallery };
        camera.takePicture(options)
            .then(imageAsset => {
                this.imageTaken = imageAsset;
                console.log("Size: " + imageAsset.options.width + "x" + imageAsset.options.height);
            }).catch(err => {
                console.log(err.message);
            })
    }

    onRequestPermissions() {
        camera.requestPermissions();
    }


    onCheckForCamera() {
        var isCameraAvailable = camera.isAvailable();
        console.log("Is camera hardware available: " + isCameraAvailable);
    }

}

这是我得到的痕迹:

java.lang.RuntimeException:无法恢复活动{org.nativescript.finlyng / com.tns.NativeScriptActivity}:
com.tns.NativeScriptException:调用js方法onCreateView失败TypeError:无法读取未定义的属性'LayoutParams'
文件:“/ data / data / org.nativescript.finlyng / files / app / tns_modules / ui / core / view.js,
line:507,column:68 StackTrace:
框架:功能:'ViewStyler.setNativeLayoutParamsProperty',file:'/ data / data / org.nativescript.finlyng / files / app / tns_modules / ui / core / view.js',
line:507,column:69 Frame:function:'StylePropertyChangedHandler.applyProperty',file:'/ data / data / org.nativescript.finlyng / files / app / tns_modules / ui / styling / style.js',line:1326, column:14 Frame:function:'Style._applyStyleProperty',file:'/ data / data / org.nativescript.finlyng / files / app / tns_modules / ui / styling / style.js',line:1086,column:25 Frame :function:'Style._applyProperty',file:'/ data / data / org.nativescript.finlyng / files / app / tns_modules / ui / styling / style.js',line:1049,column:14

我该如何解决这个问题?谢谢

1 回答

  • 2

    您的代码很好,但是为了使用 FlexboxLayoutImageAsset 模块,您需要在应用程序中使用tns-core-modules @(因为这些功能未正式发布,并且将与NativeScript 2.4.0一起出现)

    请注意,您引用的示例应用程序在其package.json中具有以下依赖关系

    "tns-core-modules": "next"
    

    尝试以这种方式更新tns-core-modules:

    tns plugin remove tns-core-modules
    tns plugin add tns-core-modules@next
    

    然后删除 node_modulesplatforms 文件夹并重建您的应用程序 .

相关问题