FloatBubble 浮动气泡
介绍
悬浮在页面边缘的可点击气泡。
TIP
阅读该组件文档前请确保已认真阅读快速上手章节的每一个字。
引入
ts
import { IBestFloatBubble } from "@ibestservices/ibest-ui-v2";代码演示
基础用法

TIP
• 使用时需要通过 show 属性控制气泡的显隐, 具体显隐时机需开发者自己控制;
• 如果当前页面内需要跳转其他页面, 且需要隐藏气泡, 需要手动设置 show 为 false。
点我查看代码
ts
@Entry
@ComponentV2
struct DemoPage {
@Local bubbleShow: boolean = false
build() {
NavDestination(){
IBestFloatBubble({
show: this.bubbleShow,
icon: "chat",
onBubbleClick: () => {
IBestToast.show("点击了气泡")
}
})
}
.onShown(() => {
this.bubbleShow = true
})
.onWillHide(() => {
this.bubbleShow = false
})
}
}自动隐藏

点我查看代码
ts
@Entry
@ComponentV2
struct DemoPage {
@Local bubbleShow: boolean = false
build() {
NavDestination(){
IBestFloatBubble({
show: this.bubbleShow,
icon: "chat",
dragAxis: "xy",
autoHide: true
})
}
.onShown(() => {
this.bubbleShow = true
})
.onWillHide(() => {
this.bubbleShow = false
})
}
}自定颜色和内容

点我查看代码
ts
@Entry
@ComponentV2
struct DemoPage {
@Local bubbleShow: boolean = false
@Builder customBubble(){
Column({space: 6}){
IBestIcon({
name: "replay",
iconSize: 16,
color: "#fff"
})
Text("刷新").fontSize(12).fontColor("#fff")
}
}
build() {
NavDestination(){
IBestFloatBubble({
show: this.bubbleShow,
bubbleSize: 54,
bgColor: "#ed4040",
pos: {right: 0, bottom: 100},
bubbleShadow: {
radius: 14,
color: "#333"
}
}){
this.customBubble()
}
}
.onShown(() => {
this.bubbleShow = true
})
.onWillHide(() => {
this.bubbleShow = false
})
}
}API
@Props
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| show | 是否展示 | boolean | false |
| bgColor | 气泡背景色 | ResourceColor | #1989fa |
| bubbleSize | 气泡大小 | string | number | 48 |
| shape | 气泡形状, 可选值为 circle square | string | circle |
| radius | 圆角, 仅shap为 square 时生效 | string | number | 6 |
| icon | 图标 | ResourceStr | - |
| iconSize | 图标大小 | string | number | 24 |
| iconColor | 图标颜色 | ResourceColor | #fff |
| pos | 气泡初始位置 | IBestEdges | - |
| dragAxis | 可拖拽方向, 可选值为 x y xy lock | string | y |
| gap | 气泡与窗口最小间距 | number | 24 |
| isMagnetic | 是否开启磁吸 | boolean | true |
| bubbleShadow | 气泡阴影 | ShadowOptions | ShadowStyle | - |
| autoHide | 自动磁吸后是否自动延时隐藏, 仅isMagnetic为true时有效 | boolean | false |
| hideDelay | 延时隐藏时间, 单位ms, 仅autoHide为true时有效 | number | 2000 |
| remainSize | 隐藏时预留尺寸, 仅autoHide为true时有效 | number | 20 |
IBestEdges 数据结构
| 参数 | 说明 | 类型 |
|---|---|---|
| top | 顶部距离 | number |
| left | 左侧距离 | number |
| right | 右侧距离, 优先级大于left | number |
| bottom | 底部距离, 优先级大于top | number |
插槽
| 插槽名 | 说明 | 类型 |
|---|---|---|
| defaultBuilder | 自定义气泡的内容 | CustomBuilder |
Events
| 事件名 | 说明 | 事件类型 |
|---|---|---|
| onBubbleClick | 点击气泡触发 | () => void |