1/* 2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { WebSocketSource } from '../model/DataSource'; 17 18@Component 19export default struct ChatsPage { 20 @Link chats: WebSocketSource 21 @Builder 22 ChatsMessage(name: Resource, message: string, direction: Direction) { 23 Row() { 24 Text(name) 25 .width(40) 26 .height(40) 27 .padding(5) 28 .fontSize(25) 29 .borderRadius(10) 30 .margin({ right: 10 }) 31 .backgroundColor('#e5e5e5') 32 .textAlign(TextAlign.Center) 33 Text(message) 34 .padding(10) 35 .maxLines(5) 36 .fontSize(20) 37 .borderRadius(10) 38 .margin({ top: 20 }) 39 .alignSelf(ItemAlign.Start) 40 .backgroundColor('#ff78dd4d') 41 } 42 .width('100%') 43 .direction(direction) 44 .margin({ top: 5, bottom: 10 }) 45 } 46 47 build() { 48 Column() { 49 List() { 50 LazyForEach(this.chats, (item) => { 51 ListItem() { 52 if (item.isServer) { 53 this.ChatsMessage($r('app.string.server'), item.message, Direction.Ltr); 54 } else { 55 this.ChatsMessage($r('app.string.me'), item.message, Direction.Rtl); 56 } 57 } 58 .id('text_list') 59 .padding(10) 60 .width('100%') 61 }, item => item) 62 }.width('100%').height('100%') 63 } 64 .width('100%') 65 .layoutWeight(1) 66 .backgroundColor(Color.White) 67 } 68}