提交 1364d280 编写于 作者: DCloud_iOS_XHY's avatar DCloud_iOS_XHY

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

上级 944fc893
//
// 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 { 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;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册