提交 df493a8e 编写于 作者: DCloud_iOS_XHY's avatar DCloud_iOS_XHY 提交者: shutao-dc

iOS 补齐 get-native-view uts 插件实现

上级 bb7937d3
//
// 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
}
}
import { CanWebViewGoBack, CanWebViewGoForward, HasNativeView } from "../interface"; import { CanWebViewGoBack, CanWebViewGoForward, HasNativeView, CheckWebViewNativeView, CheckInputNativeView, CheckTextareaNativeView, CheckViewNativeView } from "../interface";
import { WKWebView } from 'WebKit'; import { WKWebView } from 'WebKit';
import { UIView, UITextField, UITextView } from "UIKit"
export const canWebViewGoBack : CanWebViewGoBack = function (elementId : string) : boolean { export const canWebViewGoBack : CanWebViewGoBack = function (elementId : string) : boolean {
// const element = uni.getElementById(elementId) const element = uni.getElementById(elementId)
const element = DCGetElementByID.dcGetElementById(elementId)
const view = element?.getIOSView(); const view = element?.getIOSView();
if (view != null && view instanceof WKWebView) { if (view != null && view instanceof WKWebView) {
return (view! as WKWebView).canGoBack; return (view! as WKWebView).canGoBack;
...@@ -12,8 +12,7 @@ export const canWebViewGoBack : CanWebViewGoBack = function (elementId : string) ...@@ -12,8 +12,7 @@ export const canWebViewGoBack : CanWebViewGoBack = function (elementId : string)
} }
export const canWebViewGoForward : CanWebViewGoForward = function (elementId : string) : boolean { export const canWebViewGoForward : CanWebViewGoForward = function (elementId : string) : boolean {
// const element = uni.getElementById(elementId) const element = uni.getElementById(elementId)
const element = DCGetElementByID.dcGetElementById(elementId)
const view = element?.getIOSView(); const view = element?.getIOSView();
if (view != null && view instanceof WKWebView) { if (view != null && view instanceof WKWebView) {
return (view! as WKWebView).canGoForward; return (view! as WKWebView).canGoForward;
...@@ -22,11 +21,42 @@ export const canWebViewGoForward : CanWebViewGoForward = function (elementId : s ...@@ -22,11 +21,42 @@ export const canWebViewGoForward : CanWebViewGoForward = function (elementId : s
} }
export const hasNativeView : HasNativeView = function (elementId : string) : boolean { export const hasNativeView : HasNativeView = function (elementId : string) : boolean {
// const element = uni.getElementById(elementId) const element = uni.getElementById(elementId)
const element = DCGetElementByID.dcGetElementById(elementId)
const view = element?.getIOSView(); const view = element?.getIOSView();
if (view != null && view instanceof WKWebView) { if (view != null && view instanceof WKWebView) {
return true; return true;
} }
return false; 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;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册