SafeView
这个提交包含在:
父节点
82e14a060b
当前提交
a2d70ffff2
@ -1,75 +1,138 @@
|
|||||||
import { WindowHelper } from '../utils/WindowHelper'
|
import { WindowHelper } from '../utils/WindowHelper';
|
||||||
import { inputMethod } from '@kit.IMEKit'
|
import { inputMethod } from '@kit.IMEKit';
|
||||||
|
|
||||||
|
export interface TitleBarBtn {
|
||||||
|
text?: string | Resource;
|
||||||
|
img?: PixelMap | ResourceStr | DrawableDescriptor;
|
||||||
|
color?: string | Resource;
|
||||||
|
onClick: () => void
|
||||||
|
}
|
||||||
|
|
||||||
@Preview
|
@Preview
|
||||||
@Component
|
@Component
|
||||||
export struct SafeView {
|
export struct SafeView {
|
||||||
@Consume('pageInfos') pageInfos?: NavPathStack
|
@Consume('pageInfos') pageInfos?: NavPathStack
|
||||||
@Link isLoading: boolean
|
@Link isLoading: boolean
|
||||||
@State _titleText: ResourceStr=''
|
// 是不是沉浸式
|
||||||
private _onBackEvent?: () => void
|
@Prop isImmersive: boolean
|
||||||
|
// 设置导航栏标题
|
||||||
|
@Prop titleText: ResourceStr
|
||||||
|
// 设置导航栏背景色
|
||||||
|
@Prop backgroundColorY: ResourceColor
|
||||||
|
// 设置导航栏背景不透明度
|
||||||
|
// 元素的不透明度,取值范围为0到1,1表示不透明,0表示完全透明, 达到隐藏组件效果,但是在布局中占位。
|
||||||
|
@Prop opacitys: number | Resource
|
||||||
|
// 设置返回按钮事件
|
||||||
|
onBackEvent?: () => void = undefined
|
||||||
|
// 设置返回按钮事件
|
||||||
|
onClickLeft?: TitleBarBtn
|
||||||
|
onClickRight?: TitleBarBtn
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
doNothingBuilder() {
|
doNothingBuilder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
onBack(event: () => void) {
|
|
||||||
this._onBackEvent = event
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
titleText(title: ResourceStr) {
|
|
||||||
this._titleText = title
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
@BuilderParam customBuilderParam: () => void = this.doNothingBuilder
|
@BuilderParam customBuilderParam: () => void = this.doNothingBuilder
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
NavDestination() {
|
NavDestination() {
|
||||||
Stack() {
|
Stack() {
|
||||||
Column() {
|
Column() {
|
||||||
Row()
|
this.customBuilderParam()
|
||||||
.height(WindowHelper.topRectHeight)
|
}
|
||||||
.width('100%')
|
.padding({
|
||||||
.backgroundColor('#999999')
|
top: this.isImmersive ? 0 : WindowHelper.topRectHeight + 44
|
||||||
Row() {
|
})
|
||||||
|
.align(Alignment.Top)
|
||||||
|
.width('100%')
|
||||||
|
.height('100%')
|
||||||
|
|
||||||
|
Row()
|
||||||
|
.height(WindowHelper.topRectHeight)
|
||||||
|
.width('100%')
|
||||||
|
.backgroundColor(this.backgroundColorY ?? 'white')
|
||||||
|
.opacity(undefined === this.opacitys ? 1 : this.opacitys > 1 ? 1 : this.opacitys < 0 ? 0 : this.opacitys)
|
||||||
|
|
||||||
|
Row() {
|
||||||
|
|
||||||
|
Row() {
|
||||||
Image($r("app.media.base_back"))
|
Image($r("app.media.base_back"))
|
||||||
.height(15)
|
.height(15)
|
||||||
|
.objectFit(ImageFit.Contain)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
if (this._onBackEvent) {
|
if (this.onBackEvent) {
|
||||||
this._onBackEvent()
|
this.onBackEvent()
|
||||||
} else if (this.pageInfos) {
|
} else if (this.pageInfos) {
|
||||||
this.pageInfos.pop()
|
this.pageInfos.pop()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}.width(110)
|
||||||
|
|
||||||
Text(this._titleText ?? '')
|
Text(`${this.titleText}:${this.titleText}:${this.titleText}:${this.titleText}:${this.titleText}:${this.titleText}:${this.titleText}:${this.titleText}:${this.titleText}:${this.titleText}:`)
|
||||||
.maxLines(1)
|
.maxLines(1)
|
||||||
.ellipsisMode(EllipsisMode.CENTER)
|
.ellipsisMode(EllipsisMode.CENTER)
|
||||||
.textOverflow({
|
.textOverflow({
|
||||||
overflow: TextOverflow.Ellipsis
|
overflow: TextOverflow.Ellipsis
|
||||||
})
|
})
|
||||||
|
.constraintSize({
|
||||||
Row() {
|
maxWidth: 120
|
||||||
|
})
|
||||||
|
|
||||||
|
Row() {
|
||||||
|
if (!this.onClickLeft?.img && this.onClickLeft) {
|
||||||
|
Text(`${this.onClickLeft?.text}` ?? '确定')
|
||||||
|
.fontColor(this.onClickLeft?.color ?? '#17171A')
|
||||||
|
.onClick(() => {
|
||||||
|
this.onClickLeft?.onClick && this.onClickLeft?.onClick()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (this.onClickLeft?.img) {
|
||||||
|
Image(this.onClickLeft.img)
|
||||||
|
.onClick(() => {
|
||||||
|
this.onClickLeft?.onClick && this.onClickLeft?.onClick()
|
||||||
|
})
|
||||||
|
.objectFit(ImageFit.Contain)
|
||||||
|
.width(20)
|
||||||
|
.height(20)
|
||||||
|
}
|
||||||
|
if (!this.onClickRight?.img && this.onClickRight) {
|
||||||
|
Text(this.onClickRight?.text ?? '确定')
|
||||||
|
.fontColor(this.onClickRight?.color ?? '#17171A')
|
||||||
|
.onClick(() => {
|
||||||
|
this.onClickRight?.onClick && this.onClickRight?.onClick()
|
||||||
|
})
|
||||||
|
.margin({
|
||||||
|
left: 10
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (this.onClickRight?.img) {
|
||||||
|
Image(this.onClickRight.img)
|
||||||
|
.onClick(() => {
|
||||||
|
this.onClickRight?.onClick && this.onClickRight?.onClick()
|
||||||
|
})
|
||||||
|
.objectFit(ImageFit.Contain)
|
||||||
|
.width(20)
|
||||||
|
.height(20)
|
||||||
|
.margin({
|
||||||
|
left: 10
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
.justifyContent(FlexAlign.SpaceBetween)
|
|
||||||
.padding({
|
|
||||||
left: 15,
|
|
||||||
right: 15
|
|
||||||
})
|
|
||||||
.height(44)
|
|
||||||
.width('100%')
|
|
||||||
|
|
||||||
this.customBuilderParam()
|
}.width(110)
|
||||||
|
.justifyContent(FlexAlign.End)
|
||||||
}
|
}
|
||||||
|
.backgroundColor(this.backgroundColorY ?? 'white')
|
||||||
|
.opacity(undefined === this.opacitys ? 1 : this.opacitys > 1 ? 1 : this.opacitys < 0 ? 0 : this.opacitys)
|
||||||
|
.justifyContent(FlexAlign.SpaceBetween)
|
||||||
|
.height(44)
|
||||||
|
.padding({
|
||||||
|
left: 15,
|
||||||
|
right: 15
|
||||||
|
})
|
||||||
.width('100%')
|
.width('100%')
|
||||||
.height('100%')
|
.margin({
|
||||||
.justifyContent(FlexAlign.Start)
|
top: WindowHelper.topRectHeight
|
||||||
|
})
|
||||||
|
|
||||||
Column() {
|
Column() {
|
||||||
LoadingProgress()
|
LoadingProgress()
|
||||||
@ -85,11 +148,24 @@ export struct SafeView {
|
|||||||
.backgroundColor('#40000000')
|
.backgroundColor('#40000000')
|
||||||
.justifyContent(FlexAlign.Center)
|
.justifyContent(FlexAlign.Center)
|
||||||
}
|
}
|
||||||
}.onClick(() => {
|
.align(Alignment.Top)
|
||||||
|
.width('100%')
|
||||||
|
.height('100%')
|
||||||
|
}
|
||||||
|
.onClick(() => {
|
||||||
inputMethod.getController().stopInputSession()
|
inputMethod.getController().stopInputSession()
|
||||||
})
|
})
|
||||||
.hideTitleBar(true)
|
.hideTitleBar(true)
|
||||||
.width('100%')
|
.width('100%')
|
||||||
.height('100%')
|
.height('100%')
|
||||||
|
.backgroundColor('white')
|
||||||
|
.onBackPressed(() => {
|
||||||
|
if (this.onBackEvent) {
|
||||||
|
this.onBackEvent()
|
||||||
|
} else if (this.pageInfos) {
|
||||||
|
this.pageInfos.pop()
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
正在加载...
在新工单中引用
屏蔽一个用户