From 1364d280a97a721b149b5420bd639536a3b9448b Mon Sep 17 00:00:00 2001 From: XHY Date: Mon, 29 Jul 2024 20:09:02 +0800 Subject: [PATCH] =?UTF-8?q?iOS=20=E8=A1=A5=E9=BD=90=20get-native-view=20?= =?UTF-8?q?=20uts=20=E6=8F=92=E4=BB=B6=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utssdk/app-ios/DCGetElementByID.swift | 22 ---------- .../utssdk/app-ios/index.uts | 44 ++++++++++++++++--- 2 files changed, 37 insertions(+), 29 deletions(-) delete mode 100644 uni_modules/uts-get-native-view/utssdk/app-ios/DCGetElementByID.swift 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 f60b4608..00000000 --- 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 b03c6eb5..bf47264c 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; +} + -- GitLab