๐[HarmonyOS Foldable Screen Development Treasure Guide] So many great things hidden in the official docs! A step-by-step guide to mastering hover state development๐
Hey friends! I'm your old pal XX. Recently, while working on a HarmonyOS foldable screen project, I stumbled upon some hidden gems in the official documentation! Turns out HarmonyOS has already prepared tons of practical samples. Today, I have to show you the right way to unlock "hover state" development. Don't miss out~
๐ฑ Let's start with the basics: What is the hover state?
It means folding the screen halfway like a laptop and placing it on the table. At this point, the screen automatically splits into upper and lower halves. HarmonyOS provides three ways to implement this. Let's go through them one by one!
1. For the lazy: FolderStack Component
(Suitable for simple scenarios like video/music players)
// The code is as simple as a sandwich cookie!
FolderStack({ upperItems: ['video'] }) {
VideoComponent().id('video') // Upper half: playback area
ControlPanel() // Lower half: control bar
}
โจ Practical Tips:
- You must set the
<font style="color:rgba(0, 0, 0, 0.9);background-color:rgb(252, 252, 252);">upperItems</font>
array to tell the system which components go to the upper half - The hover layout is only triggered in fullscreen mode (important!)
- Great for live streaming apps where the comment section automatically sinks to the lower half
2. Split-screen magic: FoldSplitContainer
(Must-see for dual-screen operation scenarios in games/office apps)
FoldSplitContainer({
primary: () => <GameScreen/>, // Upper half: game screen
secondary: () => <Joystick/> // Lower half: virtual joystick
})
๐ฎ Case Extensions:
- Food delivery app: upper half map + lower half merchant list
- Stock app: upper half K-line chart + lower half trading panel โ ๏ธ Note: The system enforces two/three-column layouts. For fancy layouts, check the next solution!
3. Advanced mode: Custom hover state
(Special angle hover shooting scenarios for camera apps)
// Focus on listening to these two key events!
display.on('foldStatusChange', (status) => {
if(status === 'half-folded' && landscape){
const foldRegion = display.getCurrentFoldCreaseRegion()
// Work your layout magic here...
}
})
๐ฅ Advanced Tips:
- Limit hover trigger to specific angles (e.g., 60ยฐ-120ยฐ)
- Dynamically adjust the camera viewfinder to avoid the crease
- Implement TikTok-style hover playback + floating comment window
๐ Pitfall Guide (Lessons Learned)
- Use
<font style="color:rgba(0, 0, 0, 0.9);background-color:rgb(252, 252, 252);">px2vp</font>
to convert units when getting crease region coordinates - Remember to off event listeners when the page is destroyed!
- The crease region on Huawei Mate X3 is 5px larger than on Pocket S (measured data)
- Disable bottom navigation bar clicks in hover state (official recommended solution)
๐ก Ultimate Solution for Indecisiveness
FolderStack | FoldSplit | Custom | |
---|---|---|---|
Development Difficulty | โญ | โญโญ | โญโญโญโญโญ |
Layout Flexibility | 80% | 60% | 100% |
Special Scenario Adaptation | โ | โ | โ |
Recommended Scenarios | Media | Tools | Innovative |
One last truth: The official sample code also hides black technologies like hover gesture recognition and multi-window linkage. If this post gets 100 likes, I'll immediately work on the next article! What mysterious issues have you encountered in development? Come battle it out in the comments section๐
Top comments (0)