Overview
This sample demonstrates how to develop a community comment UI that can be deployed across devices. This sample covers bar-type phones, foldable devices, tablets, and PCs. In addition, a three-layer architecture is used to organize the code project, and the adaptive layout and responsive layout are combined to build a complete community comment experience, covering the follow page, hot topics, social details, and image details.
Preview
| Widescreen Foldable Outer Screen |
Bar-Type Phone |
Foldable |
 |
 |
 |
| Tablet |
PC |
 |
 |
How to Use
- Install and open the application on a bar-type phone, bi-fold device, widescreen foldable device, tablet, or PC. The responsive layout and adaptive layout are used to display different effects on the application pages for different devices.
- The Following page shows the waterfall layout of posts of the authors you have followed. The follower list is displayed on the left (large-screen devices).
- The hot topics page displays real-time posts. The post widget is displayed on the left of the large screen, and the comment area is displayed on the right.
- Tap the post widget to go to the community details page, where the author information and images are displayed.
- Tap an image to go to the image details page, where you can view the full image.
- Switch between the home page, hot topics, video, and personal center at the bottom.
Project Directory
├──common
│ └──commonmulticommunityapplication
│ └──src/main
│ ├──ets
│ │ ├──components // Common components
│ │ ├──constants // Common constants
│ │ ├──model // Common model
│ │ ├──utils // Utilities
│ │ └──view // Common service components of features
│ └──resources // Public resources
├──features
│ ├──commoncommunityui // Common service component module of products
│ │ └──src/main
│ │ ├──ets
│ │ │ ├──view // Common service components of products
│ │ │ └──viewmodel // Common view model of products
│ │ └──resources // Static routing table resources
│ ├──contentcommunity // Content community module
│ │ └──src/main
│ │ ├──ets
│ │ │ ├──model // Post data model
│ │ │ ├──view // Post component
│ │ │ └──viewmodel // Post view model
│ │ └──resources // Post module resources
│ └──socialcommunity // Social community module
│ └──src/main
│ ├──ets
│ │ ├──model // Follower/Comment data model
│ │ ├──view // Follower/Comment component
│ │ └──viewmodel // Follower/Comment view model
│ └──resources // Social module resources
├──product
│ ├──default // Mobile phone/Tablet
│ │ └──src/main
│ │ ├──ets
│ │ │ ├──entryability // Entry ability
│ │ │ ├──entrybackupability // Custom extension ability for application data backup and restoration
│ │ │ └──pages // Entry page
│ │ └──resources // Resource file
│ └──pc // PC
│ └──src/main
│ ├──ets
│ │ ├──pages // Entry page
│ │ ├──pcability // Entry ability
│ │ └──pcbackupability // Custom extension ability for application data backup and restoration
│ └──resources // Resource file
└──oh-package.json5 // Project dependency declaration
How to Implement
- Page structure
| Version |
6.0.2(22) |
6.1.0(23) |
| Root container |
Tabs are nested within a Navigation component. One NavPathStack component is used to manage all page routes. |
HdsTabs is nested within an HdsNavigation component. One NavPathStack component is used to manage all page routes. |
- Use @Env(SystemProperties.BREAK_POINT) to listen for system breakpoint changes. Dynamically adapt UIs and dynamically change the single-column or split-column layout of the Navigation component.
- Use expandSafeArea to adapt to immersive display.
- Use the MVVM architecture. The Model layer defines data APIs, the ViewModel layer processes the service logic, and the View layer manages the UI display.
- Use WaterFlow to implement the waterfall layout of posts, which adapts to different screen sizes.
- Use SideBarContainer to implement the sidebar layout on large-screen devices.
Required Permissions
N/A
Constraints
- This sample is only supported on devices running standard systems, including bar-type phones, bi-fold devices (Mate X series), widescreen foldable devices, tri-fold devices, tablets, and PCs/2-in-1 devices.
- The HarmonyOS version must be HarmonyOS 6.0.2 Release or later.
- The DevEco Studio version must be DevEco Studio 6.1.0 Release or later.
- The HarmonyOS SDK version must be HarmonyOS 6.1.0 Release SDK or later.