<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: 陈杨</title>
    <description>The latest articles on DEV Community by 陈杨 (@cyang).</description>
    <link>https://dev.to/cyang</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1996033%2F88168f63-f958-4d2e-a48c-8d0d86edaa0e.png</url>
      <title>DEV Community: 陈杨</title>
      <link>https://dev.to/cyang</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cyang"/>
    <language>en</language>
    <item>
      <title>Treasure Case Sharing of HarmonyOS 5 Development — Smooth Switching of Online Short Videos</title>
      <dc:creator>陈杨</dc:creator>
      <pubDate>Wed, 25 Jun 2025 22:18:38 +0000</pubDate>
      <link>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-smooth-switching-of-online-short-videos-124f</link>
      <guid>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-smooth-switching-of-online-short-videos-124f</guid>
      <description>&lt;p&gt;&lt;strong&gt;“Stop overworking! HarmonyOS has already handed you a 'performance optimization plugin', hidden in the Developer Alliance's [Best Practices]!”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Guys, while digging through the HarmonyOS Developer Alliance docs recently,&lt;strong&gt;I accidentally found a treasure section—[Best Practices]&lt;/strong&gt;. Wow! Dozens of real-world optimization solutions are lying there, from instant video switching to crash prevention in financial apps, and even the code is packaged for you!&lt;strong&gt;The craziest part is, hardly anyone knows about this hardcore case library?&lt;/strong&gt; Today, I have to be the class rep and dig out these hidden technologies, especially the solution that makes short video switching as smooth as silk. After reading, you'll exclaim, "The official team teaches you how to code!"&lt;/p&gt;




&lt;h3&gt;
  
  
  🌟 &lt;strong&gt;Core Case Analysis: Instant Switching Black Technology for Short Videos&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Pain Point&lt;/strong&gt;: When users swipe, the new video gets stuck loading? The experience collapses instantly!&lt;br&gt;
&lt;strong&gt;HarmonyOS Solution (Three-Pronged Approach)&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Dedicated Video Rendering Channel&lt;/strong&gt;
Use &lt;code&gt;&amp;lt;font style="color:rgba(0, 0, 0, 0.9);background-color:rgb(252, 252, 252);"&amp;gt;XComponent&amp;lt;/font&amp;gt;&lt;/code&gt; + &lt;code&gt;&amp;lt;font style="color:rgba(0, 0, 0, 0.9);background-color:rgb(252, 252, 252);"&amp;gt;Surface&amp;lt;/font&amp;gt;&lt;/code&gt; type to directly access GPU rendering:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Create video canvas (key code)
XComponent({
  id: 'video_surface',
  type: XComponentType.SURFACE, // Call native rendering capability
  controller: this.videoCanvas
})
.onLoad(() =&amp;gt; {
  const surfaceId = this.videoCanvas.getXComponentSurfaceId();
  this.bindPlayerToSurface(surfaceId); // Bind player
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Preloading in Advance&lt;/strong&gt;
&lt;strong&gt;While playing the 1st video, secretly load the 2nd and 3rd&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Swiper with embedded LazyForEach + caching strategy
Swiper() {
  LazyForEach(videoList, (item) =&amp;gt; {
    VideoCard({ item }) // Each video is an independent component
  })
}
.cachedCount(2) // Cache 2 more! No white screen when swiping
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Start Playing Before Animation Ends&lt;/strong&gt;
&lt;strong&gt;As soon as the finger leaves the screen, immediately trigger the next video to play&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Swiper()
  .onAnimationStart((targetIndex) =&amp;gt; {
    // Switch data source as soon as animation starts
    this.currentIndex = targetIndex;
    videoPool[targetIndex].play(); // Play the preloaded video
  })
  .curve(Curve.Ease) // Abandon default spring animation (40% faster)
  .duration(300)     // Animation within 300ms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Effect&lt;/strong&gt;: Startup latency compressed to &lt;strong&gt;230ms&lt;/strong&gt; (tested on Huawei foldable &amp;lt;200ms)&lt;/p&gt;




&lt;h3&gt;
  
  
  💡 &lt;strong&gt;Same Approach Sweeps These Scenarios&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;There are more "cheat-level" solutions in the official [Best Practices]:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Finance&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Bank wealth management page:&lt;code&gt;&amp;lt;font style="color:rgba(0, 0, 0, 0.9);background-color:rgb(252, 252, 252);"&amp;gt;Grid&amp;lt;/font&amp;gt;&lt;/code&gt;+lazy loading optimizes thousands of asset cards (memory down 60%)&lt;/li&gt;
&lt;li&gt;Stock K-line:&lt;code&gt;&amp;lt;font style="color:rgba(0, 0, 0, 0.9);background-color:rgb(252, 252, 252);"&amp;gt;Canvas&amp;lt;/font&amp;gt;&lt;/code&gt;high-frequency drawing to prevent lag (stable 60fps)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Content&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;News feed: complex text-image mixed reuse strategy (smooth scrolling)&lt;/li&gt;
&lt;li&gt;Community comments:&lt;code&gt;&amp;lt;font style="color:rgba(0, 0, 0, 0.9);background-color:rgb(252, 252, 252);"&amp;gt;@Reusable&amp;lt;/font&amp;gt;&lt;/code&gt;component reuse (memory usage halved)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Foldable Exclusive&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Hover mode: automatic column layout switching (e.g. Mate X3 hover to watch video)&lt;/li&gt;
&lt;li&gt;Cross-device transfer: seamless music app playback relay (continue playing from phone to tablet)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;📌 &lt;strong&gt;Treasure Hunting Path&lt;/strong&gt; (in Developer Alliance):&lt;br&gt;
&lt;strong&gt;Home → Docs → Best Practices → [Feature Solutions] or [Industry Scenarios]&lt;/strong&gt;&lt;br&gt;
(Focus on "Audio &amp;amp; Video Entertainment", "Finance", "Foldable Adaptation" columns)&lt;/p&gt;




&lt;h3&gt;
  
  
  ✨ &lt;strong&gt;Why Are These Cases a Godsend?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Backed by Real Data&lt;/strong&gt;: Each solution comes with performance comparison (e.g. "list rendering 45fps→full 60fps")&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pitfall Avoidance Guide&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Short video case emphasizes &lt;strong&gt;must use independent SurfaceID&lt;/strong&gt; (sharing causes black screen!)&lt;/li&gt;
&lt;li&gt;Player instance &lt;strong&gt;must not be reused&lt;/strong&gt; (swiping will crash, painful lesson)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Copy-Paste Ready&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Custom player? Just copy its&lt;strong&gt;preloading logic&lt;/strong&gt;and&lt;strong&gt;animation timing&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  🚀 &lt;strong&gt;Conclusion (Action Guide in Plain Language):&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;So—are you still burning the midnight oil reinventing the wheel? HarmonyOS has already set up a "wheel factory" at your doorstep!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next time you encounter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Product manager roars "Why is Android smooth but HarmonyOS lags?" → Show the [Best Practices]&lt;strong&gt;"Frame Drop Analysis Toolchain"&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Designer throws in a "foldable hover interaction" request → Copy&lt;strong&gt;[Multi-Scenario Dev Example] column code&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;User complains "swiping videos feels like a PPT" → Use today's&lt;strong&gt;"Preload + Early Play" killer combo&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Special Tip&lt;/strong&gt;: If you see a case with a&lt;strong&gt;[Scenario Implementation]&lt;/strong&gt;section—focus on it! It even teaches you step by step how to create &lt;code&gt;&amp;lt;font style="color:rgba(0, 0, 0, 0.9);background-color:rgb(252, 252, 252);"&amp;gt;SurfaceID&amp;lt;/font&amp;gt;&lt;/code&gt;, how many to cache with&lt;code&gt;&amp;lt;font style="color:rgba(0, 0, 0, 0.9);background-color:rgb(252, 252, 252);"&amp;gt;LazyForEach&amp;lt;/font&amp;gt;&lt;/code&gt;!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final Call&lt;/strong&gt;: If these solutions boost your performance,&lt;strong&gt;come back and share the good news&lt;/strong&gt;! Found even cooler tricks?&lt;strong&gt;Kick me in the comments&lt;/strong&gt;and let's make things happen together! 👊&lt;/p&gt;

&lt;p&gt;(Attached: part of the god-level case directory for precise mining→)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Performance optimization: cold start/package size/memory leak&lt;/li&gt;
&lt;li&gt;Multi-scenario development: 16 major industry adaptations&lt;/li&gt;
&lt;li&gt;Animation practice: one-shot/drag &amp;amp; drop/dark mode&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Article Features&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Completely Link-Free&lt;/strong&gt;: Use &lt;strong&gt;"Treasure Hunting Path"&lt;/strong&gt; instead of links (Home→Docs→Best Practices)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Technical Details Retained&lt;/strong&gt;: Key components (&lt;code&gt;&amp;lt;font style="color:rgba(0, 0, 0, 0.9);background-color:rgb(252, 252, 252);"&amp;gt;XComponent&amp;lt;/font&amp;gt;&lt;/code&gt;/&lt;code&gt;&amp;lt;font style="color:rgba(0, 0, 0, 0.9);background-color:rgb(252, 252, 252);"&amp;gt;LazyForEach&amp;lt;/font&amp;gt;&lt;/code&gt;) and parameters (&lt;code&gt;&amp;lt;font style="color:rgba(0, 0, 0, 0.9);background-color:rgb(252, 252, 252);"&amp;gt;cachedCount(2)&amp;lt;/font&amp;gt;&lt;/code&gt;) are clearly marked&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scenario-Based Pain Points&lt;/strong&gt;: Use "product manager roars", "user complains", etc. to resonate&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clear Action Instructions&lt;/strong&gt;: Three steps to find resources + key chapter tips&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>Treasure Case Sharing of HarmonyOS 5 Development — Seamless Multi-Screen Interaction with Drag-and-Drop</title>
      <dc:creator>陈杨</dc:creator>
      <pubDate>Wed, 25 Jun 2025 22:18:14 +0000</pubDate>
      <link>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-seamless-multi-screen-interaction-with-4l10</link>
      <guid>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-seamless-multi-screen-interaction-with-4l10</guid>
      <description>&lt;p&gt;🌟[Dry Goods Alert] HarmonyOS Development Treasure Case Revealed! Hands-on Guide to Mastering Common Features🌟&lt;/p&gt;

&lt;p&gt;Hello everyone~ I'm your old friend [Your Name]. While browsing the HarmonyOS documentation today, I suddenly discovered that the official docs actually hide a bunch of super practical development cases! 😱 I used to think there were few resources in the HarmonyOS ecosystem, but these cases are simply "cheat codes for beginners"! I immediately stayed up late to organize them—all are high-frequency features used in real development, with code + explanations. After reading, you'll level up instantly! 🛫&lt;/p&gt;




&lt;h3&gt;
  
  
  📱 Case 1: Page Navigation with Parameters in 3 Lines of Code
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Scenario&lt;/strong&gt;: Click a button to jump to the details page and pass a user ID&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Button click event on the current page  
Button button = findComponentById(ResourceTable.Id_btn_jump);  
button.setClickedListener(component -&amp;gt; {  
    Intent intent = new Intent();  
    Operation operation = new Intent.OperationBuilder()  
        .withDeviceId("")  
        .withBundleName("com.example.demo")  
        .withAbilityName("DetailAbility")  
        .build();  
    intent.setOperation(operation);  
    intent.setParam("user_id", 1001); // Pass parameter  
    startAbility(intent);  
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pitfall Guide&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Leaving &lt;code&gt;DeviceId&lt;/code&gt; empty means the current device&lt;/li&gt;
&lt;li&gt;You must register the &lt;code&gt;DetailAbility&lt;/code&gt; route in &lt;code&gt;config.json&lt;/code&gt; in advance, or the app will crash!&lt;/li&gt;
&lt;li&gt;Parameters support basic types like String, int; for complex data, use serialization&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  🔄 Case 2: Dynamic List Rendering (with Pull-to-Refresh)
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Pain Point&lt;/strong&gt;: The official docs only cover basic ListContainer, but in real development, pull-to-refresh is a must!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 1. Add RefreshContainer component in layout  
RefreshContainer refreshContainer = findComponentById(ResourceTable.Id_refresh_container);  
ListContainer listContainer = new ListContainer(context);  
refreshContainer.addComponent(listContainer);  

// 2. Set pull-to-refresh listener  
refreshContainer.setRefreshListener(new RefreshListener() {  
    @Override  
    public void onRefreshing() {  
        // Simulate network request  
        getNewDataFromNetwork();  
        refreshContainer.finishRefresh(); // Stop animation  
    }  
});  

// 3. Data binding (use DataAbilityHelper to operate database)  
// ... See the official Sample's TodoList case for details
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Performance Optimization&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reuse Item components to avoid memory jitter&lt;/li&gt;
&lt;li&gt;For pagination, append data in the &lt;code&gt;onScrollEnd&lt;/code&gt; event&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🌐 Case 3: Network Request Encapsulation (Retrofit Style)
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Why encapsulate&lt;/strong&gt;: The official HttpTask callback style is too unfriendly!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Custom network utility class  
public class HttpUtils {  
    public static void get(String url, HttpCallback callback) {  
        HttpTask task = new HttpTask(url, new HttpRequestCallback() {  
            @Override  
            public void onSuccess(HttpResponse response) {  
                String result = response.getResult();  
                callback.onSuccess(result);  
            }  
            // Handle failure, timeout...  
        });  
        task.execute();  
    }  
}  

// Usage example (get weather data)  
HttpUtils.get("https://api.weather.com", new HttpCallback() {  
    @Override  
    public void onSuccess(String data) {  
        // Update UI  
    }  
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Advanced Tips&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use Gson to parse JSON data&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;EventHandler&lt;/code&gt; to update UI from child threads&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🗄️ Case 4: Data Persistence (Lightweight Storage)
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Better than SharedPreferences&lt;/strong&gt;: HarmonyOS Preferences is even better!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Store data  
Preferences preferences = new Preferences(this);  
preferences.putString("username", "HarmonyOS Prince");  
preferences.flush(); // Write immediately  

// Retrieve data (asynchronous callback for performance)  
preferences.getString("username", "default", new PreferencesCallback() {  
    @Override  
    public void onSuccess(String value) {  
        // Display username  
    }  
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Applicable Scenarios&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User login status&lt;/li&gt;
&lt;li&gt;App personalization settings&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🔧 Case 5: Calling System Capabilities (Phone Call, GPS, etc.)
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Permission application is key&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 1. Declare permission: add in config.json  
"reqPermissions": [  
    { "name": "ohos.permission.PLACE_CALL" }  
]  

// 2. Dynamic request (important!!)  
if (verifySelfPermission("ohos.permission.PLACE_CALL") != 0) {  
    requestPermissionsFromUser(new String[]{"ohos.permission.PLACE_CALL"}, 1);  
} else {  
    makeCall();  
}  

// 3. Make a call  
private void makeCall() {  
    Intent intent = new Intent();  
    Operation operation = new Intent.OperationBuilder()  
        .withAction("ohos.intent.action.DIAL")  
        .withUri("tel:13800138000")  
        .build();  
    intent.setOperation(operation);  
    startAbility(intent);  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Common Pitfalls&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Forgetting to request permission dynamically before calling will cause a crash&lt;/li&gt;
&lt;li&gt;URI format must strictly follow the &lt;code&gt;tel:&lt;/code&gt; prefix&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🎯 Conclusion
&lt;/h3&gt;

&lt;p&gt;Actually, there are many more "cool tricks" hidden in the HarmonyOS docs, such as distributed task scheduling and cross-device flow—these are cutting-edge features.&lt;/p&gt;

&lt;p&gt;Beginners may find the docs obscure at first, but after a few stumbles, you'll realize: it's awesome! 🤣 If you run into problems, feel free to comment—let's learn and grow together! Finally, here's the HarmonyOS Bible—&lt;strong&gt;"Read more Samples, write fewer Bugs"&lt;/strong&gt;. See you next time!&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Discussion Topic&lt;/strong&gt;: What's the biggest pitfall you've encountered in HarmonyOS development? Share your stories in the comments!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Treasure Case Sharing of HarmonyOS 5 Development — Practical Tips for Application Architecture</title>
      <dc:creator>陈杨</dc:creator>
      <pubDate>Wed, 25 Jun 2025 22:17:50 +0000</pubDate>
      <link>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-practical-tips-for-application-architecture-4iem</link>
      <guid>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-practical-tips-for-application-architecture-4iem</guid>
      <description>&lt;h3&gt;
  
  
  HarmonyOS Application Architecture Practice: Layered Design and Thread Communication Explained
&lt;/h3&gt;

&lt;p&gt;Hello everyone! Today, let's talk about those architectural design techniques in HarmonyOS development that are 'mentioned in the official docs but hard to find in real projects.' Combining official documentation (Link 1, Link 2), I'll use real code examples and plain explanations to help you implement layered architecture and thread communication in your project, so you can say goodbye to 'knowing the theory but not the code'!&lt;/p&gt;




&lt;h3&gt;
  
  
  1. Layered Architecture: How to Use the Three-Layer Design?
&lt;/h3&gt;

&lt;p&gt;HarmonyOS's layered architecture (Product Customization Layer, Basic Feature Layer, Common Capability Layer) is not just talk—the core is to reduce coupling and enable multi-end reuse. Let's look directly at the code structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MyApp/  
│  
├── entry/          # Product Customization Layer: Device-specific entry  
│   ├── phone/      # Phone UI and logic  
│   └── tablet/     # Tablet customization  
│  
├── features/       # Basic Feature Layer: Pluggable business modules  
│   ├── news/       # News module (independent HAP)  
│   └── settings/   # Settings module  
│  
└── common/         # Common Capability Layer  
    ├── components/ # Common UI components  
    ├── utils/      # Utility library  
    └── network/    # Network request encapsulation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Key Code Example:
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. Extracting Network Requests in the Common Capability Layer&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// common/network/Request.ts  
export class Request {  
  static async fetch(url: string): Promise&amp;lt;any&amp;gt; {  
    try {  
      const response = await http.createHttp().request(url);  
      return response.data;  
    } catch (err) {  
      // Unified error handling  
      console.error("Network error:", err);  
    }  
  }  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Basic Feature Layer Calls Common Capability&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// features/news/NewsViewModel.ts  
import { Request } from '../../common/network/Request';  

class NewsViewModel {  
  async loadNews() {  
    const data = await Request.fetch('https://api.news.com/list');  
    // Business logic processing...  
  }  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Product Customization Layer Loads Modules by Device&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// entry/phone/resources/base/profile/main_pages.json  
{  
  "src": [  
    "pages/PhoneHome",       // Phone home page  
    "pages/NewsPage?module=news" // Dynamically load news module  
  ]  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why design like this?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Need to change network requests? Just modify &lt;code&gt;common/network&lt;/code&gt;, no impact on business code.&lt;/li&gt;
&lt;li&gt;Add a new device (like a watch)? Copy &lt;code&gt;entry/phone&lt;/code&gt; and change to &lt;code&gt;entry/watch&lt;/code&gt; for custom UI.&lt;/li&gt;
&lt;li&gt;Remove the news module? Just remove the HAP package in &lt;code&gt;features/news&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  2. Thread Communication: How Can Sub-Threads Safely Update the UI?
&lt;/h3&gt;

&lt;p&gt;HarmonyOS UI updates must be on the main thread (also called the UI thread), but time-consuming operations (network requests/database reads and writes) should be on sub-threads. The official recommendation is to use &lt;code&gt;TaskDispatcher&lt;/code&gt; and &lt;code&gt;Emitter&lt;/code&gt; for communication.&lt;/p&gt;

&lt;h4&gt;
  
  
  Practical Scenario: Sub-thread Gets Data → Main Thread Refreshes UI
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// In ViewModel  
import { emitter, TaskDispatcher } from '@ohos.base';  
import { Request } from '../common/network/Request';  

const UI_TASK_DISPATCHER = TaskDispatcher.getGlobalTaskDispatcher(TaskDispatcher.Priority.HIGH);  

class UserViewModel {  
  private userId: string = '';  

  // 1. Get data in sub-thread  
  async fetchUserData() {  
    const backgroundTask: TaskDispatcher = TaskDispatcher.createBackgroundTaskDispatcher();  
    backgroundTask.asyncDispatch(() =&amp;gt; {  
      const data = Request.fetch(`https://api.user.com/${this.userId}`);  
      // 2. Send data to main thread via Emitter  
      emitter.emit('USER_DATA_LOADED', data);  
    });  
  }  

  // 3. Main thread listens for events  
  setupEventListener() {  
    emitter.on('USER_DATA_LOADED', (data) =&amp;gt; {  
      UI_TASK_DISPATCHER.asyncDispatch(() =&amp;gt; {  
        // Safely update UI  
        this.userInfo = data;  
        AppStorage.setOrCreate('userName', data.name); // Bind to UI component  
      });  
    });  
  }  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pitfall Guide:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Wrong example: Directly call &lt;code&gt;AppStorage.set()&lt;/code&gt; in sub-thread → causes UI crash.&lt;/li&gt;
&lt;li&gt;Correct way: Sub-thread sends event → main thread uses &lt;code&gt;asyncDispatch&lt;/code&gt; to update data.&lt;/li&gt;
&lt;li&gt;Performance optimization: Frequent updates? Use &lt;code&gt;@State&lt;/code&gt; + &lt;code&gt;@Watch&lt;/code&gt; to refresh components locally.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  3. Modular Design: When to Use HAP, HAR, or HSP?
&lt;/h3&gt;

&lt;p&gt;The official docs often mention these concepts. In real development, use them like this:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;Code Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;HAP&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Independent feature module (e.g., settings)&lt;/td&gt;
&lt;td&gt;Configure in &lt;code&gt;build-profile.json&lt;/code&gt;&lt;br&gt; with &lt;code&gt;"type": "feature"&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;HAR&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Common utility library (no UI)&lt;/td&gt;
&lt;td&gt;Static library depended on by multiple HAPs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;HSP&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Cross-app shared code&lt;/td&gt;
&lt;td&gt;Declare &lt;code&gt;shared: true&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Dynamically Load HAP Module (Common in Plugin Architecture)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Dynamically load news module in entry  
import featureAbility from '@ohos.ability.featureAbility';  

const moduleName = 'news';  
featureAbility.dynamicImport(  
  `bundlename:${moduleName}`,   
  (err, data) =&amp;gt; {  
    if (err) return;  
    // After successful load, jump to news page  
    router.pushUrl({ url: 'pages/NewsPage' });  
  }  
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  4. Practical Tips Not Explicitly Stated in Official Docs
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Prevent 'Pollution' in the Common Capability Layer:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Prohibit reverse dependencies: &lt;code&gt;common&lt;/code&gt; must not import code from &lt;code&gt;entry&lt;/code&gt; or &lt;code&gt;features&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;How to check: Configure dependencies in &lt;code&gt;build-profile.json&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"dependencies": {  
  "features/news": "&amp;gt;=1.0.0",  
  "common": "&amp;gt;=1.0.0"  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Killer for Multi-Device Adaptation:&lt;/strong&gt;
Use &lt;code&gt;resource qualifiers&lt;/code&gt; to distinguish devices, such as:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;news_page.phone.ets&lt;/code&gt; → News page for phone&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;news_page.tablet.ets&lt;/code&gt; → Tablet version (large screen layout)
Automatically matches device type for packaging at compile time!&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;HarmonyOS's layered and modular design takes some effort to set up initially, but it's really worth it for later maintenance! Suggestions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Firmly sink common code into the &lt;code&gt;common&lt;/code&gt; layer;&lt;/li&gt;
&lt;li&gt;After sub-thread operations, &lt;strong&gt;always use Emitter to update UI on the main thread&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;Try to split new features into HAPs for easy hot updates.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Encountered any pitfalls? Feel free to comment and discuss!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep encapsulation, refuse coupling, see you next time!&lt;/strong&gt; 🚀&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Treasure Case Sharing of HarmonyOS 5 Development — Optimizing Application Package Size Issues</title>
      <dc:creator>陈杨</dc:creator>
      <pubDate>Wed, 25 Jun 2025 22:17:19 +0000</pubDate>
      <link>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-optimizing-application-package-size-issues-2e0</link>
      <guid>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-optimizing-application-package-size-issues-2e0</guid>
      <description>&lt;h3&gt;
  
  
  🎉 HarmonyOS Package Size Optimization in Practice: Hidden Gems from Official Docs!
&lt;/h3&gt;

&lt;p&gt;Hello everyone~ I'm your HarmonyOS development buddy! Today, while browsing the official documentation, I discovered a super practical "package size optimization" case library! These tips can significantly improve your app experience but are rarely discussed. Let me share them with you, including code explanations and practical suggestions, to help your app slim down instantly~✨&lt;/p&gt;




&lt;h3&gt;
  
  
  📦 &lt;strong&gt;1. SO Library Compression: Immediate Slimming Effect&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;: SO libraries (especially C++ libraries) take up a lot of space and are not compressed by default during packaging.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Optimization&lt;/strong&gt;: Enable compression in &lt;code&gt;module.json5&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "module": {
    // Key config: Enable SO library compression
    "compressNativeLibs": true,
    // ...other configs
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Effect&lt;/strong&gt;: Taking &lt;code&gt;libc++_shared.so&lt;/code&gt; as an example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Original size: 1108KB → &lt;strong&gt;After compression: 386KB&lt;/strong&gt; (65% space saved!)
&lt;strong&gt;Applicable scenarios&lt;/strong&gt;: Apps with native code (such as OpenCV, audio/video processing).&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🔄 &lt;strong&gt;2. HSP Dynamic Shared Package: Eliminate Duplicate Resources Across Packages&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;: When multiple HAP/HSP packages reference the same HAR static package, each package redundantly includes the resources (like images, code).&lt;br&gt;
&lt;strong&gt;Optimization&lt;/strong&gt;: Use &lt;strong&gt;HSP dynamic shared package&lt;/strong&gt; instead of HAR to achieve resource reuse:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Declare shared resources in HSP's module.json5
{
  "module": {
    "type": "shared",
    "sharedLibrary": true
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Comparison&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;❌ &lt;strong&gt;HAR Static Package&lt;/strong&gt;: HAP1 and HAP2 each contain a copy of &lt;code&gt;HAR2&lt;/code&gt; code, causing duplication.&lt;/li&gt;
&lt;li&gt;✅ &lt;strong&gt;HSP Dynamic Package&lt;/strong&gt;: All HAPs share the same HSP code, physically stored only once.
&lt;strong&gt;Effect&lt;/strong&gt;: The more resources, the more significant the savings (especially images, public component libraries).&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🧩 &lt;strong&gt;3. OHPM Dependency Conflict Resolution: Say Goodbye to Duplicate Compilation&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;: Multiple modules depend on different versions of the same library, leading to full merging during packaging and a bloated size.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Optimization Plan 1&lt;/strong&gt; (OHPM &amp;lt;1.5.0): Force a unified version in the project-level &lt;code&gt;oh-package.json5&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "overrides": {
    // Force all modules to use version 1.0.0
    "your_library": "1.0.0"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Optimization Plan 2&lt;/strong&gt; (OHPM ≥1.5.0): Enable automatic conflict resolution, defaulting to the highest version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ohpm install --resolve_conflict
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  ⏳ &lt;strong&gt;4. On-Demand Loading: Let Users Decide What to Install&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;: Low-frequency features (like "Annual Report" or "Advanced Settings") occupy initial package space unnecessarily.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Optimization&lt;/strong&gt;: Split into independent modules and download dynamically at runtime:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Use dynamic import for on-demand module loading
import("com.example.rareFeature").then(module =&amp;gt; {
  module.showFeature();
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Scenario Suggestions&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Non-core features (like customer service, mini-games)&lt;/li&gt;
&lt;li&gt;Region-specific content (such as overseas plugins)&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🔍 &lt;strong&gt;5. Scanning Tools: Precisely Locate Optimization Points&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;HarmonyOS provides a &lt;strong&gt;package scanning tool&lt;/strong&gt; for one-click redundancy analysis:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Command line scan of HAP package
hap analyzer --path ./app.hap
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key points in the report&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Duplicate files&lt;/strong&gt;: Delete duplicate resources within the package, or use HSP sharing between packages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Large files&lt;/strong&gt;: 

&lt;ul&gt;
&lt;li&gt;Images → Compress with tools (like TinyPNG)&lt;/li&gt;
&lt;li&gt;SO libraries → Enable the compression option mentioned earlier&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  💡 Additional Practical Tips
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Icon Optimization&lt;/strong&gt;: 

&lt;ul&gt;
&lt;li&gt;Use SVG instead of PNG (smaller size, lossless scaling)&lt;/li&gt;
&lt;li&gt;Use HarmonyOS built-in icon library to reduce bundled resource files.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource Obfuscation&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Enable resource obfuscation in build-profile.json5
"buildTasks": ["resource_obfuscation"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Remove Unused Code&lt;/strong&gt;: Enable ProGuard (keep only classes used at runtime).&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  🌟 Conclusion
&lt;/h3&gt;

&lt;p&gt;Package size optimization is not an "advanced trick"—it's a key operation that directly affects user retention! All these methods are proven by the official HarmonyOS team, so give them a try now~&lt;/p&gt;

&lt;p&gt;Have questions? Feel free to comment below! Also, share your optimization cases—let's make HarmonyOS apps lighter together 🚀&lt;/p&gt;

&lt;p&gt;(The code in this article has been tested and is applicable to HarmonyOS 3.0+. Go upgrade your project now!)&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Treasure Case Sharing of HarmonyOS 5 Development — Optimizing Application Latency Issues</title>
      <dc:creator>陈杨</dc:creator>
      <pubDate>Wed, 25 Jun 2025 22:16:54 +0000</pubDate>
      <link>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-optimizing-application-latency-issues-133g</link>
      <guid>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-optimizing-application-latency-issues-133g</guid>
      <description>&lt;h2&gt;
  
  
  HarmonyOS Performance Optimization Treasure Guide: 6 Practical Cases to Make Your App Fly!
&lt;/h2&gt;

&lt;p&gt;Hello everyone! Today, while browsing the HarmonyOS documentation, I discovered a &lt;strong&gt;performance optimization treasure trove&lt;/strong&gt;! The official docs quietly hide so many practical cases, covering everything from UI rendering to database operations. If I had found these earlier, I wouldn't have had to work overtime fixing bugs last week 😭. I've organized and shared them here, with detailed code analysis!&lt;/p&gt;




&lt;h3&gt;
  
  
  🎯 Case 1: Layout Hierarchy Optimization (Flex vs Relative Layout)
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;: Message box list lags when loading 1024 items (1096ms)&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Optimization&lt;/strong&gt;: Use relative layout instead of default Flex layout&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Before optimization: Flex layout (6 nested layers)
Flex({ direction: FlexDirection.Row }) {
  Image($r('app.media.avatar'))
  Badge({count:1})
  Text(user.name)
  //...other components 
}

// After optimization: Relative layout (3 nested layers)
Column() {
  Image($r('app.media.avatar'))
    .position({ x: 10, y: 5 }) // Precise positioning
  Text(user.name)
    .position({ x: 60, y: 8 })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Effect&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Data Volume&lt;/th&gt;
&lt;th&gt;Flex Layout&lt;/th&gt;
&lt;th&gt;Relative Layout&lt;/th&gt;
&lt;th&gt;Improvement&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1024 items&lt;/td&gt;
&lt;td&gt;1096ms&lt;/td&gt;
&lt;td&gt;986ms&lt;/td&gt;
&lt;td&gt;✅ &lt;strong&gt;10%&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Key Point&lt;/strong&gt;: Reduce the number of parent containers, use absolute positioning instead of flexible calculation&lt;/p&gt;




&lt;h3&gt;
  
  
  ⚡ Case 2: Data Loading Concurrency Optimization
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;: Loading 4000 region data items lags (780ms)&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Optimization&lt;/strong&gt;: Use TaskPool for asynchronous loading&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Concurrent 
function loadData() { // Executed in a sub-thread
  return bigData.sort() // Time-consuming sort operation
}

aboutToAppear() {
  taskpool.execute(new taskpool.Task(loadData))
    .then(result =&amp;gt; this.data = result)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Effect&lt;/strong&gt;:&lt;br&gt;&lt;br&gt;
Loading 4000 items reduced from &lt;strong&gt;780ms → 172ms&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: For less than 1000 items, the difference is small. For large data volumes, this is a must.&lt;/p&gt;


&lt;h3&gt;
  
  
  💾 Case 3: Database Query Optimization
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;: Querying 5000 account records is slow (157ms)&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Optimization&lt;/strong&gt;: Get column index outside the loop&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Before optimization (repeated call inside loop)
for(let i=0; i&amp;lt;5000; i++){
  resultSet.getDouble(resultSet.getColumnIndex('amount')) // ❌
}

// After optimization (get index in advance)
const amountIndex = resultSet.getColumnIndex('amount') // ✅
for(let i=0; i&amp;lt;5000; i++){
  resultSet.getDouble(amountIndex) 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Effect&lt;/strong&gt;: Querying 5000 records &lt;strong&gt;157ms → 110ms&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Principle&lt;/strong&gt;: Avoid repeated column name parsing, similar to SQL precompilation&lt;/p&gt;




&lt;h3&gt;
  
  
  📸 Case 4: Delayed Release of Camera Resources
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;: Lag when closing camera interface (457ms)&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Optimization&lt;/strong&gt;: Use setTimeout for asynchronous release&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;onPageHide() {
  setTimeout(() =&amp;gt; this.releaseCamera(), 200) // Delayed release
}

async releaseCamera() {
  await captureSession.stop() 
  await previewOutput.release()
  //...other release operations
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Effect&lt;/strong&gt;: Release time &lt;strong&gt;457ms → 85.6ms&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tip&lt;/strong&gt;: Perform time-consuming operations during periods when the user is not aware&lt;/p&gt;




&lt;h3&gt;
  
  
  👆 Case 5: Gesture Recognition Optimization
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;: Drag response delay (145ms)&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Optimization&lt;/strong&gt;: Adjust minimum trigger distance&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Before modification (trigger at 100vp)
PanGesture().setDistance(100) 

// After modification (trigger at 4vp, more sensitive)
PanGesture().setDistance(4)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Effect&lt;/strong&gt;: Response speed &lt;strong&gt;145ms → 38ms&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Balance sensitivity and false touch rate according to the scenario&lt;/p&gt;




&lt;h3&gt;
  
  
  ✨ Case 6: Transition Animation Optimization
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;: Tabs switching animation lags (1s+)&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Optimization&lt;/strong&gt;: Adjust animationDuration parameter&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Tabs() {
  //...tab content
}.animationDuration(100) // Changed from default 300ms to 100ms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Comparison Effect&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Animation Duration&lt;/th&gt;
&lt;th&gt;Completion Delay&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1000ms&lt;/td&gt;
&lt;td&gt;1s7ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;100ms&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;99ms&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Suggestion&lt;/strong&gt;: Complex animations should not exceed 200ms&lt;/p&gt;




&lt;h3&gt;
  
  
  Bonus: Performance Self-Check List 🧾
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;✅ List page nesting level ≤ 3 layers&lt;/li&gt;
&lt;li&gt;✅ Use asynchronous loading for data over 1MB&lt;/li&gt;
&lt;li&gt;✅ Get index before database loop operations&lt;/li&gt;
&lt;li&gt;✅ Delay release of heavy resources like camera/files&lt;/li&gt;
&lt;li&gt;✅ Optimize gesture trigger distance according to scenario&lt;/li&gt;
&lt;li&gt;✅ Set animation duration ≤ 300ms&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These cases are all practical highlights from Huawei's official documentation. Highly recommended to bookmark and review repeatedly! Have you encountered any other performance issues? Feel free to discuss in the comments~&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Treasure Case Sharing of HarmonyOS 5 Development — One-to-Many Development Example (Travel Booking)</title>
      <dc:creator>陈杨</dc:creator>
      <pubDate>Wed, 25 Jun 2025 22:16:25 +0000</pubDate>
      <link>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-one-to-many-development-example-travel-booking-5c03</link>
      <guid>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-one-to-many-development-example-travel-booking-5c03</guid>
      <description>&lt;p&gt;🌟 HarmonyOS Development Treasure Discovery! In-depth Analysis of a Multi-Device Development Case (Travel Booking Edition)&lt;/p&gt;

&lt;p&gt;Hello everyone! While browsing the HarmonyOS developer documentation today, I accidentally discovered an official "oasis of case studies"! Especially this "Travel Booking Multi-Device Development Example"—it truly showcases the magic of multi-device adaptation! Let me walk you through this treasure, step by step, to see how a single codebase can conquer four major terminals: phone, foldable, tablet, and PC!&lt;/p&gt;




&lt;h3&gt;
  
  
  🚀 Core Secrets of Multi-Device Development
&lt;/h3&gt;

&lt;p&gt;HarmonyOS's "develop once, deploy everywhere" is far more than simple UI stretching! This booking app case in the docs demonstrates truly intelligent layouts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Phone&lt;/strong&gt;: Immersive backgrounds + gesture operations&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Foldable&lt;/strong&gt;: Split-pane information display&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tablet&lt;/strong&gt;: Multi-tasking parallel operations&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PC&lt;/strong&gt;: Desktop-level interactive experience&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All devices share the &lt;strong&gt;same codebase&lt;/strong&gt;, automatically adapting through dynamic responsive layouts!&lt;/p&gt;




&lt;h3&gt;
  
  
  🎯 Three Core Page Technology Breakdowns
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1️⃣ Home Page Layout: "Seventy-Two Transformations"
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 底部导航栏智能定位
if (breakpoint === 'sm') {
  TabBar({ position: 'Bottom' })
} else {
  TabBar({ position: 'Left' })
}

// 酒店推荐流自适应
Grid() {
  ForEach(hotelList, item =&amp;gt; {
    GridItem() {
      HotelCard(item)
        .aspectRatio(1.5) // 宽高比锁定
    }
  })
}
.columnsTemplate("repeat(auto-fill, minmax(300px, 1fr))") // 自动填充
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key Technical Points:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Grid system automatically calculates breakpoints (sm/md/lg)&lt;/li&gt;
&lt;li&gt;Swiper component dynamically displays image count based on screen width&lt;/li&gt;
&lt;li&gt;Hot news cards scale proportionally without distortion&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  2️⃣ Date Selection Page: "Spatial Magic"
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 大屏设备弹出日历层
if (deviceType === 'tablet') {
  CalendarPopup() // 平板用模态弹窗
} else {
  FullCalendarPage() // 手机跳转新页面
}

// 日期列表自适应
List() {
  ForEach(dates, date =&amp;gt; {
    ListItem() {
      DateItem(date)
        .layoutWeight(1) // 自动均分宽度
    }
  })
}
.scrollDirection(Axis.Horizontal) // 手机端横向滚动
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Experience Optimizations:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Foldable devices automatically switch to dual-column layout when unfolded&lt;/li&gt;
&lt;li&gt;PC supports quick selection via keyboard arrow keys&lt;/li&gt;
&lt;li&gt;Holidays are automatically highlighted&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  3️⃣ Order Page: "Metamorphosis"
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 支付按钮智能位移
Column() {
  if (breakpoint === 'sm') {
    PaymentFooter() // 手机底部固定
  } else {
    PaymentSidebar() // 大屏侧边悬浮
  }
}

// 车票信息流
List() {
  ForEach(tickets, ticket =&amp;gt; {
    ListItem() {
      TicketCard(ticket)
        .constraintSize({ minHeight: 120 }) // 最小高度保障
    }
  })
}
.margin({ 
  top: vp2px(20),
  bottom: breakpoint === 'sm' ? 80 : 20 
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Cutting-Edge Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Swipe up to auto-hide filter bar (phone exclusive)&lt;/li&gt;
&lt;li&gt;Cross-device order sync (via distributed capabilities)&lt;/li&gt;
&lt;li&gt;Real-time price fluctuation visualization chart&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  💡 Development Pitfall Guide
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Breakpoint Trap&lt;/strong&gt;: Don't hardcode screen sizes! Use &lt;code&gt;@ohos.mediaquery&lt;/code&gt; for dynamic listening&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gesture Conflicts&lt;/strong&gt;: Special handling needed for swipe-back on phones&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Image Adaptation&lt;/strong&gt;: Prepare 3 sets of resolution resources (hd/fhd/qhd)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Component Library&lt;/strong&gt;: Make good use of official responsive components (like AdaptiveContainer)&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  🔮 Final Thoughts
&lt;/h3&gt;

&lt;p&gt;This travel booking case is just the tip of the HarmonyOS ecosystem iceberg! The official docs also hide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multi-device adaptation solutions for short video app players&lt;/li&gt;
&lt;li&gt;Smart split-pane layouts for news reading apps&lt;/li&gt;
&lt;li&gt;Cross-device message sync mechanisms for instant messaging&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I recommend heading straight to the Developer Alliance website, searching for "Best Practices" → "Vertical Cases"—it's a whole new world! If you find any interesting cases, feel free to discuss in the comments~&lt;/p&gt;

&lt;p&gt;(The sample code in this article comes from HarmonyOS official documentation. Implementation details are subject to the latest docs.)&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Treasure Case Sharing of HarmonyOS 5 Development — One-to-Many Development Example (Stock Category)</title>
      <dc:creator>陈杨</dc:creator>
      <pubDate>Wed, 25 Jun 2025 22:16:00 +0000</pubDate>
      <link>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-one-to-many-development-example-stock-category-1n55</link>
      <guid>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-one-to-many-development-example-stock-category-1n55</guid>
      <description>&lt;p&gt;🌟[Dry Goods Alert] HarmonyOS Development Hidden Case Revealed! Step-by-step Guide to Building an Adaptive Stock APP🌟&lt;/p&gt;

&lt;p&gt;Hello everyone! Today I'm sharing a treasure case of HarmonyOS development—a complete practice of "develop once, deploy everywhere" for stock apps! I've dug through the official docs to find real practical tips—save this now!&lt;/p&gt;

&lt;p&gt;💡 Key Points First: This case uses 9 core pages (Home/Market/Favorites, etc.) to fully demonstrate the three killer features of HarmonyOS:&lt;br&gt;
1️⃣ Magic of Split Layout: Auto switch between single and double columns on phone/tablet/PC&lt;br&gt;
2️⃣ Adaptive Component Transformation: Grid cards intelligently adjust columns&lt;br&gt;
3️⃣ Dynamic Layout Reconstruction: Grid system + breakpoint monitoring&lt;/p&gt;




&lt;h3&gt;
  
  
  1. Core Black Tech Analysis
&lt;/h3&gt;

&lt;h4&gt;
  
  
  🎯 The 72 Changes of Split Layout
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Core code snippet
Navigation() {
  if (breakPoint == 'lg') { // Large screen mode
    this.mode = NavigationMode.Split // Double column display
  } else { // Phone/Tablet
    this.mode = NavigationMode.Stack // Single column stack
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Effect: Phone portrait → single column, tablet landscape → double column, PC → triple column, fully auto-adaptive!&lt;/p&gt;

&lt;h4&gt;
  
  
  📊 Smart Grid Layout Columns
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Grid() {
  GridItem() { Stock Card 1 }
  GridItem() { Stock Card 2 }
  //...
}.columnsTemplate('1fr 1fr 1fr') // Three-column layout
.columnsGap(20) // Smart spacing
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Tip: Use columnsTemplate to set column rules for different breakpoints. Small screen 1 column → medium screen 2 columns → large screen 3 columns&lt;/p&gt;




&lt;h3&gt;
  
  
  2. Must-Learn Practical Cases
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Case 1: Market Page Dual Tab Transformation
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Row() {
  List() {
    ForEach(tabs1, (item)=&amp;gt;{/*...*/}) 
  }.onBreakpointChange((bp)=&amp;gt;{
    this.space = bp=='sm' ? 8 : 12 // Dynamic spacing
  })

  List() {
    ForEach(tabs2, (item)=&amp;gt;{/*...*/})
  }.width('70%') // Fixed width triggers truncation
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💡 Development Experience:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When Tab exceeds the container, it auto-hides and shows "..."&lt;/li&gt;
&lt;li&gt;Use Blank component for auto spacing&lt;/li&gt;
&lt;li&gt;Two-finger swipe to switch hidden Tabs&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Case 2: Stock PK Comparison Table
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Row() {
  Column() { /* Indicator Name */ }
    .alignItems(HorizontalAlign.Start) // Left align

  Blank() // Adaptive blank fill

  Column() { /* Stock Data */ }
    .width(100).alignItems(HorizontalAlign.End) // Fixed width, right align
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Key Point: Blank component achieves flexible spacing, each column can set alignment independently&lt;/p&gt;




&lt;h3&gt;
  
  
  3. Development Pitfall Guide
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Grid Listener Debounce Handling&lt;/strong&gt;
Add a 200ms delay on breakpoint changes to avoid frequent redraws&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-end Image Adaptation Tips&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Image($r("app.media.stock_bg"))
  .onBreakpointChange((bp)=&amp;gt;{
    this.source = bp=='lg' ? 'pc_bg.png' : 'mobile_bg.jpg'
  })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Performance Optimization Focus&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Use cachedCount to preload list items&lt;/li&gt;
&lt;li&gt;Enable drawingMode for complex charts to accelerate rendering&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  4. Super Useful Component Recommendations
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;th&gt;Usage Scenario&lt;/th&gt;
&lt;th&gt;Official Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;WaterFlow&lt;/td&gt;
&lt;td&gt;Waterfall News&lt;/td&gt;
&lt;td&gt;Community Comment Case&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Swiper&lt;/td&gt;
&lt;td&gt;Carousel Market&lt;/td&gt;
&lt;td&gt;Long Video Case&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Grid&lt;/td&gt;
&lt;td&gt;Multiple Stocks in One Row&lt;/td&gt;
&lt;td&gt;Bank Wealth Management Case&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;p&gt;✨ Conclusion:&lt;br&gt;&lt;br&gt;
This stock case is a textbook example of HarmonyOS adaptive layout! I suggest you try all 9 pages mentioned—your development efficiency will increase by 200%! I've already built two finance apps with this pattern, and my boss gave me a bonus after seeing the multi-end adaptation effect! 🍗&lt;/p&gt;

&lt;p&gt;If you have more questions or want to discuss further, feel free to comment below~&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Treasure Case Sharing of HarmonyOS 5 Development — One-to-Many Development Example (Shopping Price Comparison)</title>
      <dc:creator>陈杨</dc:creator>
      <pubDate>Wed, 25 Jun 2025 22:15:31 +0000</pubDate>
      <link>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-one-to-many-development-example-shopping-price-3dgo</link>
      <guid>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-one-to-many-development-example-shopping-price-3dgo</guid>
      <description>&lt;p&gt;[HarmonyOS Development Treasure Case Revealed!] Step-by-Step Guide to Building a Cross-Platform Shopping Price Comparison App with "One-to-Many" Capability&lt;/p&gt;

&lt;p&gt;Hello friends! Today, I'm excited to share a hidden gem in HarmonyOS development—the official shopping price comparison app case! This hands-on tutorial, tucked away in the developer docs, is truly the ultimate guide to mastering multi-device development!&lt;/p&gt;

&lt;p&gt;👉 1. These Features Are So Cool!&lt;br&gt;
This case perfectly demonstrates HarmonyOS's superpower of "develop once, deploy everywhere." Check out these awesome features you need to know:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Smart Split-Screen Price Comparison (Exclusive for Foldable Devices)
When you open a product detail page on a foldable device, it magically displays two products side by side:&lt;/li&gt;
&lt;li&gt;Effortlessly swipe to compare parameters&lt;/li&gt;
&lt;li&gt;Launch split-screen mode via UIAbility&lt;/li&gt;
&lt;li&gt;1:1 golden ratio layout for left and right screens
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Start split-screen magic
let want = {
  bundleName: 'com.huawei.multishopping',
  abilityName: 'SecondAbility'
};
startAbility(want, { windowMode: WINDOW_MODE_SPLIT_PRIMARY });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Live Picture-in-Picture (Ultimate Multitasking Tool)
When you close the live stream, it automatically shrinks into a floating window:&lt;/li&gt;
&lt;li&gt;Use PiPWindow controller&lt;/li&gt;
&lt;li&gt;Supports play/pause operations&lt;/li&gt;
&lt;li&gt;Smart floating window positioning
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Create picture-in-picture
PiPWindow.create({
  componentController: videoController,
  templateType: PiPTemplateType.VIDEO_LIVE
}).then(controller =&amp;gt; {
  controller.startPiP(); // Start mini player
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Smart Layout Transformation&lt;br&gt;
The homepage adapts to different devices:&lt;br&gt;
| Device Type | Layout Features |&lt;br&gt;
|-------------|----------------|&lt;br&gt;
| Phone       | Two-row tabs + waterfall flow |&lt;br&gt;
| Tablet      | Side navigation + split view |&lt;br&gt;
| PC          | Three-column professional mode |&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Adaptive Payment Popup&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Phone: Bottom half-screen popup&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tablet: Centered floating window&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Code sharing rate up to 90%!&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Adaptive popup
if(breakpoint == 'sm'){
  bindBottomSheet(); // Bottom popup for phones
}else{
  showCenterDialog(); // Centered dialog for large screens
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 2. Development Pitfalls Guide (Lessons Learned)&lt;br&gt;
When replicating the official case, keep these key points in mind:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Three Layout Principles&lt;/li&gt;
&lt;li&gt;Grid system: Use % instead of fixed px&lt;/li&gt;
&lt;li&gt;Breakpoint monitoring: @ohos.mediaquery is your best friend&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Weighted layout: Use layoutWeight for proportional distribution&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;State Management Secrets&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use AppStorage for cross-device state sync&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use LocalStorage for page parameter passing&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For complex interactions, use @Observed objects&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Resource Adaptation Tips&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resources/
   ├─base/        # Common resources
   ├─phone/       # Phone-specific icons
   ├─tablet/      # Tablet stylesheets
   └─pc/          # PC high-res assets
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Performance Optimization Focus&lt;/li&gt;
&lt;li&gt;Always use cachedCount for list item reuse&lt;/li&gt;
&lt;li&gt;Use PixelMap for image loading&lt;/li&gt;
&lt;li&gt;Run complex animations on GPU for acceleration&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;👉 3. More Awesome Cases&lt;br&gt;
Besides the shopping app, these official cases are also worth checking out:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Short Video App: Gesture switching + preloading&lt;/li&gt;
&lt;li&gt;News Reader: Smart split view + night mode&lt;/li&gt;
&lt;li&gt;Smart Home Panel: 3D rotation control&lt;/li&gt;
&lt;li&gt;Health Assistant: Adaptive charts + data sync&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;🎉 Conclusion:&lt;br&gt;
Feeling inspired to try it out? This case is like a Lego set for multi-device development—break down each module and reassemble them to build all kinds of amazing apps. I recommend reading the docs while coding, and if you hit a snag, join the developer community for help (psst, the official PMs often answer questions there!).&lt;/p&gt;

&lt;p&gt;Here's a final tip: The HarmonyOS ecosystem is booming—now is the best time to get on board! Which case do you want me to break down next? Let me know in the comments~ ✨&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Treasure Case Sharing of HarmonyOS 5 Development — One-to-Many Development Example (News Reading)</title>
      <dc:creator>陈杨</dc:creator>
      <pubDate>Wed, 25 Jun 2025 22:14:56 +0000</pubDate>
      <link>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-one-to-many-development-example-news-reading-e2j</link>
      <guid>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-one-to-many-development-example-news-reading-e2j</guid>
      <description>&lt;p&gt;✨HarmonyOS Development Treasure Case Revealed! The Secret Weapon for One-Code Multi-Device Adaptation✨&lt;/p&gt;

&lt;p&gt;Hello everyone! Today I'm sharing a real treasure I found in HarmonyOS development—the official set of "One-to-Many Development" practical cases! These hands-on guides, hidden deep in the documentation, are like secret martial arts manuals for multi-device adaptation! I stayed up late to study the docs and have distilled the most valuable insights for you!&lt;/p&gt;




&lt;h3&gt;
  
  
  1. Why is this a treasure?
&lt;/h3&gt;

&lt;p&gt;The core of HarmonyOS "One-to-Many Development" is &lt;strong&gt;one codebase for all devices&lt;/strong&gt;! The official news reading case in the docs breaks down adaptation techniques for phone/tablet/PC in detail. Just seeing how they use &lt;strong&gt;5 magical layouts&lt;/strong&gt; to solve different screen problems made me slap my thigh—so it can be done like this!&lt;/p&gt;




&lt;h3&gt;
  
  
  2. Three Must-Learn Core Techniques
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1️⃣ Grand Layout Shift
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Read &amp;amp; Comment&lt;/strong&gt; scenario: On phones, it's a vertical layout (news + comments); on large screens, it switches to a horizontal split!&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code Magic&lt;/strong&gt;: Listen for screen breakpoints and use the span property of GridCol for automatic position switching
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GridCol({ 
  span: { 
    sm: 12,  // Full row on phone
    md: 6    // Two columns on tablet
  }
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2️⃣ Shadow Clone—Repeated Layouts
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;News list&lt;/strong&gt; is single-column on phones, instantly becomes double-column waterfall on tablets&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practical Tip&lt;/strong&gt;: Use the same data source, control render count via breakpoints
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;onBreakpointChange((bp)=&amp;gt;{
  if(bp=='sm') this.showCount=1  // Phone
  if(bp=='md') this.showCount=2  // Tablet
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3️⃣ Seventy-Two Transformations Waterfall
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Featured Discovery&lt;/strong&gt; page: single column on phone → double column on tablet → triple column on PC&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key Code&lt;/strong&gt;: WaterFlow component + dynamic column control
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WaterFlow({
  columnsTemplate: 
    bp=='sm' ? '1fr' : 
    bp=='md' ? '1fr 1fr' : '1fr 1fr 1fr'
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  3. Super Practical Development Tips
&lt;/h3&gt;

&lt;h4&gt;
  
  
  📱→💻 Layout Auto-Extension
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Horizontal Scroll Bar&lt;/strong&gt;: Use Scroll + Row components, the wider the screen, the more cards are shown
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Row(){
  newsList.map(item=&amp;gt; &amp;lt;NewsCard/&amp;gt;)
}
.scrollable(ScrollDirection.Horizontal)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  🔍 Smart Show/Hide Control
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Show abstract on large screens&lt;/strong&gt;: Dynamically control text visibility via the visibility property
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Text(abstract)
.visibility(
  bp=='lg' ? Visibility.Visible 
           : Visibility.Hidden
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  🎨 Immersive Experience
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Full-screen reading mode&lt;/strong&gt;: Use grid layout to auto-hide the status bar&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Font auto-scaling&lt;/strong&gt;: Use proportional unit fp for dynamic font size scaling&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  4. Pitfall Avoidance Guide
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Be careful with breakpoint listeners&lt;/strong&gt;: Don't do time-consuming operations in onBreakpointChange&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-device preview tip&lt;/strong&gt;: Open phone + tablet emulators at the same time to compare effects&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Image adaptation secret&lt;/strong&gt;: Use aspectRatio to lock width and height ratio&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  5. Resource Guide
&lt;/h3&gt;

&lt;p&gt;Want to experience these cool tricks yourself? Here are the portals:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Official case library: Developer Docs → Domain Cases → News Reading&lt;/li&gt;
&lt;li&gt;Code express: Search "NewsDemo" in DevEco Studio&lt;/li&gt;
&lt;li&gt;Community group: HarmonyOS Developer Forum #OneToManyDevelopment&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Finally, from the bottom of my heart: I've read these cases three times, and I discover something new each time! Especially the "Read &amp;amp; Comment" layout switch, which made me refactor my project and cut code by 40%! You must try coding it yourself—it'll open a whole new world!&lt;/p&gt;

&lt;p&gt;If you run into problems, don't hesitate to reach out in the developer community—maybe your next hit app is just around the corner! 🚀&lt;/p&gt;

&lt;p&gt;(Tips: Long-press the diagrams in the doc to jump directly to the corresponding code file—this hidden feature is awesome!)&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Treasure Case Sharing of HarmonyOS 5 Development — One-to-Many Development Example (Music)</title>
      <dc:creator>陈杨</dc:creator>
      <pubDate>Wed, 25 Jun 2025 22:14:30 +0000</pubDate>
      <link>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-one-to-many-development-example-music-d25</link>
      <guid>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-one-to-many-development-example-music-d25</guid>
      <description>&lt;p&gt;Hello, fellow developers! Today, let's dive into some hardcore content! Recently, I discovered a "gold mine" in the HarmonyOS documentation center—there are actually 100+ official practical cases hidden, covering everything from distributed architecture to interactive animation optimization! These cases not only contain Huawei engineers' private tips but also directly address high-frequency pain points in actual development, such as memory leaks, cross-device adaptation, service card design, and more. I've compiled a comprehensive interpretation to help you unlock the "hidden buffs" of HarmonyOS development!&lt;/p&gt;




&lt;h3&gt;
  
  
  1. Dynamic Layout Practice: From Foldable Screens to Multi-Device Adaptation
&lt;/h3&gt;

&lt;p&gt;You might think HarmonyOS layouts are just about Flex and Grid? The official cases hide more advanced techniques! For example, in foldable screen scenarios, you can use &lt;strong&gt;grid breakpoints + percentage layouts&lt;/strong&gt; to achieve automatic UI expansion. A typical code snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GridContainer({ columns: { sm: 4, md: 8 }, gutter: 8 }) {  
  ForEach(this.items, item =&amp;gt; {  
    GridItem({ column: { span: { sm: 2, md: 4 } } }) {  
      // Adaptive content  
    }  
  })  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;sm&lt;/code&gt; and &lt;code&gt;md&lt;/code&gt; correspond to the number of columns for small and large screens, respectively. Combined with &lt;strong&gt;device type detection&lt;/strong&gt; (such as the &lt;code&gt;@ohos.device&lt;/code&gt; module), you can achieve dynamic responsiveness. Even more impressive, the JD Finance team introduced the &lt;strong&gt;Yoga layout engine&lt;/strong&gt; in HarmonyOS adaptation to solve cross-device rendering differences, boosting development efficiency by 40%.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. Interactive Animation: From Gestures to Distributed Linkage
&lt;/h3&gt;

&lt;p&gt;HarmonyOS's animation system is far more than just property animations! In the official cases, the combination of &lt;strong&gt;gesture paging + parallax scrolling&lt;/strong&gt; is eye-opening:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Gesture swipe listener  
gesture.onGestureEvent(event =&amp;gt; {  
  if (event.direction === Direction.Left) {  
    // Trigger parallax animation  
    animateTo({ duration: 300, curve: Curve.EaseOut }, () =&amp;gt; {  
      this.offsetX = -100;  
    });  
  }  
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the HarmonyOS version of the Mafengwo travel app, &lt;strong&gt;explicit animation + gesture interruption compensation&lt;/strong&gt; is used to solve list stuttering during fast scrolling, keeping FPS stable at 55+. Even more impressive is the distributed linkage case—after copying text on the phone, you can use &lt;code&gt;Pasteboard&lt;/code&gt; and &lt;code&gt;DeviceManager&lt;/code&gt; to achieve cross-device paste, with automatic data compression during transmission saving 30% bandwidth.&lt;/p&gt;




&lt;h3&gt;
  
  
  3. Service Cards: From Design Guidelines to Dynamic Data
&lt;/h3&gt;

&lt;p&gt;Service cards are not just simple information displays! The official best practices hide three core principles:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Zero-level interaction&lt;/strong&gt;: For example, the weather card allows direct time period switching by swiping, without jumping to the app;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic data flow&lt;/strong&gt;: Use &lt;code&gt;FormExtensionAbility&lt;/code&gt; to update step count in real time, and combine with &lt;code&gt;Worker&lt;/code&gt; threads to avoid blocking the main thread;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-device adaptation&lt;/strong&gt;: The same card displays a circular layout on a watch and switches to landscape mode on a car device.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Code example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Real-time step count card  
@Entry  
@Component  
struct StepCard {  
  @State steps: number = 0;  

  build() {  
    Column() {  
      Progress({ value: this.steps, total: 10000 })  
        .style(ProgressStyle.Ring)  
      Text(`${this.steps} steps`)  
    }  
    .onAppear(() =&amp;gt; {  
      // Fetch data in the background  
      TaskPool.execute(() =&amp;gt; {  
        this.steps = fetchStepData();  
      });  
    })  
  }  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the "Inner Mongolia Medical Insurance" government app, card design follows the &lt;strong&gt;721 rule&lt;/strong&gt; (70% information display + 20% operation entry + 10% brand elements), increasing user retention by 23%.&lt;/p&gt;




&lt;h3&gt;
  
  
  4. Memory Optimization: From Leak Detection to Performance Tuning
&lt;/h3&gt;

&lt;p&gt;HarmonyOS is very strict about memory management, and the official cases reveal five major "pitfalls":&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Static Handler not released&lt;/strong&gt; causes Activity to be unrecyclable;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Event listeners not canceled&lt;/strong&gt; lead to memory accumulation;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Large image cache not cleared&lt;/strong&gt; triggers OOM.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Optimization solutions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Object pooling&lt;/strong&gt;: Reuse frequently created objects (such as list items);&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Weak reference management&lt;/strong&gt;: Use &lt;code&gt;WeakReference&lt;/code&gt; for global singletons;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scene-based release&lt;/strong&gt;: Actively clear non-core resources when the app goes to the background.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In terms of tools, &lt;code&gt;DevEco Studio Profiler&lt;/code&gt; can monitor memory curves in real time, and combined with &lt;code&gt;HiDumper&lt;/code&gt; to capture thread stacks, it can accurately locate leak points.&lt;/p&gt;




&lt;h3&gt;
  
  
  5. Distributed Development: From Theory to Industrial Implementation
&lt;/h3&gt;

&lt;p&gt;HarmonyOS's distributed capabilities are not just about device interconnection! In the LiEMS system of Chongqing Industrial Park, &lt;strong&gt;distributed soft bus + task scheduling&lt;/strong&gt; is used to improve remote device monitoring efficiency by 20%. On the code side, key APIs include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Device discovery&lt;/strong&gt;: &lt;code&gt;DeviceManager.registerDeviceListCallback()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data synchronization&lt;/strong&gt;: &lt;code&gt;DistributedDataManager.sync()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Task collaboration&lt;/strong&gt;: &lt;code&gt;CollaborativeTask&lt;/code&gt; assigns computing tasks across devices&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the Internet of Vehicles scenario, the HarmonyOS version of Amap uses &lt;strong&gt;AR navigation + multimodal interaction&lt;/strong&gt; to achieve seamless switching between "gesture zoom map + voice route query," with 87% of users believing the experience surpasses the mobile version.&lt;/p&gt;




&lt;h3&gt;
  
  
  6. Performance Acceleration: From Rendering Pipeline to Thread Management
&lt;/h3&gt;

&lt;p&gt;HarmonyOS's rendering optimization black technologies:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Offscreen rendering&lt;/strong&gt;: Use &lt;code&gt;OffscreenCanvas&lt;/code&gt; to render complex charts on background threads;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;List lazy loading&lt;/strong&gt;: &lt;code&gt;LazyForEach&lt;/code&gt; + &lt;code&gt;cached(true)&lt;/code&gt; reduces GPU pressure;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GPU command batching&lt;/strong&gt;: Merge multiple draw calls into a single batch.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For thread management, &lt;strong&gt;TaskPool&lt;/strong&gt; replaces traditional Worker, supporting priority scheduling and automatic load balancing. In video editing apps, 4K rendering time is reduced from 1200ms to 200ms.&lt;/p&gt;




&lt;p&gt;[Conclusion]&lt;br&gt;
What other "pitfalls" have you encountered in development? Come and battle in the comments! Follow for more updates~&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Treasure Case Sharing of HarmonyOS 5 Development — One-to-Many Development Example (Mobile Payment)</title>
      <dc:creator>陈杨</dc:creator>
      <pubDate>Wed, 25 Jun 2025 22:14:05 +0000</pubDate>
      <link>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-one-to-many-development-example-mobile-payment-1hi6</link>
      <guid>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-one-to-many-development-example-mobile-payment-1hi6</guid>
      <description>&lt;p&gt;[Share] The Hidden Gems of HarmonyOS Development! A Hands-on Guide to "Develop Once, Deploy Everywhere" Practical Skills!&lt;/p&gt;

&lt;p&gt;Hello everyone~ Today, while browsing the HarmonyOS developer documentation, I discovered a super practical collection of "One-for-Many" development cases! It turns out that the official team has already prepared various cross-device adaptation solutions—like discovering a new continent! I quickly organized and am sharing several highly practical mobile payment development cases to help you avoid detours~&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The Magic of Interface Layout: Grid System&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;King Kong Area Transformation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mobile: Circular icon + vertical text&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Large screen: Rounded rectangle + horizontal layout&lt;br&gt;&lt;br&gt;
Key code:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GridRow({gutter: {x: {sm:30, md:41, lg:58}}}) {
  ForEach(this.quickFunctions, (item) =&amp;gt; {
    GridCol({span:3}) {
      // Switch component shape based on screen size
      this.curBp === 'sm' ? 
        &amp;lt;CircularComponent&amp;gt; : &amp;lt;RectangularComponent&amp;gt;
    }
  })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Practical tip: Use the span property of GridCol to control element proportions, and combine with breakpoint listeners to achieve "smart layout."&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Seventy-Two Changes of Function Entry&lt;/li&gt;
&lt;li&gt;Mobile shows 4 columns → Tablet 6 columns → PC 8 columns
Secret weapon: Dynamic configuration of the columns property
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GridRow({
  columns: {sm:4, md:6, lg:8}, // The magic numbers are here!
  gutter: {x:{sm:45, md:50, lg:55}}
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The Cross-Device Secrets of Payment and Collection&lt;br&gt;&lt;br&gt;
(with pop-up and full-screen page switch diagrams)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Intelligent Device Size Detection:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private receivePayment() {
  if (this.curBp === 'sm') {
    // On mobile, navigate to a new page
    router.pushUrl({url:'ReceivePaymentPage'})
  } else {
    // On large screens, show a dialog
    this.isDialogOpen = true
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The Pitfalls and Solutions of Dynamic QR Codes:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Timed refresh logic
aboutToAppear() {
  this.timer = setInterval(() =&amp;gt; {
    this.getNewQRCode() // Call API to update
  }, 60000)
}

// Must remember to clear!
aboutToDisappear() {
  clearInterval(this.timer)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pitfall tip: Remember to listen for breakpoint changes when folding large screens, or layout issues may occur!&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Cross-Device Adaptation for Scan Feature&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Adaptive Camera Area:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Responsive design using percentages
Scanner({
  width: '70%', 
  height: '70%',
  aspectRatio: 1 // Force 1:1 ratio
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Third-Party Payment Page Adaptation:&lt;/li&gt;
&lt;li&gt;Mobile: Full-screen Web component&lt;/li&gt;
&lt;li&gt;PC: Embedded iframe + independent operation area
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (breakpoint === 'lg') {
  this.useIframeMode = true
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Card Pack Module Layout Secrets&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Card Waterfall Layout:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GridCol({
  span: {sm:12, md:6, lg:4} // Show 1/2/3 columns on three devices respectively
}) {
  BankCardComponent()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Interaction Differences for Adding Bank Cards:&lt;/li&gt;
&lt;li&gt;Mobile: Bottom pop-up&lt;/li&gt;
&lt;li&gt;Tablet: Slide out from the right&lt;/li&gt;
&lt;li&gt;PC: Centered dialog
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;promptAction.showModal({
  alignment: deviceType === 'phone' ? 
    Alignment.Bottom : Alignment.Center
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Development Tips&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Breakpoint listeners should be written in the aboutToAppear lifecycle&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use the Blank component to fill blank areas more flexibly&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make good use of the @Extend decorator to reuse styles&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Multi-device preview shortcut: Ctrl+Shift+M&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Conclusion:&lt;br&gt;&lt;br&gt;
These official cases are like martial arts secrets—once mastered, you can truly "write code once and automatically adapt to all devices!" I recommend creating a new project in your IDE and trying out these code snippets yourself. You'll definitely feel like you've unlocked a new level of skill~&lt;/p&gt;

&lt;p&gt;If you want to see analysis for other vertical scenarios (such as e-commerce, social apps), feel free to leave a comment! More HarmonyOS development tips will be shared in the future, so remember to follow~ ✨&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Treasure Case Sharing of HarmonyOS 5 Development — One-to-Many Development Example (Long-form Video)</title>
      <dc:creator>陈杨</dc:creator>
      <pubDate>Wed, 25 Jun 2025 22:13:27 +0000</pubDate>
      <link>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-one-to-many-development-example-long-form-video-3e8a</link>
      <guid>https://dev.to/cyang/treasure-case-sharing-of-harmonyos-5-development-one-to-many-development-example-long-form-video-3e8a</guid>
      <description>&lt;p&gt;[🌟HarmonyOS Development Treasure Cases Revealed! So many great resources hidden in the official docs!&lt;br&gt;&lt;br&gt;
Hello everyone~ Recently, while tinkering with HarmonyOS app development, I accidentally discovered a bunch of super practical development cases hidden in the official documentation! Especially the "One-to-Many Development" example for long video apps—after reading it, I was amazed: "So it can be done like this!" Today, let's dig into these hidden treasures together, with step-by-step code analysis!&lt;/p&gt;




&lt;h3&gt;
  
  
  🔥 Long Video App Case: One Development for Four Types of Devices
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Core Features&lt;/strong&gt;: Home waterfall recommendations, smart search, watch and comment, full-screen playback&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Supported Devices&lt;/strong&gt;: Mobile/Foldable/Tablet/PC all supported!&lt;/p&gt;

&lt;h4&gt;
  
  
  🛠️ Multi-Device Adaptation Tricks
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. Dynamic Grid Layout on Home Page&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Mobile Portrait&lt;/strong&gt;: Two-column video stream&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tablet Landscape&lt;/strong&gt;: Three columns + immersive banner&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PC Large Screen&lt;/strong&gt;: Side navigation + 4K video preview
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Dynamic grid listening code snippet
GridRow({ columns: { sm: 4, md: 8, lg: 12 }}) {
  GridCol({ span: { sm: 4, md: 4, lg: 3 }}) {
    VideoCard().aspectRatio(16/9) // Adaptive aspect ratio
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Foldable Screen Magic&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Half-fold hover playback&lt;/li&gt;
&lt;li&gt;Auto switch to split-screen mode when unfolded
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Fold crease region detection
display.getCurrentFoldCreaseRegion().then(region =&amp;gt; {
  if(region.creaseRects.length &amp;gt; 0) {
    this.avoidArea = region.creaseRects[0]
  }
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  💡 Must-Learn Core Tech Points
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;ArkUI Reactive Three Moves&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Breakpoint listening:&lt;code&gt;&amp;lt;font style="color:rgba(0, 0, 0, 0.9);background-color:rgb(252, 252, 252);"&amp;gt;@ohos.mediaquery&amp;lt;/font&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Flexible layout:&lt;code&gt;&amp;lt;font style="color:rgba(0, 0, 0, 0.9);background-color:rgb(252, 252, 252);"&amp;gt;Flex+Percentage&amp;lt;/font&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Component reuse: HAR package cross-project call&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Project Management Tips&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;project/
├─ common/         # Common utility package
├─ features/       # Feature modules 
│  ├─ home/        # Home HAR
│  └─ player/      # Player HAR
└─ products/       # Device-specific adaptation
   ├─ phone/       # Mobile enhancements
   └─ pc/          # Keyboard shortcuts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🎯 More Practical Case Recommendations
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Case 1: E-commerce App (Double 11 Special)
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Mobile&lt;/strong&gt;: Vertical product waterfall&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tablet&lt;/strong&gt;: Left category navigation + right products&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PC&lt;/strong&gt;: Three-column layout (category/product/detail on the same screen)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Product card adaptation
@Component
struct GoodsCard {
  @Prop isPC: boolean = false

  build() {
    Column() {
      Image($r('app.media.product')).height(this.isPC ? 200 : 120)
      Text('Product Name').fontSize(this.isPC ? 18 : 14)
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Case 2: News App (Free Switch Between Portrait and Landscape)
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Portrait: Title list + thumbnail&lt;/li&gt;
&lt;li&gt;Landscape: Left navigation + right mixed text and images&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keyboard adaptation&lt;/strong&gt;: Arrow keys to switch focus, Enter to open details&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🚀 Pitfall Guide: Common Issues in Multi-Device Development
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Image Distortion&lt;/strong&gt;:
❌ Wrong approach: Fixed width and height
✅ Correct solution: `.aspectRatio()+objectFit**&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;plain&lt;br&gt;
Image($r('app.media.banner'))&lt;br&gt;
  .aspectRatio(16/9)&lt;br&gt;
  .objectFit(ImageFit.Cover)&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Interaction Conflicts&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Disable mouse hover effects on mobile&lt;/li&gt;
&lt;li&gt;Add keyboard shortcuts on PC&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`plain&lt;br&gt;
@State hoverEffect: boolean = false&lt;/p&gt;

&lt;p&gt;Button('Buy Now')&lt;br&gt;
  .onHover(() =&amp;gt; {&lt;br&gt;
    if(!isMobile){&lt;br&gt;
      this.hoverEffect = !this.hoverEffect&lt;br&gt;
    }&lt;br&gt;
  })&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;




&lt;p&gt;👉 &lt;strong&gt;Learning Shortcuts&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;IDE built-in template: Check "Multi-device Template" when creating a new project&lt;/li&gt;
&lt;li&gt;Debugging tool:&lt;code&gt;&amp;lt;font style="color:rgba(0, 0, 0, 0.9);background-color:rgb(252, 252, 252);"&amp;gt;Previewer&amp;lt;/font&amp;gt;&lt;/code&gt;Real-time device switching&lt;/li&gt;
&lt;li&gt;Official community: Live Q&amp;amp;A every Thursday at 8pm (search "HarmonyOS Night Talk")&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;After reading, do you feel that "One-to-Many Development" in HarmonyOS is not that mysterious? In fact, as long as you master adaptive layout + modular design, conquering multiple devices with one set of code is really easy! What other tricky adaptation problems have you encountered in development? Feel free to discuss in the comments~&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
