diff --git a/uni_modules/uts-get-native-view/utssdk/app-android/index.uts b/uni_modules/uts-get-native-view/utssdk/app-android/index.uts index e502bdb95409a902c37c0ac80d2fafeceb6e782e..5f8ddbac0f3d4fc0d5d2a6b51777b02b59b8bf6a 100644 --- a/uni_modules/uts-get-native-view/utssdk/app-android/index.uts +++ b/uni_modules/uts-get-native-view/utssdk/app-android/index.uts @@ -1,7 +1,6 @@ import { CanWebViewGoBack, CanWebViewGoForward, HasNativeView, CheckWebViewNativeView, CheckInputNativeView, CheckTextareaNativeView, CheckViewNativeView} from "../interface"; import WebView from 'android.webkit.WebView'; -import View from "android.view.View" -import EditText from "android.widget.EditText" +import AppCompatEditText from "androidx.appcompat.widget.AppCompatEditText" import ViewGroup from "android.view.ViewGroup" export const canWebViewGoBack : CanWebViewGoBack = function (elementId : string) : boolean { @@ -15,28 +14,29 @@ export const canWebViewGoForward : CanWebViewGoForward = function (elementId : s } export const hasNativeView : HasNativeView = function (elementId : string) : boolean { - const view = uni.getElementById(elementId)?.getAndroidView(); + const view = uni.getElementById(elementId)?.getAndroidView(); return view != null; } export const checkWebViewNativeView: CheckWebViewNativeView = function (elementId : string) : boolean { //通过getElementById不设置泛型,取值view类型 再通过instanceof校验WebView const element = uni.getElementById(elementId) - if(element != null && element.getAndroidView()! instanceof WebView) { + const view = element?.getAndroidView() + if(view != null && view instanceof WebView) { return true } return false; } export const checkInputNativeView: CheckInputNativeView = function (elementId : string) : boolean { - //通过getAndroidView设置泛型直接获取EditText 如果获取失败则返回null - const view = uni.getElementById(elementId)?.getAndroidView(); + //通过getAndroidView设置泛型直接获取AppCompatEditText 如果获取失败则返回null + const view = uni.getElementById(elementId)?.getAndroidView(); return view != null; } export const checkTextareaNativeView: CheckViewNativeView = function (elementId : string) : boolean { - //通过getAndroidView设置泛型直接获取EditText 如果获取失败则返回null - const view = uni.getElementById(elementId)?.getAndroidView(); + //通过getAndroidView设置泛型直接获取AppCompatEditText 如果获取失败则返回null + const view = uni.getElementById(elementId)?.getAndroidView(); return view != null; }