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

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

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