# rte-controller-react-native

> RTE UI controller is a module to be used in the UI resource itself to facilitate the integration with RTE world.

Latest version **0.4.0-alpha.2** (published 2022-09-03) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install rte-controller-react-native
pnpm add rte-controller-react-native
yarn add rte-controller-react-native
bun add rte-controller-react-native
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.4.0-alpha.2 |
| Published | 2022-09-03 |
| First published | 2022-05-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 1.2 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | xiaqin@agora.io |
| Maintainers | deliberatekids, adonia12, halajohn, xiaqin |
| Keywords | rte-controller-react-native |

## Links

- npm: https://www.npmjs.com/package/rte-controller-react-native
- npm.io page: https://npm.io/package/rte-controller-react-native

## Dependencies (2)

- [rte-controller-base](https://npm.io/package/rte-controller-base.md) 0.4.0-alpha.1
- [react-native-flex-layout](https://npm.io/package/react-native-flex-layout.md) ^0.1.5

## Recent versions

- 0.4.0-alpha.2 (latest) — 2022-09-03
- 0.4.0-alpha.1 — 2022-09-03
- 0.4.0-alpha.0 — 2022-09-02
- 0.3.0-beta.1 — 2022-08-31
- 0.3.0-beta.0 — 2022-08-30
- 0.3.0-alpha.2 — 2022-08-29
- 0.3.0-alpha.1 — 2022-08-26
- 0.3.0-alpha.0 — 2022-08-25
- 0.2.1-beta.1 — 2022-08-09
- 0.2.1-beta.0 — 2022-08-08
- 0.2.1-alpha.0 — 2022-08-03
- 0.2.0-beta.9 — 2022-08-02
- 0.2.0-beta.8 — 2022-08-02
- 0.2.0-beta.7 — 2022-08-01
- 0.2.0-beta.6 — 2022-08-01
- … 36 more at https://npm.io/package/rte-controller-react-native/versions

## README

# rte-controller-react-native

RTE UI controller is a module to be used in the UI resource itself to facilitate the integration with RTE world.

## How to Use?

### Install

```bash
cd path/to/your project
npm i rte-controller-react-native --save-dev
```

### Use

#### Create RteContext instance

```typescript
import { createDefaultRteContext } from "rte-controller-base";

// We need to init RteContext before rendering any widget.
const rteContext = await createDefaultRteContext({
  uri: "http://192.168.0.104:8001/",
  graph_id: "0",
  extension_group: "default_ui_gateway_extension_ts_group",
  extension: "default_ui_gateway_extension_ts",
});
```

#### Use with RTE layout template

```react
import { RteLayoutComp } from "rte-controller-react-native";

return (
  <RteLayoutComp rteContext={rteContext} />
);
```

#### Use with your own layouts

```React
import {
  RteLayoutRenderOptions,
  ExtensionContainer,
} from "rte-controller-react-native";

return (
  <View
    style={{
      width: "200px",
    }}
  >
    <ExtensionContainer
      extension="default_ui_extension_ts"
      rteContext={rteContext}
      options={options}
    />
  </View>
);
```

You can use `widgetProps` in `ExtensionContainer` to define any props, which will be passed to the widget component directly.

#### Customize the timing of receiving message

By default, rte-controller will start to receive message when all the widgets are mounted.

You can customize with `setWidgetMountedListener()` in `RteContext`. For example:

```typescript
import {
  RteContext,
  RteUiWidgetInfo,
} from 'rte-controller';

rteContext.setWidgetMountedListener(
  (
    rteContext: RteContext,
    widget: RteUiWidgetInfo,
    error?: Error,
  ): void => {
    console.log(
      `The widget is ready, ${JSON.stringify(widget)}, error: ${error}`,
    );

    // Calling 'readyToReceiveExtensionMessage()' to open the message channel between the App and RTE Extension, and will receive events from RTE Extension if any.
    setTimeout(() => {
      rteContext.readyToReceiveExtensionMessage();
    }, 5000);
  },
);
```

> Keep in mind that you have to call `readyToReceiveExtensionMessage()` yourself when the App is ready to receive messages from RTE Extension.

#### Subscribe events

You can subscribe event from RTE Extension like the UI Widget with `subscribeEvent()` in `RteContext`. For example:

```typescript
rteContext.subscribeEvent({
  extension: 'default_ui_extension_ts',
  handler: (msg: RteUiWidgetMsg) => {
    console.log(
      `Receive message from default_ui_extension_ts: ${JSON.stringify(
        msg,
      )}`,
    );
  },
});
```

The `extension` and `type` are used to filter the events, you have to specify at least one. And of course, you can specify both of them.

And you can use `unsubscribeEvent()` to cancel the subscription.

---
_Source: https://npm.io/package/rte-controller-react-native · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
