Take control over your live stream video by running it yourself. Streaming + chat out of the box.
HTML activitypubbroadcastingchatdecentralizedfederationfediversegolanghacktoberfesthlslivelivestreamowncastrtmpself-hostedstreaming-videovideo
feat(web): keep viewer tabs reachable when they overflow on mobile
Gabe Kangas19573f6ae5a4
diff --git a/web/components/ui/Content/Content.module.scss b/web/components/ui/Content/Content.module.scssindex 9b6f0aaf9c..ccbada6045 100644--- a/web/components/ui/Content/Content.module.scss+++ b/web/components/ui/Content/Content.module.scss@@ -41,6 +41,42 @@margin-bottom: 0;padding-top: 0.5vh;padding-left: 1vw;++ // The mobile action-button menu floats over the right end of this+ // row (absolutely positioned, z-index 199), so anything under it+ // can't be tapped. Reserve that strip so tabs and the all-tabs+ // menu button always end before it.+ margin-right: 52px;+ }++ // rc-tabs shows its own "more" dropdown for overflowing tabs in+ // desktop mode but removes it entirely on mobile devices. The+ // all-tabs menu button replaces it in both cases, so hide the+ // built-in one here.+ // stylelint-disable-next-line declaration-no-important -- antd's own+ // `.ant-tabs > .ant-tabs-nav .ant-tabs-nav-operations` rule is more+ // specific than anything this module can express cleanly.+ :global(.ant-tabs-nav-operations) {+ display: none !important;+ }++ // Show the all-tabs menu button only while the tab bar actually+ // overflows. rc-tabs sets the ping classes on the nav wrap whenever+ // tabs are scrolled out of view on either side. Toggle visibility+ // rather than display, and fix the slot's width, so rc-tabs measures+ // the same size at mount (before the lazy icon inside has loaded) as+ // after: it only measures this slot once.+ :global(.ant-tabs-extra-content) {+ display: flex;+ align-items: center;+ justify-content: center;+ width: 40px;+ visibility: hidden;+ }++ :global(.ant-tabs-nav-wrap-ping-left) ~ :global(.ant-tabs-extra-content),+ :global(.ant-tabs-nav-wrap-ping-right) ~ :global(.ant-tabs-extra-content) {+ visibility: visible;}}@@ -102,10 +138,6 @@display: grid;}-.defaultTabBar {- width: 85%;-}-.bottomPageContentContainer {background-color: var(--theme-color-components-content-background);padding: calc(2 * var(--content-padding));diff --git a/web/components/ui/Content/MobileContent.stories.tsx b/web/components/ui/Content/MobileContent.stories.tsxnew file mode 100644index 0000000000..b7ed1d0fc8--- /dev/null+++ b/web/components/ui/Content/MobileContent.stories.tsx@@ -0,0 +1,78 @@+import React from 'react';+import { Meta, StoryFn } from '@storybook/nextjs';+import { RecoilRoot } from 'recoil';+import { MobileContent, MobileContentProps } from './MobileContent';+import { PluginTab } from '../../../interfaces/client-config.model';++const makePluginTabs = (count: number): PluginTab[] =>+ Array.from({ length: count }, (_, i) => ({+ slug: `demo-plugin/tab-${i + 1}`,+ pluginSlug: 'demo-plugin',+ title: `Plugin Tab ${i + 1}`,+ html: `<h1>Content of plugin tab ${i + 1}</h1><p>Rendered inside the plugin tab iframe.</p>`,+ }));++const meta = {+ title: 'owncast/Components/Mobile content',+ component: MobileContent,+ parameters: {+ viewport: {+ defaultViewport: 'iphone12Portrait',+ },+ docs: {+ description: {+ component:+ 'The tabbed lower section of the viewer page on mobile. When plugins ' ++ 'contribute enough tabs to overflow the screen width, an all-tabs menu ' ++ 'button appears at the right end of the tab bar so every tab stays ' ++ 'reachable without swipe-scrolling. Pick a mobile viewport to see the ' ++ 'overflow behavior.',+ },+ },+ },+} satisfies Meta<typeof MobileContent>;++export default meta;++// PluginTabFrame reads plugin styles from Recoil, so the component needs a+// RecoilRoot around it.+const Template: StoryFn<MobileContentProps> = args => (+ <RecoilRoot>+ <MobileContent {...args} />+ </RecoilRoot>+);++const defaultArgs: MobileContentProps = {+ name: 'Demo stream',+ summary: 'A stream for exercising the mobile tab bar.',+ tags: ['demo', 'tabs'],+ socialHandles: [],+ extraPageContent: '<p>This is the About tab content.</p>',+ pluginTabs: [],+ setShowFollowModal: () => {},+ showFollowersTab: false,+ online: false,+ federatedServers: [],+};++// Enough plugin tabs to overflow any phone-sized viewport: the tab bar+// scrolls and the all-tabs menu button appears next to it.+export const ManyPluginTabs = Template.bind({});+ManyPluginTabs.args = {+ ...defaultArgs,+ pluginTabs: makePluginTabs(8),+};++// A single plugin tab alongside About: everything fits, so the all-tabs+// menu button stays hidden.+export const OnePluginTab = Template.bind({});+OnePluginTab.args = {+ ...defaultArgs,+ pluginTabs: makePluginTabs(1),+};++// No plugin tabs and only one built-in tab: no tab bar is rendered at all.+export const NoTabs = Template.bind({});+NoTabs.args = {+ ...defaultArgs,+};diff --git a/web/components/ui/Content/MobileContent.tsx b/web/components/ui/Content/MobileContent.tsxindex c2408106b2..938142e068 100644--- a/web/components/ui/Content/MobileContent.tsx+++ b/web/components/ui/Content/MobileContent.tsx@@ -1,10 +1,13 @@-import React, { ComponentType, FC } from 'react';+import React, { ComponentType, FC, useState } from 'react';import dynamic from 'next/dynamic';-import { TabsProps } from 'antd';+import { Button, Dropdown } from 'antd';+import type { TabsProps } from 'antd';+import { useTranslation } from 'next-export-i18n';import { ErrorBoundary } from 'react-error-boundary';import classNames from 'classnames';import { SocialLink } from '../../../interfaces/social-link.model';import { PluginTab } from '../../../interfaces/client-config.model';+import { Localization } from '../../../types/localization';import styles from './Content.module.scss';import { CustomPageContent } from '../CustomPageContent/CustomPageContent';import { PluginTabFrame } from '../PluginTabFrame/PluginTabFrame';@@ -30,6 +33,10 @@ const Tabs: ComponentType<TabsProps> = dynamic(() => import('antd').then(mod =>ssr: false,});+const UnorderedListOutlined = dynamic(() => import('@ant-design/icons/UnorderedListOutlined'), {+ ssr: false,+});+const FollowerCollection = dynamic(() =>import('../followers/FollowerCollection/FollowerCollection').then(@@ -64,6 +71,9 @@ export const MobileContent: FC<MobileContentProps> = ({online,federatedServers = [],}) => {+ const { t } = useTranslation();+ const [activeKey, setActiveKey] = useState('0');+const aboutTabContent = (<><ContentHeader name={name} summary={summary} tags={tags} links={socialHandles} logo="/logo" />@@ -119,6 +129,31 @@ export const MobileContent: FC<MobileContentProps> = ({});});+ // Menu listing every tab so any of them stays reachable when the tab+ // bar overflows the screen. rc-tabs turns its own "more" dropdown off+ // on mobile devices, leaving swipe-scrolling as the only way to reach+ // far tabs. This button is shown via CSS only while the tab bar+ // actually overflows (the nav-wrap ping classes).+ const translatedShowAllTabs = t(Localization.Frontend.showAllTabs);+ const showAllTabsLabel =+ translatedShowAllTabs === Localization.Frontend.showAllTabs+ ? 'Show all tabs'+ : translatedShowAllTabs;++ const allTabsMenu = (+ <Dropdown+ menu={{+ items: items.map(({ key, label }) => ({ key, label })),+ onClick: ({ key }) => setActiveKey(key),+ selectedKeys: [activeKey],+ }}+ placement="bottomRight"+ trigger={['click']}+ >+ <Button type="text" icon={<UnorderedListOutlined />} aria-label={showAllTabsLabel} />+ </Dropdown>+ );+return (<ErrorBoundary// eslint-disable-next-line react/no-unstable-nested-components@@ -128,7 +163,12 @@ export const MobileContent: FC<MobileContentProps> = ({>{items.length > 1 ? (<div className={classNames([styles.lowerSectionMobileTabbed, online && styles.online])}>- <Tabs defaultActiveKey="0" items={items} />+ <Tabs+ activeKey={activeKey}+ onChange={setActiveKey}+ items={items}+ tabBarExtraContent={{ right: allTabsMenu }}+ /></div>) : (<div>{aboutTabContent}</div>diff --git a/web/i18n/en/translation.json b/web/i18n/en/translation.jsonindex 25affa4e0c..fc07af4626 100644--- a/web/i18n/en/translation.json+++ b/web/i18n/en/translation.json@@ -434,6 +434,7 @@"offlineFediverseOnly": "This stream is offline. <span class='follow-link'>Follow</span> {{fediverseAccount}} on the Fediverse to see the next time {{streamer}} goes live.","offlineNotifyAndFediverse": "This stream is offline. You can <span class='notify-link'>be notified</span> the next time {{streamer}} goes live or <span class='follow-link'>follow</span> {{fediverseAccount}} on the Fediverse.","offlineNotifyOnly": "This stream is offline. <span class='notify-link'>Be notified</span> the next time {{streamer}} goes live.",+ "showAllTabs": "Show all tabs","unmute": "Unmute"},"Testing": {diff --git a/web/types/localization.ts b/web/types/localization.tsindex 66e142cdcf..f723991ba3 100644--- a/web/types/localization.ts+++ b/web/types/localization.ts@@ -32,6 +32,7 @@ export const Localization = {skipToPlayer: 'Skip to player',skipToContent: 'Skip to page content',skipToFooter: 'Skip to footer',+ showAllTabs: 'Frontend.showAllTabs',// Social and external servicesstayUpdated: 'Stay updated!',