Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(toolbox/native): refactoring (#17420)

Calinteodor1374539e9bac
diff --git a/react/features/toolbox/components/native/Toolbox.tsx b/react/features/toolbox/components/native/Toolbox.tsx
index 0249400a2d..138f9a3254 100644
--- a/react/features/toolbox/components/native/Toolbox.tsx
+++ b/react/features/toolbox/components/native/Toolbox.tsx
@@ -54,10 +54,6 @@ function Toolbox(props: IProps) {
dispatch
} = props;
- if (!_visible) {
- return null;
- }
-
const { clientWidth } = useSelector((state: IReduxState) => state['features/base/responsive-ui']);
const { customToolbarButtons } = useSelector((state: IReduxState) => state['features/base/config']);
const toolbarBackgroundColor = useSelector((state: IReduxState) => state['features/base/config'].toolbarConfig?.backgroundColor);
@@ -68,6 +64,10 @@ function Toolbox(props: IProps) {
const allButtons = useNativeToolboxButtons(customToolbarButtons);
+ if (!_visible) {
+ return null;
+ }
+
const { mainMenuButtons } = getVisibleNativeButtons({
allButtons,
clientWidth,
diff --git a/react/features/toolbox/hooks.native.ts b/react/features/toolbox/hooks.native.ts
index 99adb12d85..608349b14d 100644
--- a/react/features/toolbox/hooks.native.ts
+++ b/react/features/toolbox/hooks.native.ts
@@ -1,3 +1,4 @@
+import { useMemo } from 'react';
import { useSelector } from 'react-redux';
import ChatButton from '../chat/components/native/ChatButton';
@@ -63,73 +64,6 @@ const hangup = {
group: 3
};
-/**
- * A hook that returns the audio mute button.
- *
- * @returns {Object | undefined}
- */
-function getAudioMuteButton() {
- const _iAmVisitor = useSelector(iAmVisitor);
-
- if (!_iAmVisitor) {
- return microphone;
- }
-}
-
-/**
- * A hook that returns the video mute button.
- *
- * @returns {Object | undefined}
- */
-function getVideoMuteButton() {
- const _iAmVisitor = useSelector(iAmVisitor);
-
- if (!_iAmVisitor) {
- return camera;
- }
-}
-
-/**
- * A hook that returns the chat button.
- *
- * @returns {Object | undefined}
- */
-function getChatButton() {
- return chat;
-}
-
-/**
- * A hook that returns the screen sharing button.
- *
- * @returns {Object | undefined}
- */
-function getScreenSharingButton() {
- const _iAmVisitor = useSelector(iAmVisitor);
- const _isScreenShareButtonDisabled = useSelector(isDesktopShareButtonDisabled);
-
- if (!_isScreenShareButtonDisabled && !_iAmVisitor) {
- return screensharing;
- }
-}
-
-/**
- * A hook that returns the tile view button.
- *
- * @returns {Object | undefined}
- */
-function getTileViewButton() {
- return tileview;
-}
-
-/**
- * A hook that returns the overflow menu button.
- *
- * @returns {Object | undefined}
- */
-function getOverflowMenuButton() {
- return overflowmenu;
-}
-
/**
* Returns all buttons that could be rendered.
*
@@ -138,44 +72,44 @@ function getOverflowMenuButton() {
*/
export function useNativeToolboxButtons(
_customToolbarButtons?: ICustomToolbarButton[]): { [key: string]: IToolboxNativeButton; } {
- const audioMuteButton = getAudioMuteButton();
- const videoMuteButton = getVideoMuteButton();
- const chatButton = getChatButton();
- const screenSharingButton = getScreenSharingButton();
- const tileViewButton = getTileViewButton();
- const overflowMenuButton = getOverflowMenuButton();
-
- const buttons: { [key in NativeToolbarButton]?: IToolboxNativeButton; } = {
- microphone: audioMuteButton,
- camera: videoMuteButton,
- chat: chatButton,
- desktop: screenSharingButton,
- raisehand,
- tileview: tileViewButton,
- overflowmenu: overflowMenuButton,
- hangup
- };
- const buttonKeys = Object.keys(buttons) as NativeToolbarButton[];
-
- buttonKeys.forEach(
- key => typeof buttons[key] === 'undefined' && delete buttons[key]);
-
- const customButtons = _customToolbarButtons?.reduce((prev, { backgroundColor, icon, id, text }) => {
- prev[id] = {
- backgroundColor,
- key: id,
- id,
- Content: CustomOptionButton,
- group: 4,
- icon,
- text
- };
+ const _iAmVisitor = useSelector(iAmVisitor);
+ const _isScreenShareButtonDisabled = useSelector(isDesktopShareButtonDisabled);
- return prev;
- }, {} as { [key: string]: ICustomToolbarButton; });
+ return useMemo(() => {
+ const buttons: { [key in NativeToolbarButton]?: IToolboxNativeButton; } = {
+ chat,
+ raisehand,
+ tileview,
+ overflowmenu,
+ hangup
+ };
- return {
- ...buttons,
- ...customButtons
- };
+ if (!_iAmVisitor) {
+ buttons.microphone = microphone;
+ buttons.camera = camera;
+
+ if (!_isScreenShareButtonDisabled) {
+ buttons.desktop = screensharing;
+ }
+ }
+
+ const customButtons = _customToolbarButtons?.reduce((prev, { backgroundColor, icon, id, text }) => {
+ prev[id] = {
+ backgroundColor,
+ key: id,
+ id,
+ Content: CustomOptionButton,
+ group: 4,
+ icon,
+ text
+ };
+
+ return prev;
+ }, {} as { [key: string]: ICustomToolbarButton; });
+
+ return {
+ ...buttons,
+ ...customButtons
+ };
+ }, [ _iAmVisitor, _isScreenShareButtonDisabled, _customToolbarButtons ]);
}