DEV Community

Cover image for [Daily HarmonyOS Next] Bottom Placement, Adding Search Component to Custom Dialog, Modifying APP Name and Icon, Page Navigation
kouwei qing
kouwei qing

Posted on

[Daily HarmonyOS Next] Bottom Placement, Adding Search Component to Custom Dialog, Modifying APP Name and Icon, Page Navigation

[Daily HarmonyOS Next Knowledge] Bottom Placement, Adding Search Component to Custom Dialog, Modifying APP Name and Icon, Page Navigation, Animation Options

1. Why does setting the bottom position with the initialIndex property in HarmonyOS not work perfectly?

The bottom position is set using the initialIndex property, but there is a slight offset.

Check the height settings between list items and whether dividers are set. Refer to the API documentation:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-service-widget-container-list-V5

2. When adding a Search component to a CustomDialogController in HarmonyOS, the soft keyboard pushes the interface off the screen when the Search component is focused?

Reference: https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-sheet-transition-V5#ZH-CN_TOPIC_0000001884917674__bindsheet

Bind a semi-modal page to a component using the bindSheet property. The size of the semi-modal page can be determined by setting a custom or default built-in height when inserting the component.

Replace the custom popup with a semi-modal page using the following demo:

@Entry
@Component
struct Index {
  @State message: string = 'Click to Show Dialog';
  scroller: Scroller = new Scroller();
  private arr: number[] = [0, 1, 2, 3, 4, 5];
  controllera: TextInputController = new TextInputController();
  @State flag: boolean = false;
  @State TextTest: string = '';
  @State TextTest1: string = '';
  @State screenHeight: number = 0;
  // Control the display/hide of the semi-modal transition
  @State isShowSheet: boolean = false;

  // Build the semi-modal display interface using @Builder
  @Builder
  mySheet() {
    // Use a Stack container to fix the Navigation bar
    Stack({ alignContent: Alignment.TopStart }) {
      Scroll(this.scroller) {
        Column() {
          TextInput({ placeholder: 'search...', controller: this.controllera })
            // Disable focus by default
            .focusable(this.flag)
            .width('90%')
            .height(40)
            .backgroundColor('#FFFFFF')
            .margin({ top: 8, bottom: 20 })
            // Re-acquire focus on click
            .onClick(() => {
              this.flag = true;
              this.TextTest1 = '1';
            });

          ForEach(this.arr, (item: number) => {
            Text(item.toString())
              .width('90%')
              .height(150)
              .backgroundColor(0xFFFFFF)
              .borderRadius(15)
              .fontSize(16)
              .textAlign(TextAlign.Center)
              .margin({ top: 10 });
          }, (item: number) => item.toString());

          // Space for the keyboard; pushes up content when not empty
          Text(this.TextTest)
            .lineHeight(300)
            .fontColor('#DCDCDC');
          Text(this.TextTest1)
            .lineHeight(300)
            .fontColor('#DCDCDC');
        }.width('100%');
      }
      // Top margin based on the Navigation bar height
      .margin({ top: 110 })
      .scrollable(ScrollDirection.Vertical)
      .scrollBar(BarState.On)
      .scrollBarColor(Color.Gray)
      .scrollBarWidth(0)
      .onScroll((xOffset: number, yOffset: number) => {
        console.info(xOffset + ' ' + yOffset);
      });

      // Second child component in the Stack; Navigation overlays the Scroll container
      Navigation() {
      }
      .title('Navigation Title')
      .backgroundColor(Color.Yellow)
      .height(110)
      .titleMode(NavigationTitleMode.Full)
      .hideTitleBar(false)
      .hideToolBar(false);

      // A button concept to handle keyboard dismissal (not implemented due to lack of keyboard event)
      Button('Dismiss Keyboard')
        .onClick(() => {
          this.TextTest1 = '';
          this.flag = false;
        })
        .margin({ top: 10, left: 20 });
    }.width('100%').height('100%').backgroundColor(0xDCDCDC);
  }

  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .bindSheet(this.isShowSheet, this.mySheet(), {
            showClose: false,
            height: 700,
            dragBar: false,
            onDisappear: () => {
              this.isShowSheet = !this.isShowSheet;
            }
          })
          .onClick(() => {
            this.isShowSheet = !this.isShowSheet;
          });
      }
      .width('100%');
    }
    .height('100%');
  }
}
Enter fullscreen mode Exit fullscreen mode

3. Changes to the APP name and icon in HarmonyOS are not taking effect?

In a Flutter project, changes to the icon and APP name under the ohos\AppScope\resources path are not reflected.

Solution:

  • In app.json5, icon corresponds to the APP launch icon, and label corresponds to the APP name.

4. How to navigate between pages in modular development in HarmonyOS?

How to navigate between pages when developing modularly using the HAR method? How can the main module use router.pushUrl to navigate to a page in a sub-module?

Reference: https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-routing-V5#%E5%91%BD%E5%90%8D%E8%B7%AF%E7%94%B1

To navigate to a page in a shared package (HAR or HSP), use router.pushNamedRoute:

router.pushNamedRoute({
  name: 'targetRouteName', // Name of the target route
  parameters: {
    // Parameters to pass
  }
});
Enter fullscreen mode Exit fullscreen mode

5. The local code dependency for AnimationOptions in HarmonyOS cannot be found?

Reference for AnimationOptions:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-arkui-drawabledescriptor-V5#animationoptions12

AnimationOptions is used to control the playback of animations when displaying an array of PixelMap objects using the Image component:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-arkui-drawabledescriptor-V5#ZH-CN_TOPIC_0000001884757686__animationoptions12

Top comments (0)