[Daily HarmonyOS Next Knowledge] Search Component Callback, Print Object Specific Type, Uninitialized Exception, Semi-Modal Failure to Display, Linear Gradient Adaptation
1. Does the HarmonyOS Search component have a callback event for the "×" icon? What is it specifically?
You can use onChange to listen for when the content is empty.
2. How to print the specific type of an object in HarmonyOS?
As shown below, except for clear types like string/number/undefined, others are all Object? Or are there other keywords to print?
let a = '';
let b = null;
let c = undefined;
let d = 4;
// let e = {};
let f = [];
console.log(a, typeof(a)); // string
console.log(b, typeof(b)); // null object
console.log(c, typeof(c)); // undefined undefined
console.log('', d, typeof(d)); // 4 number
console.log('', f, typeof(f)); // object
// Ideally, it should be Array
let g: User = new User();
console.log('', typeof(g)); // object
// Ideally, it should display as xx.User object
class User {
id: number = 0;
name: string = '';
}
In TypeScript, you can use Object.getPrototypeOf(a).constructor.name to get the object type.
3. When a static readonly constant is declared in a HarmonyOS class, the app runs with an error that the class is not initialized.
// Example of declaring a static readonly constant in class RouterConstant:
export class RouterConstant {
// Home page
public static readonly MAIN_NOTDATA_PAGE: string = 'RemoteViewPage';
}
Error message during runtime: AAFwkAppKit: [invalidDomain]Error message: RouterConstant is not initialized
Solutions:
- Dynamic loading failure exists in the app, and there is an error in the reference chain.
Verification method: Use a static
importstatement in the entry file to preload the file containing the uninitialized variable. If no error occurs after this operation, it indicates dynamic loading failure. - Circular dependency in the code. Reference: https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ide_no-cycle-V5
4. When switching semi-modal gears in HarmonyOS, the UX occasionally fails to fully display.
When switching a semi-modal from half-screen to full-screen, a gray area sometimes appears, causing the interface to fail to load completely.
This issue can be resolved by using properties introduced in semi-modal API 12.

5. HarmonyOS linearGradient is not adapted to mirrored languages.
When switching to a mirrored language, the property GradientDirection.Left does not change to GradientDirection.Right.
Row()
.size({ width: '100%', height: 50 })
.linearGradient({
direction: GradientDirection.Left,
colors: [[this.getColorString(this.bottomColorInfo.mainColor, 0), 0.0],
[this.getColorString(this.bottomColorInfo.mainColor, 1), 1.0]]
})
linearGradient does not require adaptation; Left remains the Left direction (it is not start). The app can determine the display angle based on RTL (right-to-left) logic independently.

Top comments (0)