This module provides core capabilities of Reader Kit, including the page data base class, page status, content pagination information, page typesetting attributes, and component controller.
Since: 5.0.4(16)
Page data base class.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.4(16).
System capability: SystemCapability.Reader.ReaderService.ReaderCore
Since: 5.0.4(16)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| nodeType | string | No | No | Node type. The value is fixed at ReaderCoreIdentity, indicating the reader node. |
| dataId | string | No | No | Node ID, which is automatically generated based on the resource index and page offset. |
constructor(nodeType: string, nodeDataId: string)
Page data constructor.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.4(16).
System capability: SystemCapability.Reader.ReaderService.ReaderCore
Since: 5.0.4(16)
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| nodeType | string | Yes | Node type. The value is fixed at ReaderCoreIdentity, indicating the reader node. |
| nodeDataId | string | Yes | Node ID, which is automatically generated based on the resourceIndex and pageOffset parameters of the PageDataInfo child class. |
Page status.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.4(16).
System capability: SystemCapability.Reader.ReaderService.ReaderCore
Since: 5.0.4(16)
| Name | Value | Description |
|---|---|---|
| PAGE_WAITING | 1 | Initialization succeeded. Wait for the typesetting engine notification. |
| PAGE_LOADING | 2 | Initialization succeeded. Wait for the typesetting result. |
| PAGE_ON_SHOW | 3 | The typesetting is successful and the reading page is displayed. |
| OPEN_BOOK_FAIL | 4 | The typesetting fails and the page fails to be loaded. |
Content pagination information, which is inherited from PageDatabaseBean.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.4(16).
System capability: SystemCapability.Reader.ReaderService.ReaderCore
Since: 5.0.4(16)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| nodeType | string | No | No | Node type. The value is fixed at ReaderCoreIdentity, indicating the reader node. |
| dataId | string | No | No | Node ID, which is automatically generated based on the resourceIndex and pageOffset parameters. |
| pageHeaderContent | string | No | No | Page header text. (This parameter is reserved.) |
| pageFooterContent | string | No | No | Page footer text. (This parameter is reserved.) |
| startDomPos | string | No | No | Start position of the current page. |
| endDomPos | string | No | No | End position of the current page. |
| state | PageState | No | No | Page status. |
| resourceIndex | number | No | No | Spine item index (SpineItem.index). |
| pageOffset | number | No | No | Page number offset, starting from 0. For example, if a content resource file contains 50 pages, the value ranges from 0 to 49. |
constructor(nodeType: string, nodeId: string)
Constructor of content pagination information.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.4(16).
System capability: SystemCapability.Reader.ReaderService.ReaderCore
Since: 5.0.4(16)
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| nodeType | string | Yes | Node type. The value is fixed at ReaderCoreIdentity. |
| nodeId | string | Yes | Node ID, which is automatically generated based on the resourceIndex and pageOffset parameters of the PageDataInfo child class. |
Page typesetting attributes.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.4(16).
System capability: SystemCapability.Reader.ReaderService.ReaderCore
Since: 5.0.4(16)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| fontName | string | No | No | Font name. |
| fontSize | number | No | No | Font size, in pixels. |
| fontWeight | number | No | No | Font weight, which depends on whether the referenced font file supports setting the font weight of the text. (This parameter is reserved.) |
| fontColor | string | No | No | Font color Example: #ffffff or rgba(248, 249, 250, 1). The font color value constraints are as follows: For hexadecimal color values, only the 6-digit format is supported, and opacity setting is not supported. For RGBA color values, the opacity value must be 1. |
| fontPath | string | No | No | Local path of a font file. The following storage paths are supported: resources/rawfile in the project directory. This path is suitable for scenarios where fonts are preset. App sandbox directory. This path is suitable for scenarios where fonts are downloaded online. |
| lineHeight | number | No | No | Line height coefficient. The actual display height of a line of text equals fontSize x lineHeight. |
| nightMode | boolean | No | No | Indicates whether to use the dark mode. You need to manually set the parameter when detecting switch between dark and light modes. It is used for drawing the back theme color in simulated page turning. true: dark mode. false: light mode. The default value is false. |
| themeColor | string | No | No | Theme background color. Example: #ffffff or rgba(248, 249, 250, 1). If a background image is set, this parameter is used to draw the back theme color in simulated page turning. If no background image is set, this parameter is used to render the background color of the reading page. The background color value constraints are as follows: For hexadecimal color values, only the 6-digit format is supported, and opacity setting is not supported. For RGBA color values, the opacity value must be 1. |
| themeBgImg | string | No | No | Theme background image path, which is used for drawing the reading page background. The following storage paths are supported: resources/rawfile in the project directory. This path is suitable for scenarios where a background image is preset. App sandbox directory. This path is suitable for scenarios where a background image is downloaded online. |
| flipMode | string | No | No | Page turning mode. 0: simulated page turning 1: horizontal swipe The default value is 0. |
| scaledDensity | number | No | No | Scaling factor of the system displayed text. The value is obtained from the display.getDefaultDisplaySync().scaledDensity parameter. When the text scaling factor changes in scenarios such as Multi-Window, you need to call the setPageConfig API of ReaderComponentController to update the attribute. |
| viewPortWidth | number | No | No | Viewport width, in pixels. |
| viewPortHeight | number | No | No | Viewport height, in pixels. |
ReadPageComponent controller, which must be used together with ReadPageComponent.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.4(16).
System capability: SystemCapability.Reader.ReaderService.ReaderCore
Since: 5.0.4(16)
init(context: common.UIAbilityContext): Promise<void>
Initializes ReaderComponentController. This API returns the result asynchronously through a promise.
When integrating ReaderComponentController, the initialization API must be executed before other APIs of the controller.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.4(16).
System capability: SystemCapability.Reader.ReaderService.ReaderCore
Since: 5.0.4(16)
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| context | common.UIAbilityContext | Yes | App context. |
Returns
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
| ID | Error Message |
|---|---|
| 401 | Parameter error. |
| 1016910004 | Invalid caller. |
Example:
import { readerCore, ReadPageComponent } from '@kit.ReaderKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Reader {
private readerComponentController: readerCore.ReaderComponentController = new readerCore.ReaderComponentController();
aboutToAppear(): void {
this.init();
}
private async init() {
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
await this.readerComponentController.init(context);
hilog.info(0x0000, 'testTag', `init succeeded`);
}
build() {
Stack() {
ReadPageComponent({
controller: this.readerComponentController,
readerCallback: (err: BusinessError, data: readerCore.ReaderComponentController) => {
this.readerComponentController = data;
}
})
}.width('100%').height('100%')
}
} registerBookParser(bookParserHandler: bookParser.BookParserHandler): void
Registers a book parser.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.4(16).
System capability: SystemCapability.Reader.ReaderService.ReaderCore
Since: 5.0.4(16)
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| bookParserHandler | bookParser.BookParserHandler | Yes | Book parser. |
Error codes
| ID | Error Message |
|---|---|
| 401 | Parameter error. |
| 1016900002 | Read Page Component is not initialized. |
| 1016900003 | Invalid request. |
| 1016900999 | Other error. |
Example
import { bookParser, readerCore, ReadPageComponent } from '@kit.ReaderKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Reader {
private readerComponentController: readerCore.ReaderComponentController = new readerCore.ReaderComponentController();
aboutToAppear(): void {
this.registerBookParser();
}
private async registerBookParser() {
// Initialize the book parser for the book file that has been imported to the app sandbox directory.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let filePath: string = `${context.filesDir}/abc.epub`;
let bookParserHandler: bookParser.BookParserHandler = await bookParser.getDefaultHandler(filePath);
await this.readerComponentController.init(context);
this.readerComponentController.registerBookParser(bookParserHandler);
hilog.info(0x0000, 'testTag', `registerBookParser succeeded`);
}
build() {
Stack() {
ReadPageComponent({
controller: this.readerComponentController,
readerCallback: (err: BusinessError, data: readerCore.ReaderComponentController) => {
this.readerComponentController = data;
}
})
}.width('100%').height('100%')
}
} setPageConfig(pageConfig: ReaderSetting): void
Sets or modifies page typesetting attributes.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.4(16).
System capability: SystemCapability.Reader.ReaderService.ReaderCore
Since: 5.0.4(16)
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| pageConfig | ReaderSetting | Yes | Page typesetting attributes. |
Error codes
| ID | Error Message |
|---|---|
| 401 | Parameter error. |
| 1016900002 | Read Page Component is not initialized. |
| 1016900003 | Invalid request. |
| 1016900999 | Other error. |
Example
import { readerCore, ReadPageComponent } from '@kit.ReaderKit';
import { common } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { display } from '@kit.ArkUI';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Reader {
private readerComponentController: readerCore.ReaderComponentController = new readerCore.ReaderComponentController();
aboutToAppear(): void {
this.setPageConfig();
}
private async setPageConfig(){
let readerSetting: readerCore.ReaderSetting = {
fontName: 'System font',
fontPath: '',
fontSize: 18,
fontColor: '#000000',
fontWeight: 400,
lineHeight: 1.9,
nightMode: false,
themeColor: 'rgba(248, 249, 250, 1)',
themeBgImg: '',
flipMode: '0',
scaledDensity: display.getDefaultDisplaySync().scaledDensity > 0 ? display.getDefaultDisplaySync().scaledDensity :
1,
viewPortWidth: 1260, // Viewport width. Obtain it based on the actual device characteristics. Otherwise, the reading page may have display issues.
viewPortHeight: 2720 // Viewport height. Obtain it based on the actual device characteristics. Otherwise, the reading page may have display issues.
};
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
await this.readerComponentController.init(context);
this.readerComponentController.setPageConfig(readerSetting);
hilog.info(0x0000, 'testTag', `setPageConfig succeeded`);
}
build() {
Stack() {
ReadPageComponent({
controller: this.readerComponentController,
readerCallback: (err: BusinessError, data: readerCore.ReaderComponentController) => {
this.readerComponentController = data;
}
})
}.width('100%').height('100%')
}
} startPlay(spineIndex: number, domPos: string): Promise<void>
Opens a book at a specified reading progress. This API returns the result asynchronously through a promise.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.4(16).
System capability: SystemCapability.Reader.ReaderService.ReaderCore
Since: 5.0.4(16)
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| spineIndex | number | Yes | Content resource index (SpineItem.index). |
| domPos | string | Yes | Last reading progress of a user. |
Returns
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
| ID | Error Message |
|---|---|
| 401 | Parameter error. |
| 1016900002 | Read Page Component is not initialized. |
| 1016900003 | Invalid request. |
| 1016900999 | Other error. |
| 1016910001 | Invalid spine item. |
| 1016910002 | Unexpected spine item resource data. |
| 1016910003 | Spine item resource data out of range. |
Example
import { bookParser, readerCore, ReadPageComponent } from '@kit.ReaderKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Reader {
private readerComponentController: readerCore.ReaderComponentController = new readerCore.ReaderComponentController();
aboutToAppear(): void {
this.startPlay();
}
private async startPlay() {
// Initialize the book parser for the book file that has been imported to the app sandbox directory.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let filePath: string = `${context.filesDir}/abc.epub`;
let bookParserHandler: bookParser.BookParserHandler = await bookParser.getDefaultHandler(filePath);
let spineList: bookParser.SpineItem[] = bookParserHandler.getSpineList();
let spineIndex: number = spineList[0].index;
let domPos: string = '';
await this.readerComponentController.init(context);
this.readerComponentController.registerBookParser(bookParserHandler);
// Call the startPlay API to initialize the book content display.
await this.readerComponentController.startPlay(spineIndex || 0, domPos);
hilog.info(0x0000, 'testTag', `startPlay succeeded`);
}
build() {
Stack() {
ReadPageComponent({
controller: this.readerComponentController,
readerCallback: (err: BusinessError, data: readerCore.ReaderComponentController) => {
this.readerComponentController = data;
}
})
}.width('100%').height('100%')
}
} flipPage(isNext: boolean): void
Triggers ReadPageComponent to turn pages.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.4(16).
System capability: SystemCapability.Reader.ReaderService.ReaderCore
Since: 5.0.4(16)
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| isNext | boolean | Yes | Indicates whether to turn to the next page. true: Turn to the next page. false: Turn to the previous page. |
Error codes
| ID | Error Message |
|---|---|
| 401 | Parameter error. |
| 1016900002 | Read Page Component is not initialized. |
| 1016900003 | Invalid request. |
| 1016900999 | Other error. |
Example
import { readerCore, ReadPageComponent } from '@kit.ReaderKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Reader {
private readerComponentController: readerCore.ReaderComponentController = new readerCore.ReaderComponentController();
aboutToAppear(): void {
this.flipPage();
}
private async flipPage() {
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
await this.readerComponentController.init(context);
// Turn to the next page.
this.readerComponentController.flipPage(true);
hilog.info(0x0000, 'testTag', `flipPage succeeded`);
}
build() {
Stack() {
ReadPageComponent({
controller: this.readerComponentController,
readerCallback: (err: BusinessError, data: readerCore.ReaderComponentController) => {
this.readerComponentController = data;
}
})
}.width('100%').height('100%')
}
} releaseBook(): void
Releases book resources. This API is used in resource releasing scenarios such as exiting a reader.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.4(16).
System capability: SystemCapability.Reader.ReaderService.ReaderCore
Since: 5.0.4(16)
Example:
import { readerCore, ReadPageComponent } from '@kit.ReaderKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Reader {
private readerComponentController: readerCore.ReaderComponentController = new readerCore.ReaderComponentController();
aboutToAppear(): void {
this.releaseBook();
}
private async releaseBook() {
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
await this.readerComponentController.init(context);
// Release the resources used for loading the book.
this.readerComponentController.releaseBook();
hilog.info(0x0000, 'testTag', `releaseBook succeeded`);
}
build() {
Stack() {
ReadPageComponent({
controller: this.readerComponentController,
readerCallback: (err: BusinessError, data: readerCore.ReaderComponentController) => {
this.readerComponentController = data;
}
})
}.width('100%').height('100%')
}
} on(type: 'pageShow', callback: Callback<PageDataInfo>): void
Registers the notification service displayed on the page, which is triggered after the page layout is successfully displayed.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.4(16).
System capability: SystemCapability.Reader.ReaderService.ReaderCore
Since: 5.0.4(16)
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The value is fixed at pageShow. |
| callback | Callback<PageDataInfo> | Yes | Callback function, which returns the content pagination layout information. |
Example:
import { readerCore, ReadPageComponent } from '@kit.ReaderKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Reader {
private readerComponentController: readerCore.ReaderComponentController = new readerCore.ReaderComponentController();
aboutToAppear(): void {
this.registerListener();
}
private async registerListener() {
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
await this.readerComponentController.init(context)
// This is only a sample method call. To actually trigger the callback, you must use the startPlay API.
this.readerComponentController.on('pageShow', (data: readerCore.PageDataInfo): void => {
// You can save the content pagination layout data here, and pass the data.resourceIndex and data.startDomPos values to the startPlay API to resume reading when required.
hilog.info(0x0000, 'testTag', 'pageshow: data is: ' + JSON.stringify(data));
});
}
build() {
Stack() {
ReadPageComponent({
controller: this.readerComponentController,
readerCallback: (err: BusinessError, data: readerCore.ReaderComponentController) => {
this.readerComponentController = data;
}
})
}.width('100%').height('100%')
}
} off(type: 'pageShow', callback?: Callback<PageDataInfo>): void
Deregisters a callback for the chapter content pagination result. This API can be called when a page is destroyed.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.4(16).
System capability: SystemCapability.Reader.ReaderService.ReaderCore
Since: 5.0.4(16)
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The value is fixed at pageShow. |
| callback | Callback<PageDataInfo> | No | Callback function. The callback function used for on('pageShow') registration must be passed. Otherwise, all callback functions are deregistered. |
Example:
import { readerCore, ReadPageComponent } from '@kit.ReaderKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Reader {
private readerComponentController: readerCore.ReaderComponentController = new readerCore.ReaderComponentController();
aboutToAppear(): void {
this.unregisterListener();
}
private async unregisterListener(){
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let readerComponentController: readerCore.ReaderComponentController = new readerCore.ReaderComponentController();
await readerComponentController.init(context);
readerComponentController.off('pageShow');
hilog.info(0x0000, 'testTag', `offPageShow succeeded`);
}
build() {
Stack() {
ReadPageComponent({
controller: this.readerComponentController,
readerCallback: (err: BusinessError, data: readerCore.ReaderComponentController) => {
this.readerComponentController = data;
}
})
}.width('100%').height('100%')
}
} on(type: 'resourceRequest', callback: bookParser.CallbackRes<string, ArrayBuffer>): void
Registers a resource request callback. If a custom background or font is set, the typesetting engine uses this API to obtain the resource ArrayBuffer.
When multiple resource request callbacks are registered, only the last one takes effect.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.4(16).
System capability: SystemCapability.Reader.ReaderService.ReaderCore
Since: 5.0.4(16)
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The value is fixed at resourceRequest. |
| callback | bookParser.CallbackRes<string, ArrayBuffer> | Yes | Callback function (string: path of the requested resource; ArrayBuffer: binary data of the requested resource). |
Example:
import { bookParser, readerCore, ReadPageComponent } from '@kit.ReaderKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Reader {
private readerComponentController: readerCore.ReaderComponentController = new readerCore.ReaderComponentController();
// Replace the value with the path to the font file, including the file name.
private selectFontPath = 'fonts/SourceHanSerifCN-VF.ttf';
aboutToAppear(): void {
this.registerListener();
}
private async registerListener() {
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
await this.readerComponentController.init(context);
// This is only a sample method call. To actually trigger the callback, you must use the startPlay API.
this.readerComponentController.on('resourceRequest', this.resourceRequest);
}
private resourceRequest: bookParser.CallbackRes<string, ArrayBuffer> = (fileName: string): ArrayBuffer => {
if (this.isFont(fileName)) {
let res = $rawfile(this.selectFontPath);
let context = this.getUIContext().getHostContext();
if (res && context) {
// Obtain the font data in the resource path.
let value: Uint8Array = context.resourceManager.getRawFileContentSync(this.selectFontPath);
hilog.info(0x0000, 'testTag', 'resourceRequest : get success');
return value.buffer as ArrayBuffer;
}
}
return new ArrayBuffer(0);
}
private isFont(filePath: string): boolean {
let options = ['.ttf', '.woff2', '.otf'];
let path = filePath.toLowerCase();
let result = path.indexOf(options[0]) != -1 || path.indexOf(options[1]) != -1 || path.indexOf(options[2]) != -1;
hilog.info(0x0000, 'testTag', 'isFont = ' + result);
return result;
}
build() {
Stack() {
ReadPageComponent({
controller: this.readerComponentController,
readerCallback: (err: BusinessError, data: readerCore.ReaderComponentController) => {
this.readerComponentController = data;
}
})
}.width('100%').height('100%')
}
} off(type: 'resourceRequest', callback?: bookParser.CallbackRes<string, ArrayBuffer>): void
Deregisters a resource request callback. This API can be called when a page is destroyed.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.4(16).
System capability: SystemCapability.Reader.ReaderService.ReaderCore
Since: 5.0.4(16)
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The value is fixed at resourceRequest. |
| callback | bookParser.CallbackRes<string, ArrayBuffer> | No | Callback function. The callback function used for on('resourceRequest') registration must be passed. Otherwise, all callback functions are deregistered. |
Example:
import { readerCore, ReadPageComponent } from '@kit.ReaderKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Reader {
private readerComponentController: readerCore.ReaderComponentController = new readerCore.ReaderComponentController();
aboutToAppear(): void {
this.unregisterListener();
}
private async unregisterListener() {
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
await this.readerComponentController.init(context);
this.readerComponentController.off('resourceRequest');
hilog.info(0x0000, 'testTag', `offResourceRequest succeeded`);
}
build() {
Stack() {
ReadPageComponent({
controller: this.readerComponentController,
readerCallback: (err: BusinessError, data: readerCore.ReaderComponentController) => {
this.readerComponentController = data;
}
})
}.width('100%').height('100%')
}
}