可上下滑动折叠的UI容器控件
| Files | Last commit | Last update |
|---|---|---|
| 9 months ago | ||
| 9 months ago | ||
| 9 months ago | ||
| 5 months ago | ||
| 9 months ago | ||
| 9 months ago | ||
| 9 months ago | ||
| 5 months ago | ||
| 9 months ago | ||
| 9 months ago | ||
| 5 months ago | ||
| 5 months ago | ||
| 9 months ago | ||
| 9 months ago | ||
| 9 months ago | ||
| 9 months ago |
SlidingUpPanel
A sliding up panel component, ported from the AndroidSlidingUpPanel library.
How to Install
ohpm install @ohos/slidinguppanel
How to Use
Basic Usage
import {
SlidingUpPanelLayout, PanelState, Gravity, ScrollPriority
} from '@ohos/slidinguppanel';
...
@Builder
buildDragHandle() {
Row() {
Rect()
.width(40)
.height(4)
.radius(2)
.fill('#CCCCCC')
}
.width('100%')
.height(this.handleHeight)
.justifyContent(FlexAlign.Center)
.backgroundColor('#FFFFFF')
}
@Builder
buildMainContent() {
Column() {
...
}
}
@Builder
buildSlideableContent() {
Column() {
...
}
}
build() {
Column() {
SlidingUpPanelLayout({
panelHeight: this.panelHeight,
shadowHeight: this.shadowHeight,
parallaxOffset: this.parallaxOffset,
fadeColor: this.fadeColor,
minFlingVelocity: this.minFlingVelocity,
isOverlay: this.isOverlay,
anchorPoint: this.anchorPoint,
slideState: this.initialState,
gravity: this.gravity,
touchEnabled: this.touchEnabled,
clipPanel: this.clipPanel,
dragViewEnabled: this.dragViewEnabled,
handleHeight: this.handleHeight,
scrollPriority: this.scrollPriority,
mainContent: () => {
this.buildMainContent();
},
slideableContent: () => {
this.buildSlideableContent();
},
dragHandle: () => {
this.buildDragHandle();
}
})
}
}
Drag Area Control
Specify which area on the panel can be used to drag the panel through the ViewId property:
import { SlidingUpPanelLayout, HandleView } from '@ohos/slidinguppanel';
...
@Builder
buildSlideableContent() {
Column() {
HandleView({
viewId: 'handle1',
gravity: this.gravity,
slideState: this.initialState,
view: this.handle1,
controller: this.controller
})
HandleView({
viewId: 'handle2',
gravity: this.gravity,
slideState: this.initialState,
view: this.handle2,
controller: this.controller
})
HandleView({
viewId: 'handle3',
gravity: this.gravity,
slideState: this.initialState,
view: this.handle3,
controller: this.controller
})
}
}
@Builder
buildMainContent() {
Column() {
...
}
}
build() {
Column() {
SlidingUpPanelLayout({
controller: this.controller,
panelHeight: this.panelHeight,
shadowHeight: this.shadowHeight,
parallaxOffset: this.parallaxOffset,
fadeColor: this.fadeColor,
minFlingVelocity: this.minFlingVelocity,
isOverlay: this.isOverlay,
anchorPoint: this.anchorPoint,
slideState: this.initialState,
gravity: this.gravity,
touchEnabled: this.touchEnabled,
clipPanel: this.clipPanel,
dragViewEnabled: this.dragViewEnabled,
handleHeight: this.handleHeight,
scrollPriority: this.scrollPriority,
mainContent: () => {
this.buildMainContent();
},
slideableContent: () => {
this.buildSlideableContent();
}
})
}
}
Available APIs
Component Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
panelHeight |
number |
68 |
Visible height of panel when collapsed (vp), must be ≥0 |
shadowHeight |
number |
4 |
Panel shadow height (vp), must be ≥0 |
parallaxOffset |
number |
0 |
Parallax offset (vp), must be ≥0 |
fadeColor |
string |
'#99000000' |
Background overlay color |
minFlingVelocity |
number |
1000 |
Minimum fling velocity (vp/s), range 100-1000 |
overlay |
boolean |
false |
Whether to overlay main content |
anchorPoint |
number |
1.0 |
Anchor position (0-1) |
initialState |
PanelState |
PanelState.COLLAPSED |
Initial state |
touchEnabled |
boolean |
true |
Whether to enable touch |
viewId |
string |
'' |
Drag area ID, empty means the entire panel can be dragged |
handleHeight |
number |
40 |
Drag handle height (vp), must be ≥0 |
PanelController Methods
PanelController provides complete panel control capabilities, including property setting, state control and event listening.
Property Control Methods
| Method | Parameter Type | Return Type | Description |
|---|---|---|---|
setPanelHeight(value: number) |
number |
void |
Set panel height |
getPanelHeight() |
- | number |
Get panel height |
setShadowHeight(value: number) |
number |
void |
Set shadow height |
getShadowHeight() |
- | number |
Get shadow height |
setParallaxOffset(value: number) |
number |
void |
Set parallax offset |
getCurrentParallaxOffset() |
- | number |
Get current parallax offset |
setCoveredFadeColor(value: string) |
string |
void |
Set overlay color |
getCoveredFadeColor() |
- | string |
Get overlay color |
setMinFlingVelocity(value: number) |
number |
void |
Set minimum fling velocity |
getMinFlingVelocity() |
- | number |
Get minimum fling velocity |
setIsOverlay(value: boolean) |
boolean |
void |
Set whether overlay mode |
getIsOverlay() |
- | boolean |
Get whether overlay mode |
setAnchorPoint(value: number) |
number |
void |
Set anchor position |
getAnchorPoint() |
- | number |
Get anchor position |
setPanelState(value: PanelState) |
PanelState |
void |
Set panel state |
getPanelState() |
- | PanelState |
Get panel state |
setTouchEnabled(value: boolean) |
boolean |
void |
Set whether touch enabled |
getTouchEnabled() |
- | boolean |
Get whether touch enabled |
setClipPanel(value: boolean) |
boolean |
void |
Set whether clip panel |
getClipPanel() |
- | boolean |
Get whether clip panel |
setDragViewEnabled(value: boolean) |
boolean |
void |
Set whether drag function enabled |
getDragViewEnabled() |
- | boolean |
Get whether drag function enabled |
setGravity(gravity: Gravity) |
Gravity |
void |
Set gravity direction |
getGravity() |
- | Gravity |
Get gravity direction |
setScrollPriority(value: ScrollPriority) |
ScrollPriority |
void |
Set scroll priority |
getScrollPriority() |
- | ScrollPriority |
Get scroll priority |
setHandleHeight(value: number) |
number |
void |
Set drag handle height |
getHandleHeight() |
- | number |
Get drag handle height |
setDragViewById(id: string) |
string |
void |
Set drag area ID |
setAnimation(animation: ICurve) |
ICurve |
void |
Set animation curve |
getAnimation() |
- | ICurve |
Get animation curve |
setScrollerController(value: Scroller) |
Scroller |
void |
Set scroll controller |
setDragView(value: () => void) |
() => void |
void |
Set drag view builder |
setFadeOnClickListener(listener: () => void) |
() => void |
void |
Set overlay click listener |
getFadeOnClickListener() |
- | () => void |
Get overlay click listener |
removeFadeOnClickListener() |
- | void |
Remove overlay click listener |
addPanelSlideListener(listener: PanelSlideListener) |
PanelSlideListener |
void |
Add panel slide listener |
removePanelSlideListener(listener: PanelSlideListener) |
PanelSlideListener |
void |
Remove panel slide listener |
isClipPanelSet() |
- | boolean |
Check if panel is clipped |
Constraints
This project has been verified in the following versions:
- DevEco Studio: 6.0.1 Release(6.0.1.260), SDK: API12(5.0.0.71)
Directory Structure
/ohos_SlidingUpPanel # Project root directory
├── entry # Sample code
├── library/ # ohos_SlidingUpPanel library
│ ├── src/main/ets/
│ │ ├── SlidingUpPanel/ # Sliding panel core implementation
│ │ │ ├── AnimationUtils.ets # Animation utilities
│ │ │ ├── Constants.ets # Constant definitions
│ │ │ ├── EmitterHelper.ets # Event emitter helper class
│ │ │ ├── HandleView.ets # Drag view component
│ │ │ ├── PanelController.ets # Panel controller
│ │ │ ├── PanelSlideListener.ets # Panel slide listener interface
│ │ │ ├── PanelState.ets # Panel state enumeration
│ │ │ ├── Types.ets # Type definitions
│ │ │ └── utils.ets # Utility functions
│ │ └── SlidingUpPanelLayout.ets # Panel layout component
│ ├── Index.ets # External APIs
├── README.md # Readme
├── README_zh.md # Readme
How to Contribute
If you find any problem when using the project, submit an issue or a PR.
License
This project is licensed under Apache License 2.0.