Add options to hide header and composer of room view for the module api (#31095)

* feat: add props to hide header in `RoomView`

* feat: add props to hide composer in `RoomView`

* feat: pass `RoomViewProps` to room view in `renderRoomView`

* refactor: add doc and use existing types

* test: add tests for new room view props
This commit is contained in:
Florian Duros
2025-11-05 13:52:10 +01:00
committed by GitHub
parent 52eb8a9979
commit 4d66a85e73
4 changed files with 491 additions and 29 deletions

View File

@@ -165,6 +165,16 @@ interface IRoomProps extends RoomViewProps {
* Omitting this will mean that RoomView renders for the room held in SDKContext.RoomViewStore.
*/
roomId?: string;
/*
* If true, hide the header
*/
hideHeader?: boolean;
/*
* If true, hide the composer
*/
hideComposer?: boolean;
}
export { MainSplitContentType };
@@ -2455,6 +2465,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
let messageComposer;
const showComposer =
!this.props.hideComposer &&
!isRoomEncryptionLoading &&
// joined and not showing search results
myMembership === KnownMembership.Join &&
@@ -2665,10 +2676,12 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
ref={this.roomViewBody}
data-layout={this.state.layout}
>
<RoomHeader
room={this.state.room}
additionalButtons={this.state.viewRoomOpts.buttons}
/>
{!this.props.hideHeader && (
<RoomHeader
room={this.state.room}
additionalButtons={this.state.viewRoomOpts.buttons}
/>
)}
{mainSplitBody}
</div>
</MainSplit>

View File

@@ -12,6 +12,9 @@ import { MatrixClientPeg } from "../MatrixClientPeg";
import type { Room } from "matrix-js-sdk/src/matrix";
interface RoomViewPropsWithRoomId extends RoomViewProps {
/**
* The ID of the room to display
*/
roomId?: string;
}
@@ -26,9 +29,8 @@ interface Components {
}
export class ElementWebBuiltinsApi implements BuiltinsApi {
private _roomView?: React.ComponentType<RoomViewPropsWithRoomId>;
private _roomAvatar?: React.ComponentType<RoomAvatarProps>;
private _roomView?: Components["roomView"];
private _roomAvatar?: Components["roomAvatar"];
/**
* Sets the components used by the API.
*
@@ -59,9 +61,9 @@ export class ElementWebBuiltinsApi implements BuiltinsApi {
return this._roomAvatar;
}
public renderRoomView(roomId: string): React.ReactNode {
public renderRoomView(roomId: string, props?: RoomViewProps): React.ReactNode {
const Component = this.getRoomViewComponent();
return <Component roomId={roomId} />;
return <Component roomId={roomId} {...props} />;
}
public renderRoomAvatar(roomId: string, size?: string): React.ReactNode {