diff --git a/uni_modules/uts-get-native-view/utssdk/app-ios/DCGetElementByID.swift b/uni_modules/uts-get-native-view/utssdk/app-ios/DCGetElementByID.swift deleted file mode 100644 index f60b46083d1e653088389d7c8b38c6cb97d30a5b..0000000000000000000000000000000000000000 --- a/uni_modules/uts-get-native-view/utssdk/app-ios/DCGetElementByID.swift +++ /dev/null @@ -1,22 +0,0 @@ -// -// DCUni.swift -// DCGetElementByID -// -// Created by DCloud-iOS-XHY on 2024/7/8. -// - -import DCloudUniappRuntime - -public class DCGetElementByID { - /// 返回一个匹配特定 ID 的元素, 如果不存在,返回 null 规则同 https://doc.dcloud.net.cn/uni-app-x/api/get-element.html#getelementbyid - public static func dcGetElementById(_ id: String) -> UniElement? { - let appManager = UniSDKEngine.self.getAppManager() - if let app = appManager.getCurretApp(), - let pageManager = app.pageManager as? UniPageManagerImpl, - let page = pageManager.getTopPage(), - let domManager = page.document as? UniDomManager { - return domManager.getElementById(id) - } - return nil - } -} diff --git a/uni_modules/uts-get-native-view/utssdk/app-ios/index.uts b/uni_modules/uts-get-native-view/utssdk/app-ios/index.uts index b03c6eb582dd3a0582eda28dd9baf32eef6cb36d..bf47264c92e7b2dc07d55d6bfffa92083ce791d4 100644 --- a/uni_modules/uts-get-native-view/utssdk/app-ios/index.uts +++ b/uni_modules/uts-get-native-view/utssdk/app-ios/index.uts @@ -1,9 +1,9 @@ -import { CanWebViewGoBack, CanWebViewGoForward, HasNativeView } from "../interface"; +import { CanWebViewGoBack, CanWebViewGoForward, HasNativeView, CheckWebViewNativeView, CheckInputNativeView, CheckTextareaNativeView, CheckViewNativeView } from "../interface"; import { WKWebView } from 'WebKit'; +import { UIView, UITextField, UITextView } from "UIKit" export const canWebViewGoBack : CanWebViewGoBack = function (elementId : string) : boolean { - // const element = uni.getElementById(elementId) - const element = DCGetElementByID.dcGetElementById(elementId) + const element = uni.getElementById(elementId) const view = element?.getIOSView(); if (view != null && view instanceof WKWebView) { return (view! as WKWebView).canGoBack; @@ -12,8 +12,7 @@ export const canWebViewGoBack : CanWebViewGoBack = function (elementId : string) } export const canWebViewGoForward : CanWebViewGoForward = function (elementId : string) : boolean { - // const element = uni.getElementById(elementId) - const element = DCGetElementByID.dcGetElementById(elementId) + const element = uni.getElementById(elementId) const view = element?.getIOSView(); if (view != null && view instanceof WKWebView) { return (view! as WKWebView).canGoForward; @@ -22,11 +21,42 @@ export const canWebViewGoForward : CanWebViewGoForward = function (elementId : s } export const hasNativeView : HasNativeView = function (elementId : string) : boolean { - // const element = uni.getElementById(elementId) - const element = DCGetElementByID.dcGetElementById(elementId) + const element = uni.getElementById(elementId) const view = element?.getIOSView(); if (view != null && view instanceof WKWebView) { return true; } return false; } + +export const checkWebViewNativeView : CheckWebViewNativeView = function (elementId : string) : boolean { + return hasNativeView(elementId) +} + +export const checkInputNativeView : CheckInputNativeView = function (elementId : string) : boolean { + const element = uni.getElementById(elementId) + const view = element?.getIOSView(); + if (view != null && view instanceof UITextField) { + return true; + } + return false; +} + +export const checkTextareaNativeView : CheckTextareaNativeView = function (elementId : string) : boolean { + const element = uni.getElementById(elementId) + const view = element?.getIOSView(); + if (view != null && view instanceof UITextView) { + return true; + } + return false; +} + +export const checkViewNativeView : CheckViewNativeView = function (elementId : string) : boolean { + const element = uni.getElementById(elementId) + const view = element?.getIOSView(); + if (view != null && view instanceof UIView) { + return true; + } + return false; +} +