π Hidden HarmonyOS Development Treasures Revealed! Step-by-step Guide to Mastering the "One-to-Many" Map Navigation Case π
Hello everyone! I'm your old friend, and today I'm going to uncover some of those "deeply hidden" practical cases in the official HarmonyOS documentation! While working on a HarmonyOS project recently, I accidentally discovered this "one-to-many" map navigation development exampleβit's like finding a new continent! Let me give you an immersive experience with this super practical development template~
π‘ Key takeaway: This case perfectly demonstrates how to use a single codebase to handle multi-device adaptation for phones, foldables, tablets, and more. Let's dive right in!
1. What Makes This Case Awesome?
The official sample uses a map navigation app to showcase four core scenarios:
1οΈβ£ Smart Home Panel: Bottom panel for phones, auto-switches to sidebar for unfolded foldables
2οΈβ£ Route Planning Page: Layout adapts and morphs as the panel slides
3οΈβ£ Service Cards: 2x4 static grid cards work seamlessly across devices
4οΈβ£ Live Window: Dual display with capsule and card forms
The best part is that all effects are implemented using the ArkUI framework, fully adhering to the "develop once, deploy everywhere" principle!
2. Impressive Tricks That Blew My Mind
π Three-stage Panel Morphing on the Home Page (Code Snippet)
// Gesture controls panel height changes
.gesture(
PanGesture(this.panOptionHeight)
.onActionUpdate((event?: GestureEvent) => {
// Real-time calculation of panel height
let height = this.columnHeight - event.offsetY;
this.tempColumnHeight = height < Common.HEIGHT_LOW
? Common.HEIGHT_LOW
: (height > this.columnMaxHeight ? this.columnMaxHeight : height);
})
.onActionEnd(() => {
// Auto snap to the nearest stage
if(this.tempColumnHeight > ThresholdA) this.columnHeight = High;
else if(this.tempColumnHeight < ThresholdB) this.columnHeight = Low;
else this.columnHeight = Medium;
})
)
Effect Comparison:
- Phone portrait β Fixed height at the bottom
- Foldable unfolded β Floating sidebar
- Tablet landscape β Draggable adjustable position
π οΈ Service Card Development Tips
When creating a 2x4 grid of cards, the official sample uses this magic configuration:
ForEach(FormViewData.FUNCTIONS, (item) => {
Column() {
Image(item.icon)
.width($r('app.float.list_image_size'))
Text(item.desc)
.fontSize($r('app.float.list_desc_font_size'))
}
})
With resource files, you can achieve multi-device size adaptationβno more manual media queries!
3. Must-know Pitfalls for Beginners
-
Breakpoint Listening is Essential:
Use
GridContainer.onBreakpointChange
to handle different device sizes -
Gesture Conflict Solutions:
Set
.simultaneousGesture
to avoid conflicts between map sliding and panel dragging -
Dual-form Live Window:
Register both
liveView
andcapsule
forms to cover all scenarios
5. How to Get Started
- Search "One-to-Many Development Example" in the official documentation
- Download the complete demo project (includes 6 device preview modes)
- Focus on learning the
map
andliveview
modules - Customize by modifying the size resources in the resource directory
π One last heartfelt word: The official HarmonyOS case library is a real treasure trove! If you want to see case analysis in other fields, feel free to drop your requests in the comments~ Next time, I'll be digging into the "Smart Home Cross-device Linkage" practical case. If you're interested, remember to like, comment, and follow for updates!
Top comments (0)