【问题标题】:NativeScript get current android context with Vue?NativeScript 使用 Vue 获取当前的 android 上下文?
【发布时间】:2019-04-22 05:25:31
【问题描述】:

我正在尝试使用需要上下文来实例化 UI 对象的本机映射库,我该如何传递它?

native 函数是 android.view.View 的扩展,它需要的参数是一个 Context。

参考:https://developers.arcgis.com/android/latest/api-reference/reference/com/esri/arcgisruntime/mapping/view/MapView.html#MapView(android.content.Context)

Example.vue:

<template>
    <Page class="page">
        <StackLayout>
            <Placeholder @creatingView="creatingView"/>
         </StackLayout>
    </Page>
</template>

<script>
    export default {
        methods: {
            creatingView(args){
                //This is where I need the context as a parameter
                const nativeView = new com.esri.arcgisruntime.mapping.view.MapView(this.context);
                args.view = nativeView;                    
            }
        }
    };
</script>

【问题讨论】:

    标签: nativescript nativescript-vue


    【解决方案1】:

    无论您使用什么风格/框架,您都可以使用应用程序上下文,

    import * as application from "application";
    
    const context = application.android.context;
    

    【讨论】:

      【解决方案2】:

      您可以从createView 事件参数中获取当前的android 上下文。

      methods: {
             creatingView(args){
                 const nativeView = new com.esri.arcgisruntime.mapping.view.MapView(args.context);
                 args.view = nativeView;                    
             }
      }
      

      【讨论】:

        猜你喜欢
        • 2012-06-22
        • 1970-01-01
        • 1970-01-01
        • 2020-05-05
        • 2012-07-09
        • 1970-01-01
        • 1970-01-01
        • 2019-02-19
        • 1970-01-01
        相关资源
        最近更新 更多