DEV Community

ι™ˆζ¨
ι™ˆζ¨

Posted on

Hong Mong 5 Development Treasure Case Share more development instances Map Navigation

🌟 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;
  })
)
Enter fullscreen mode Exit fullscreen mode

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'))
  }
})
Enter fullscreen mode Exit fullscreen mode

With resource files, you can achieve multi-device size adaptationβ€”no more manual media queries!


3. Must-know Pitfalls for Beginners

  1. Breakpoint Listening is Essential: Use GridContainer.onBreakpointChange to handle different device sizes
  2. Gesture Conflict Solutions: Set .simultaneousGesture to avoid conflicts between map sliding and panel dragging
  3. Dual-form Live Window: Register both liveView and capsule forms to cover all scenarios

5. How to Get Started

  1. Search "One-to-Many Development Example" in the official documentation
  2. Download the complete demo project (includes 6 device preview modes)
  3. Focus on learning the map and liveview modules
  4. 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!

HarmonyOS #HarmonyOSDevelopment #OneToManyAdaptation #PracticalTutorial

Top comments (0)