Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add buttons to hide/show ui #632

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 53 additions & 2 deletions packages/react-native-ui/src/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type API_IndexHash, type Args, type StoryContext } from '@storybook/cor
import type { ReactRenderer } from '@storybook/react';
import { styled, useTheme } from '@storybook/react-native-theming';
import { ReactNode, useRef, useState } from 'react';
import { ScrollView, Text, View } from 'react-native';
import { ScrollView, Text, TouchableOpacity, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { IconButton } from './IconButton';
import { useLayout } from './LayoutProvider';
Expand All @@ -16,6 +16,8 @@ import { BottomBarToggleIcon } from './icon/BottomBarToggleIcon';
import { DarkLogo } from './icon/DarkLogo';
import { Logo } from './icon/Logo';
import { MenuIcon } from './icon/MenuIcon';
import { FullscreenIcon } from './icon/FullscreenIcon';
import { CloseFullscreenIcon } from './icon/CloseFullscreenIcon';

export const Layout = ({
storyHash,
Expand All @@ -36,6 +38,8 @@ export const Layout = ({

const [desktopAddonsPanelOpen, setDesktopAddonsPanelOpen] = useState(true);

const [uiHidden, setUiHidden] = useState(false);

if (isDesktop) {
return (
<View
Expand Down Expand Up @@ -131,7 +135,29 @@ export const Layout = ({

return (
<View style={{ flex: 1, paddingTop: insets.top, backgroundColor: theme.background.content }}>
<View style={{ flex: 1, overflow: 'hidden' }}>{children}</View>
<View style={{ flex: 1, overflow: 'hidden' }}>
{children}

<TouchableOpacity
style={{
position: 'absolute',
bottom: uiHidden ? 56 + insets.bottom : 16,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in the future it might be useful to make it draggable (like android notification bubbles), in case it overlaps with buttons of a story component.

right: 16,
backgroundColor: 'white',
padding: 4,
borderRadius: 4,
borderWidth: 1,
borderColor: theme.appBorderColor,
}}
onPress={() => setUiHidden(!uiHidden)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though we don't have any other calls of setUiHidden so it should not be a problem. I would suggest using function setter for toggling.

Suggested change
onPress={() => setUiHidden(!uiHidden)}
onPress={() => setUiHidden(prev => !prev)}

>
{uiHidden ? (
<CloseFullscreenIcon color={theme.color.mediumdark} />
) : (
<FullscreenIcon color={theme.color.mediumdark} />
Comment on lines +155 to +157
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably it's better to use theme.background.content.
Otherwise it does not respeect browsers darkmode, right?

)}
</TouchableOpacity>
</View>

<Container style={{ marginBottom: insets.bottom }}>
<Nav>
Expand Down Expand Up @@ -163,6 +189,7 @@ export const Layout = ({
<DarkLogo height={25} width={125} />
)}
</View>

<Sidebar
extra={[]}
previewInitialized
Expand All @@ -181,6 +208,30 @@ export const Layout = ({
</MobileMenuDrawer>

<MobileAddonsPanel ref={addonPanelRef} storyId={story?.id} />

{!uiHidden ? (
<Container style={{ marginBottom: insets.bottom }}>
<Nav>
<Button
style={{ flexShrink: 1 }}
hitSlop={{ bottom: 10, left: 10, right: 10, top: 10 }}
onPress={() => {
mobileMenuDrawerRef.current.setMobileMenuOpen(true);
}}
>
<MenuIcon color={theme.color.mediumdark} />
<Text style={{ flexShrink: 1, color: theme.color.defaultText }} numberOfLines={1}>
{story?.title}/{story?.name}
</Text>
</Button>

<IconButton
onPress={() => addonPanelRef.current.setAddonsPanelOpen(true)}
Icon={BottomBarToggleIcon}
/>
</Nav>
</Container>
) : null}
</View>
);
};
Expand Down
19 changes: 19 additions & 0 deletions packages/react-native-ui/src/icon/CloseFullscreenIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as React from 'react';
import Svg, { Path, SvgProps } from 'react-native-svg';
import { useTheme } from '@storybook/react-native-theming';

export function CloseFullscreenIcon({ color, width = 14, height = 14, ...props }: SvgProps) {
const theme = useTheme();

return (
<Svg
fill={color ?? theme.color.defaultText}
height={height}
viewBox="0 0 16 16"
width={width}
{...props}
>
<Path d="M5.5 0a.5.5 0 01.5.5v4A1.5 1.5 0 014.5 6h-4a.5.5 0 010-1h4a.5.5 0 00.5-.5v-4a.5.5 0 01.5-.5zm5 0a.5.5 0 01.5.5v4a.5.5 0 00.5.5h4a.5.5 0 010 1h-4A1.5 1.5 0 0110 4.5v-4a.5.5 0 01.5-.5zM0 10.5a.5.5 0 01.5-.5h4A1.5 1.5 0 016 11.5v4a.5.5 0 01-1 0v-4a.5.5 0 00-.5-.5h-4a.5.5 0 01-.5-.5zm10 1a1.5 1.5 0 011.5-1.5h4a.5.5 0 010 1h-4a.5.5 0 00-.5.5v4a.5.5 0 01-1 0v-4z" />
</Svg>
);
}
21 changes: 21 additions & 0 deletions packages/react-native-ui/src/icon/FullscreenIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as React from 'react';
import Svg, { Path, SvgProps } from 'react-native-svg';
import { useTheme } from '@storybook/react-native-theming';

export function FullscreenIcon({
color, //= '#2E3438',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is a missed debug statement?

width = 14,
height = 14,
...props
}: SvgProps) {
const theme = useTheme();

return (
<Svg width={width} height={height} viewBox="0 0 14 14" fill="none" {...props}>
<Path
d="M1.5 1h2a.5.5 0 010 1h-.793l3.147 3.146a.5.5 0 11-.708.708L2 2.707V3.5a.5.5 0 01-1 0v-2a.5.5 0 01.5-.5zm8.5.5a.5.5 0 01.5-.5h2a.5.5 0 01.5.5v2a.5.5 0 01-1 0v-.793L8.854 5.854a.5.5 0 11-.708-.708L11.293 2H10.5a.5.5 0 01-.5-.5zm2.5 8.5a.5.5 0 01.5.5v2a.5.5 0 01-.5.5h-2a.5.5 0 010-1h.793L8.146 8.854a.5.5 0 11.708-.708L12 11.293V10.5a.5.5 0 01.5-.5zM2 11.293V10.5a.5.5 0 00-1 0v2a.5.5 0 00.5.5h2a.5.5 0 000-1h-.793l3.147-3.146a.5.5 0 10-.708-.708L2 11.293z"
fill={color ?? theme.color.defaultText}
/>
</Svg>
);
}