element-getnativeview.uvue 3.5 KB
Newer Older
shutao-dc's avatar
shutao-dc 已提交
1 2 3 4
<template>
  <view id="view" style="flex: 1;">
    <input id="input" value="input" class="input" />
    <textarea id="textarea" value="textarea" class="textarea" />
DCloud-WZF's avatar
DCloud-WZF 已提交
5
    <web-view id="webview" src="/hybrid/html/local.html" class="web-view"></web-view>
DCloud_iOS_XHY's avatar
DCloud_iOS_XHY 已提交
6
    // 注意:iOS平台真机运行时需要安装 Xcode 开发工具具备 UTS 开发环境,或提交自定基座打包后 checkNativeView 相关方法才会生效
7 8 9 10
    <button class="button" type="primary" @click="checkViewNativeView">检测view标签原生View</button>
    <button class="button" type="primary" @click="checkInputNativeView">检测input标签原生View</button>
    <button class="button" type="primary" @click="checkTextareaNativeView">检测textarea标签原生View</button>
    <button class="button" type="primary" @click="checkWebViewNativeView">检测webview标签原生View</button>
shutao-dc's avatar
shutao-dc 已提交
11 12 13 14 15 16 17 18 19 20 21 22
  </view>
</template>

<script>
  import { checkWebViewNativeView, checkInputNativeView, checkTextareaNativeView, checkViewNativeView } from '@/uni_modules/uts-get-native-view';
  export default {
    data() {
      return {

      }
    },
    methods: {
DCloud-WZF's avatar
DCloud-WZF 已提交
23 24 25 26 27 28 29 30
      checkViewNativeView() : boolean {
        var viewName = "ViewGroup"
        // #ifdef APP-IOS
        viewName = "UIView"
        // #endif
        const msg = "检测view组件对应原生" + viewName
        if (checkViewNativeView("view")) {
          this.showTip(msg + "成功")
shutao-dc's avatar
shutao-dc 已提交
31
          return true
DCloud-WZF's avatar
DCloud-WZF 已提交
32 33
        }
        this.showTip(msg + "失败")
shutao-dc's avatar
shutao-dc 已提交
34 35
        return false
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
36 37 38 39 40 41 42 43
      checkInputNativeView() : boolean {
        var viewName = "AppCompatEditText"
        // #ifdef APP-IOS
        viewName = "UITextField"
        // #endif
        const msg = "检测input组件对应原生" + viewName
        if (checkInputNativeView("input")) {
          this.showTip(msg + "成功")
shutao-dc's avatar
shutao-dc 已提交
44
          return true
DCloud-WZF's avatar
DCloud-WZF 已提交
45 46
        }
        this.showTip(msg + "失败")
shutao-dc's avatar
shutao-dc 已提交
47 48
        return false
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
49 50 51 52 53 54 55 56
      checkTextareaNativeView() : boolean {
        var viewName = "AppCompatEditText"
        // #ifdef APP-IOS
        viewName = "UITextView"
        // #endif
        const msg = "检测textarea组件对应原生" + viewName
        if (checkTextareaNativeView("textarea")) {
          this.showTip(msg + "成功")
shutao-dc's avatar
shutao-dc 已提交
57
          return true
DCloud-WZF's avatar
DCloud-WZF 已提交
58 59
        }
        this.showTip(msg + "失败")
shutao-dc's avatar
shutao-dc 已提交
60 61
        return false
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
62 63 64 65 66 67 68 69
      checkWebViewNativeView() : boolean {
        var viewName = "WebView"
        // #ifdef APP-IOS
        viewName = "WKWebView"
        // #endif
        const msg = "检测webview组件对应原生" + viewName
        if (checkWebViewNativeView("webview")) {
          this.showTip(msg + "成功")
shutao-dc's avatar
shutao-dc 已提交
70
          return true
DCloud-WZF's avatar
DCloud-WZF 已提交
71 72
        }
        this.showTip(msg + "失败")
shutao-dc's avatar
shutao-dc 已提交
73
        return false
DCloud-WZF's avatar
DCloud-WZF 已提交
74 75 76 77 78 79 80
      },
      showTip(title : string) {
        console.log("title===" + title)
        uni.showToast({
          title: title,
          icon: "none"
        })
shutao-dc's avatar
shutao-dc 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
      }
    }
  }
</script>

<style>
  .input {
    width: 300px;
    height: 40px;
    border-radius: 4px;
    border-width: 1px;
    border-color: black;
    border-style: solid;
    margin: 20px auto;
  }

  .textarea {
    width: 300px;
    height: 80px;
    border-radius: 4px;
    border-width: 1px;
    border-color: black;
    border-style: solid;
    margin: 20px auto;
  }

  .web-view {
    width: 300px;
    height: 120px;
    margin: 20px auto;
    border-radius: 4px;
    border-width: 1px;
    border-color: black;
    border-style: solid;
DCloud-WZF's avatar
DCloud-WZF 已提交
115 116 117 118
  }

  .button {
    margin: 10px 20px;
shutao-dc's avatar
shutao-dc 已提交
119 120
  }
</style>