提交 1cd80a5f 编写于 作者: shutao-dc's avatar shutao-dc

uts-get-native-view/utssdk/app-android/index.uts 补充非泛型获取androidView示例

上级 a2404d28
......@@ -3,10 +3,10 @@
<input id="input" value="input" class="input" />
<textarea id="textarea" value="textarea" class="textarea" />
<web-view id="webview" src="/hybrid/html/local.html" class="web-view"></web-view>
<button type="primary" @click="checkViewNativeView">检测view标签原生View</button>
<button type="primary" @click="checkInputNativeView">检测input标签原生View</button>
<button type="primary" @click="checkTextareaNativeView">检测textarea标签原生View</button>
<button type="primary" @click="checkWebViewNativeView">检测input标签原生View</button>
<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>
</view>
</template>
......@@ -93,4 +93,8 @@
border-color: black;
border-style: solid;
}
.button {
margin: 10px 20px;
}
</style>
......@@ -20,21 +20,28 @@ export const hasNativeView : HasNativeView = function (elementId : string) : boo
}
export const checkWebViewNativeView: CheckWebViewNativeView = function (elementId : string) : boolean {
const view = uni.getElementById(elementId)?.getAndroidView<WebView>();
return view != null;
//通过getElementById不设置泛型,取值view类型 再通过instanceof校验WebView
const element = uni.getElementById(elementId)
if(element != null && element.getAndroidView()! instanceof WebView) {
return true
}
return false;
}
export const checkInputNativeView: CheckInputNativeView = function (elementId : string) : boolean {
//通过getAndroidView设置泛型直接获取EditText 如果获取失败则返回null
const view = uni.getElementById(elementId)?.getAndroidView<EditText>();
return view != null;
}
export const checkTextareaNativeView: CheckViewNativeView = function (elementId : string) : boolean {
//通过getAndroidView设置泛型直接获取EditText 如果获取失败则返回null
const view = uni.getElementById(elementId)?.getAndroidView<EditText>();
return view != null;
}
export const checkViewNativeView: CheckViewNativeView = function (elementId : string) : boolean {
//通过getAndroidView设置泛型直接获取ViewGroup 如果获取失败则返回null
const view = uni.getElementById(elementId)?.getAndroidView<ViewGroup>();
return view != null;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册