DEV Community

Cover image for JSBridge Communication, Input Placeholder Size, Book Page Turning Effect, Web Callback Functions, Auto-Sliding Carousel
kouwei qing
kouwei qing

Posted on

JSBridge Communication, Input Placeholder Size, Book Page Turning Effect, Web Callback Functions, Auto-Sliding Carousel

[Daily HarmonyOS Next Knowledge] JSBridge Communication, Input Placeholder Size, Book Page Turning Effect, Web Callback Functions, Auto-Sliding Carousel

1. HarmonyOS: Data Anomaly in JSBridge Communication Between H5 and App

When using JSBridge for H5-app communication, complex or large data transmitted from H5 cannot be observed in the ArkTS console, and specific attributes cannot be obtained.

The compiler truncates large character strings, but you can use the following methods:

Solution 1: For large JSON strings, parse them into JSON objects before printing:

let largeJsonString = '{"key1": "value1", "key2": "value2"}'; // Large JSON string
try {
  console.log(JSON.stringify(JSON.parse(largeJsonString), null, 2)); // Beautified JSON printing
} catch (error) {
  console.error('Error parsing JSON:', error);
}
Enter fullscreen mode Exit fullscreen mode

Solution 2: For ordinary strings, print in chunks:

const largeString = ...; // Extremely large string
const chunkSize = 1000; // Chunk size
for (let i = 0; i < largeString.length; i += chunkSize) {
  console.log(largeString.slice(i, i + chunkSize));
}
Enter fullscreen mode Exit fullscreen mode

2. How to Modify the Placeholder Text Size in HarmonyOS TextInput

TextInput({ placeholder: "Search enterprise name" })
  .fontSize(20)
  .height(30)
  .borderRadius(16)
  .placeholderFont({ size: 10, weight: 400 })
Enter fullscreen mode Exit fullscreen mode

3. Does HarmonyOS Have a Control for Book Page Turning Effects?

The RecyclerViewPager is a container component that supports custom left-right/up-down page turning effects and Material-style interactions.

Reference: https://gitee.com/openharmony-sig/RecyclerViewPager

4. Are There Callbacks for Unbinding webViewController from the Web Component in HarmonyOS?

Currently, no callbacks or methods exist to check the binding status of webViewController. It is recommended to use controller methods within the Web component's lifecycle rather than the page's lifecycle.

5. Flickering Issue with Two Images in HarmonyOS Swiper Auto-Sliding

When configuring auto-sliding for two images in the Swiper component, the second image flickers with the previous image before loading (using the nextMargin parameter):

Swiper() {
  ForEach(this.iconList, (item: CCIcon) => {
    Row() {
      Image(item.imgUrl)
        .objectFit(ImageFit.Cover)
        .border({ radius: 8 })
        .width('100%')
        .aspectRatio(2.16)
    }
    .width('100%')
    .margin({ bottom: 22 })
  })
}
.padding({
  left: $r("app.float.tab_container_padding_side")
})
.width('100%')
.autoPlay(true)
.duration(300)
.nextMargin(56)
.itemSpace(8)
.displayMode(SwiperDisplayMode.STRETCH)
.displayCount(1)
.loop(true)
Enter fullscreen mode Exit fullscreen mode

Recommendation: Use LazyForEach instead.

Top comments (0)