Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
67c0beb1
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5995
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
67c0beb1
编写于
7月 29, 2024
作者:
shutao-dc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新增get-native-view示例
上级
a6a3d1f5
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
190 addition
and
1 deletion
+190
-1
pages.json
pages.json
+9
-0
pages/API/get-native-view/get-native-view.test.js
pages/API/get-native-view/get-native-view.test.js
+42
-0
pages/API/get-native-view/get-native-view.uvue
pages/API/get-native-view/get-native-view.uvue
+96
-0
uni_modules/uts-get-native-view/utssdk/app-android/index.uts
uni_modules/uts-get-native-view/utssdk/app-android/index.uts
+23
-1
uni_modules/uts-get-native-view/utssdk/interface.uts
uni_modules/uts-get-native-view/utssdk/interface.uts
+20
-0
未找到文件。
pages.json
浏览文件 @
67c0beb1
...
...
@@ -1099,6 +1099,15 @@
"navigationBarTitleText"
:
"createSelectorQuery | 创建 SelectorQuery 实例"
}
},
//
#ifndef
APP
{
"path"
:
"pages/API/get-native-view/get-native-view"
,
"style"
:
{
"navigationBarTitleText"
:
"获取原生view"
,
"backgroundColor"
:
"#F8F8F8"
}
},
//
#endif
{
"path"
:
"pages/API/create-canvas-context-async/create-canvas-context-async"
,
"group"
:
"1,16,3"
,
...
...
pages/API/get-native-view/get-native-view.test.js
0 → 100644
浏览文件 @
67c0beb1
describe
(
'
get-native-view
'
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
indexOf
(
'
web
'
)
>
-
1
||
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
==
'
true
'
)
{
it
(
'
object
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
})
return
}
let
page
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
'
/pages/API/get-native-view/get-native-view
'
)
await
page
.
waitFor
(
'
web-view
'
)
})
//检测view标签原生View是否匹配
it
(
'
check_view_native_view
'
,
async
()
=>
{
page
.
waitFor
(
100
)
const
value
=
await
page
.
callMethod
(
'
checkViewNativeView
'
)
expect
(
value
).
toBe
(
true
)
})
//检测intpu标签原生View是否匹配
it
(
'
check_input_native_view
'
,
async
()
=>
{
page
.
waitFor
(
100
)
const
value
=
await
page
.
callMethod
(
'
checkInputNativeView
'
)
expect
(
value
).
toBe
(
true
)
})
//检测textarea标签原生View是否匹配
it
(
'
check_textarea_native_view
'
,
async
()
=>
{
page
.
waitFor
(
100
)
const
value
=
await
page
.
callMethod
(
'
checkTextareaNativeView
'
)
expect
(
value
).
toBe
(
true
)
})
//检测view标签原生View是否匹配
it
(
'
check_web_view_native_view
'
,
async
()
=>
{
page
.
waitFor
(
100
)
const
value
=
await
page
.
callMethod
(
'
checkWebViewNativeView
'
)
expect
(
value
).
toBe
(
true
)
})
})
pages/API/get-native-view/get-native-view.uvue
0 → 100644
浏览文件 @
67c0beb1
<template>
<view id="view" style="flex: 1;">
<input id="input" value="input" class="input" />
<textarea id="textarea" value="textarea" class="textarea" />
<web-view id="webview" src="/hybrid/html/local.html" class="web-view"></web-view>
<button type="primary" @click="checkViewNativeView">检测view标签原生View</button>
<button type="primary" @click="checkInputNativeView">检测input标签原生View</button>
<button type="primary" @click="checkTextareaNativeView">检测textarea标签原生View</button>
<button type="primary" @click="checkWebViewNativeView">检测input标签原生View</button>
</view>
</template>
<script>
import { checkWebViewNativeView, checkInputNativeView, checkTextareaNativeView, checkViewNativeView } from '@/uni_modules/uts-get-native-view';
export default {
data() {
return {
}
},
methods: {
checkViewNativeView() : boolean {
if (checkViewNativeView("view")) {
uni.showToast({
title: "检测view原生View成功"
})
return true
}
console.log("检测view原生View失败")
return false
},
checkInputNativeView() : boolean {
if (checkInputNativeView("input")) {
uni.showToast({
title: "检测input原生View成功"
})
return true
}
console.log("检测input原生View失败")
return false
},
checkTextareaNativeView() : boolean {
if (checkTextareaNativeView("textarea")) {
uni.showToast({
title: "检测textarea原生View成功"
})
return true
}
console.log("检测textarea原生View失败")
return false
},
checkWebViewNativeView() : boolean {
if (checkWebViewNativeView("webview")) {
uni.showToast({
title: "检测webview原生View成功"
})
return true
}
console.log("检测webview原生View失败")
return false
}
}
}
</script>
<style>
.input {
width: 300px;
height: 40px;
border-radius: 4px;
border-width: 1px;
border-color: black;
border-style: solid;
margin: 20px auto;
}
.textarea {
width: 300px;
height: 80px;
border-radius: 4px;
border-width: 1px;
border-color: black;
border-style: solid;
margin: 20px auto;
}
.web-view {
width: 300px;
height: 120px;
margin: 20px auto;
border-radius: 4px;
border-width: 1px;
border-color: black;
border-style: solid;
}
</style>
uni_modules/uts-get-native-view/utssdk/app-android/index.uts
浏览文件 @
67c0beb1
import { CanWebViewGoBack, CanWebViewGoForward, HasNativeView} from "../interface";
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 ViewGroup from "android.view.ViewGroup"
export const canWebViewGoBack : CanWebViewGoBack = function (elementId : string) : boolean {
const view = uni.getElementById(elementId)?.getAndroidView<WebView>();
...
...
@@ -16,3 +18,23 @@ export const hasNativeView : HasNativeView = function (elementId : string) : boo
const view = uni.getElementById(elementId)?.getAndroidView<View>();
return view != null;
}
export const checkWebViewNativeView: CheckWebViewNativeView = function (elementId : string) : boolean {
const view = uni.getElementById(elementId)?.getAndroidView<WebView>();
return view != null;
}
export const checkInputNativeView: CheckInputNativeView = function (elementId : string) : boolean {
const view = uni.getElementById(elementId)?.getAndroidView<EditText>();
return view != null;
}
export const checkTextareaNativeView: CheckViewNativeView = function (elementId : string) : boolean {
const view = uni.getElementById(elementId)?.getAndroidView<EditText>();
return view != null;
}
export const checkViewNativeView: CheckViewNativeView = function (elementId : string) : boolean {
const view = uni.getElementById(elementId)?.getAndroidView<ViewGroup>();
return view != null;
}
uni_modules/uts-get-native-view/utssdk/interface.uts
浏览文件 @
67c0beb1
...
...
@@ -12,3 +12,23 @@ export type CanWebViewGoForward = (elementId : string) => boolean
* 是否存在原生view
*/
export type HasNativeView = (elementId : string) => boolean
/**
* 检测web-view标签获取到的原生View是否符合预期的原生View
*/
export type CheckWebViewNativeView = (elementId : string) => boolean
/**
* 检测input标签获取到的原生View是否符合预期的原生View
*/
export type CheckInputNativeView = (elementId : string) => boolean
/**
* 检测textarea标签获取到的原生View是否符合预期的原生View
*/
export type CheckTextareaNativeView = (elementId : string) => boolean
/**
* 检测view标签获取到的原生View是否符合预期的原生View
*/
export type CheckViewNativeView = (elementId : string) => boolean
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录