DEV Community

wei chang
wei chang

Posted on

Practical Case of HarmonyOS NEXT Cangjie Development Language: Food Delivery App

Hello everyone, this weekend! Today, I’m going to share with you the practical application of the Cangjie language food delivery App.

Image description

We can first analyze the layout structure of the page. It is composed of the navigation bar and the List container. Youlan Jun still hasn’t found the system component of the Cangjie language navigation bar. It still needs to be customized. This navigation bar has three parts of content and can be aligned at both ends. It should be noted that if the middle part is needed in the middle of the page, the content width at both ends should be the same. The layout structure code of the navigation bar and the page is as follows:

Column{
    Row{
        Text('幽蓝外卖')
        .fontColor(Color.BLACK)
        .fontSize(17)
        Row(6){
            Image(@r(app.media.wm_m1))
            .width(16)
            .height(16)
            Text('黄埔江岸')
            .fontColor(0x1EC28A)
            .fontSize(13)
        }
        Row{
            Image(@r(app.media.wm_m2))
            .width(21)
            .height(21)
        }
        .width(65)
        .justifyContent(FlexAlign.End)
    }
    .padding(left:12,right:12)
    .width(100.percent)
    .height(60)
    .alignItems(VerticalAlign.Center)
    .justifyContent(FlexAlign.SpaceBetween)

    List{
    }
    .width(100.percent)
    .layoutWeight(1)
    .padding(left:12,right:12)
}
.width(100.percent)
.height(100.percent)
.backgroundColor(Color(247, 247, 247, alpha: 1.0))
Enter fullscreen mode Exit fullscreen mode

Next comes the search box. Cangjie provides a search box component. With just simple Settings, the effect of this case can be achieved:

ListItem{
    Search(value: "", placeholder: "吃点什么")
    .width(100.percent)
    .height(38)
    .backgroundColor(0xDDDDDD)
    .placeholderColor(0x000000)
    .borderRadius(19)
}
Enter fullscreen mode Exit fullscreen mode

Next, let’s take a look at the category and discover good dishes modules. They have the same style of title, so we use the header of ListItemGroup to implement them:

@Builder func itemHead(text:String) {
    Row{
        Text(text)
        .fontColor(Color.BLACK)
        .fontSize(13)
    }
    .width(100.percent)
    .height(35)
    .alignItems(VerticalAlign.Center)
    .padding(top:3,left:10)
}
ListItemGroup(ListItemGroupParams(header:{=>bind(this.itemHead,this)('看看品类')})){
}
Enter fullscreen mode Exit fullscreen mode

Let’s take a look at the category section. Its content has two horizontally scrollable lists. Here, we need to use “Scroll”. Let’s take the list of dishes as an example to implement a simple scrolling list:

Scroll{
    Row(14){
        ForEach(ArrayList<Int64>([1,1,1,1]), itemGeneratorFunc: {num:Int64,index:Int64 =>
                    Column{
            Image(@r(app.media.wm_mlt))
            .width(168)
            .height(168)
            Column(4){
                Text('幽蓝麻辣烫')
                .fontSize(14)
                .fontColor(Color.BLACK)
                Text('月售 1006')
                .fontSize(13)
                .fontColor(Color.GRAY)
            }
            .width(100.percent)
            .alignItems(HorizontalAlign.Start)
            .padding(left:10)
            .margin(bottom:10)
            Row{
                Text('¥ 18.88')
                .fontColor(Color.RED)
                .fontSize(14)
                Image(@r(app.media.wm_qq))
                .width(16)
                .height(16)
            }
            .padding(left:10,right:10)
            .width(100.percent)
            .justifyContent(FlexAlign.SpaceBetween)
            .margin(bottom:10)
        }
        .height(260)
        .width(162)
        .backgroundColor(Color.WHITE)
        .justifyContent(FlexAlign.SpaceBetween)
                    })
    }
    .height(260)
}
 .scrollable(ScrollDirection.Horizontal)
.scrollBar(BarState.Off)
Enter fullscreen mode Exit fullscreen mode

When using the Scroll component, it is important to set the scrolling direction; otherwise, the list may not scroll.
The above is the content sharing about the food delivery App.

Top comments (0)