提交 67c0beb1 编写于 作者: shutao-dc's avatar shutao-dc

新增get-native-view示例

上级 a6a3d1f5
......@@ -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",
......
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)
})
})
<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>
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;
}
......@@ -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.
先完成此消息的编辑!
想要评论请 注册