A component that constitutes individual screens in Stackflow navigation. Used to provide screen transition experience like mobile apps.
@seed-design/stackflow@0.0.1, @seed-design/css@0.0.1
import { IconBellFill } from "@karrotmarket/react-monochrome-icon" ;
import { Flex } from "@seed-design/react" ;
import type { StaticActivityComponentType } from "@stackflow/react/future" ;
import {
AppBar,
AppBarCloseButton,
AppBarIconButton,
AppBarLeft,
AppBarMain,
AppBarRight,
} from "seed-design/ui/app-bar" ;
import { AppScreen, AppScreenContent } from "seed-design/ui/app-screen" ;
declare module "@stackflow/config" {
interface Register {
ActivityAppScreenPreview : {};
}
}
const ActivityAppScreenPreview : StaticActivityComponentType < "ActivityAppScreenPreview" > = () => {
return (
< AppScreen theme = "cupertino" >
< AppBar >
< AppBarLeft >
< AppBarCloseButton />
</ AppBarLeft >
< AppBarMain >Preview</ AppBarMain >
< AppBarRight >
< AppBarIconButton aria-label = "Notification" >
< IconBellFill />
</ AppBarIconButton >
</ AppBarRight >
</ AppBar >
< AppScreenContent >
< Flex height = "full" justify = "center" align = "center" >
Preview
</ Flex >
</ AppScreenContent >
</ AppScreen >
);
};
export default ActivityAppScreenPreview;
npx @seed-design/cli@latest add ui:app-screen pnpm dlx @seed-design/cli@latest add ui:app-screen yarn dlx @seed-design/cli@latest add ui:app-screen bun x @seed-design/cli@latest add ui:app-screen
Install dependencies
npm install @karrotmarket/react-monochrome-icon @seed-design/react @seed-design/stackflow @stackflow/react yarn add @karrotmarket/react-monochrome-icon @seed-design/react @seed-design/stackflow @stackflow/react pnpm add @karrotmarket/react-monochrome-icon @seed-design/react @seed-design/stackflow @stackflow/react bun add @karrotmarket/react-monochrome-icon @seed-design/react @seed-design/stackflow @stackflow/react Copy the code below and paste it in /**
* @file ui:app-screen
* @requires @seed-design/react@^2.0.0
* @requires @seed-design/css@^2.0.0
**/
"use client" ;
import { PullToRefreshRoot, PullToRefreshContent, PullToRefreshIndicator } from "./pull-to-refresh" ;
import { AppScreen as SeedAppScreen } from "@seed-design/stackflow" ;
import { useActions, useActivity } from "@stackflow/react" ;
import { forwardRef } from "react" ;
export interface AppScreenProps extends SeedAppScreen . RootProps {
preventSwipeBack ?: boolean ;
}
export const AppScreen = forwardRef < HTMLDivElement , AppScreenProps >(
({ children , onSwipeBackEnd , preventSwipeBack , ... otherProps }, ref ) => {
const { pop } = useActions ();
const { isRoot } = useActivity ();
const shouldSwipeBack = ! isRoot && ! preventSwipeBack;
return (
< SeedAppScreen.Root
ref = {ref}
onSwipeBackEnd = {({ swiped }) => {
if (swiped) {
pop ();
}
onSwipeBackEnd ?.({ swiped });
}}
{ ... otherProps}
>
< SeedAppScreen.Dim />
{children}
{shouldSwipeBack && < SeedAppScreen.Edge />}
</ SeedAppScreen.Root >
);
},
);
AppScreen.displayName = "AppScreen" ;
export interface AppScreenContentProps extends SeedAppScreen . LayerProps {
ptr ?: boolean ;
onPtrReady ?: () => void ;
onPtrRefresh ?: () => Promise < void >;
}
export const AppScreenContent = forwardRef < HTMLDivElement , AppScreenContentProps >(
({ children , ptr , onPtrReady , onPtrRefresh , ... otherProps }, ref ) => {
if ( ! ptr) {
return (
< SeedAppScreen.Layer ref = {ref} { ... otherProps}>
{children}
</ SeedAppScreen.Layer >
);
}
return (
< PullToRefreshRoot asChild onPtrReady = {onPtrReady} onPtrRefresh = {onPtrRefresh}>
< SeedAppScreen.Layer ref = {ref} { ... otherProps}>
< PullToRefreshIndicator />
< PullToRefreshContent asChild >{children}</ PullToRefreshContent >
</ SeedAppScreen.Layer >
</ PullToRefreshRoot >
);
},
);
/**
* This file is a snippet from Crispy, helping you get started quickly with @seed-design/* packages.
* You can extend this snippet however you want.
*/
/**
* @file ui:app-screen
* @requires @seed-design/react@^2.0.0
* @requires @seed-design/css@^2.0.0
**/
"use client" ;
import { IconChevronLeftLine, IconXmarkLine } from "@karrotmarket/react-monochrome-icon" ; // "@daangn/react-monochrome-icon"과 동일합니다.
import { VStack } from "@seed-design/react" ;
import { AppBar as SeedAppBar } from "@seed-design/stackflow" ;
import { useActions, useActivity } from "@stackflow/react" ;
import * as React from "react" ;
import { forwardRef } from "react" ;
export interface AppBarProps extends SeedAppBar . RootProps {}
export const AppBar = SeedAppBar.Root;
export interface AppBarLeftProps extends SeedAppBar . LeftProps {}
export const AppBarLeft = SeedAppBar.Left;
export interface AppBarRightProps extends SeedAppBar . RightProps {}
export const AppBarRight = SeedAppBar.Right;
export interface AppBarSlotProps extends SeedAppBar . SlotProps {}
export const AppBarSlot = SeedAppBar.Slot;
export interface AppBarMainProps extends Omit < SeedAppBar . MainProps , "asChild" > {
/**
* The title of the app bar.
* If children is provided as ReactElement, this prop will be ignored.
*/
title ?: string ;
/**
* The subtitle of the app bar.
* If children is provided as ReactElement, this prop will be ignored.
*/
subtitle ?: string ;
}
export const AppBarMain = forwardRef < HTMLDivElement , AppBarMainProps >(
({ title , subtitle , children , ... otherProps }, ref ) => {
if (React. isValidElement (children)) {
return (
< SeedAppBar.Main { ... otherProps} ref = {ref}>
{children}
</ SeedAppBar.Main >
);
}
return (
< SeedAppBar.Main layout = {subtitle ? "withSubtitle" : "titleOnly" } { ... otherProps} ref = {ref}>
< VStack overflowX = "auto" >
< SeedAppBar.Title >{children ?? title}</ SeedAppBar.Title >
{subtitle ? < SeedAppBar.Subtitle >{subtitle}</ SeedAppBar.Subtitle > : null }
</ VStack >
</ SeedAppBar.Main >
);
},
);
AppBarMain.displayName = "AppBarMain" ;
export interface AppBarIconButtonProps extends SeedAppBar . IconButtonProps {}
export const AppBarIconButton = SeedAppBar.IconButton;
export const AppBarBackButton = forwardRef < HTMLButtonElement , AppBarIconButtonProps >(
({ children = < IconChevronLeftLine />, onClick , ... otherProps }, ref ) => {
const activity = useActivity ();
const actions = useActions ();
const handleOnClick = ( e : React . MouseEvent < HTMLButtonElement >) => {
onClick ?.(e);
if ( ! e.defaultPrevented) {
actions. pop ();
}
};
if ( ! activity) {
return null ;
}
if (activity.isRoot) {
return null ;
}
return (
< SeedAppBar.IconButton
ref = {ref}
aria-label = "뒤로"
type = "button"
onClick = {handleOnClick}
{ ... otherProps}
>
{children}
</ SeedAppBar.IconButton >
);
},
);
AppBarBackButton.displayName = "AppBarBackButton" ;
export const AppBarCloseButton = forwardRef < HTMLButtonElement , AppBarIconButtonProps >(
({ children = < IconXmarkLine />, onClick , ... otherProps }, ref ) => {
const activity = useActivity ();
const handleOnClick = ( e : React . MouseEvent < HTMLButtonElement >) => {
onClick ?.(e);
if ( ! e.defaultPrevented) {
// you can do something here
}
};
const isRoot = ! activity || activity.isRoot;
if ( ! isRoot) {
return null ;
}
return (
< AppBarIconButton
ref = {ref}
aria-label = "닫기"
type = "button"
onClick = {handleOnClick}
{ ... otherProps}
>
{children}
</ AppBarIconButton >
);
},
);
AppBarCloseButton.displayName = "AppBarCloseButton" ;
/**
* This file is a snippet from Crispy, helping you get started quickly with @seed-design/* packages.
* You can extend this snippet however you want.
*/
import {
AppBar,
AppBarBackButton,
AppBarCloseButton,
AppBarIconButton,
AppBarLeft,
AppBarMain,
AppBarRight,
} from "seed-design/ui/app-bar" ;
import { AppScreen, AppScreenContent } from "seed-design/ui/app-screen" ;
< AppScreen theme = "cupertino" >
< AppBar >
< AppBarLeft >
< AppBarBackButton />
</ AppBarLeft >
< AppBarMain >Title</ AppBarMain >
< AppBarRight >{ /* actions */ }</ AppBarRight >
</ AppBar >
< AppScreenContent >{ /* content */ }</ AppScreenContent >
</ AppScreen >
preventSwipeBack?boolean | undefined
onSwipeBackStart?(() => void ) | undefined
onSwipeBackMove?(( props : { displacement : number ; displacementRatio : number ; }) => void ) | undefined
onSwipeBackEnd?(( props : { swiped : boolean ; }) => void ) | undefined
ptr?boolean | undefined
onPtrReady?(() => void ) | undefined
onPtrRefresh?(() => Promise <void> ) | undefined
asChild?boolean | undefined
background?(string & {}) | ScopedColorBg | ScopedColorPalette | ScopedColorBanner | undefined
subtitle?string | undefined
theme?"cupertino" | "android" | undefined
transitionStyle?"slideFromRightIOS" | "fadeFromBottomAndroid" | "fadeIn" | undefined
tone?"layer" | "transparent" | undefined
layout?"titleOnly" | "withSubtitle" | undefined
You can use a transparent background by setting the tone property of AppScreen to transparent.
The background of AppBar becomes transparent.
A gradient is displayed at the top of AppScreen including the mobile OS status bar.
You can hide it by setting the gradient property to false.
import { IconBellFill } from "@karrotmarket/react-monochrome-icon" ;
import { Flex } from "@seed-design/react" ;
import type { StaticActivityComponentType } from "@stackflow/react/future" ;
import {
AppBar,
AppBarCloseButton,
AppBarIconButton,
AppBarLeft,
AppBarMain,
AppBarRight,
} from "seed-design/ui/app-bar" ;
import { AppScreen, AppScreenContent } from "seed-design/ui/app-screen" ;
declare module "@stackflow/config" {
interface Register {
ActivityAppScreenTransparent : {};
}
}
const ActivityAppScreenTransparent : StaticActivityComponentType <
"ActivityAppScreenTransparent"
> = () => {
return (
< AppScreen theme = "cupertino" layerOffsetTop = "none" tone = "transparent" >
< AppBar >
< AppBarLeft >
< AppBarCloseButton aria-label = "Close" />
</ AppBarLeft >
< AppBarMain >Preview</ AppBarMain >
< AppBarRight >
< AppBarIconButton aria-label = "Notification" >
< IconBellFill />
</ AppBarIconButton >
</ AppBarRight >
</ AppBar >
< AppScreenContent >
< Flex
height = "full"
justify = "center"
align = "center"
bg = "palette.gray800"
color = "fg.neutralInverted"
>
Preview
</ Flex >
</ AppScreenContent >
</ AppScreen >
);
};
export default ActivityAppScreenTransparent;
You can dynamically change the tone property of AppBar using Intersection Observer.
import { IconBellFill } from "@karrotmarket/react-monochrome-icon" ;
import { Flex } from "@seed-design/react" ;
import type { StaticActivityComponentType } from "@stackflow/react/future" ;
import { useEffect, useRef, useState } from "react" ;
import {
AppBar,
AppBarCloseButton,
AppBarIconButton,
AppBarLeft,
AppBarMain,
type AppBarProps,
AppBarRight,
} from "seed-design/ui/app-bar" ;
import { AppScreen, AppScreenContent } from "seed-design/ui/app-screen" ;
declare module "@stackflow/config" {
interface Register {
ActivityAppScreenIntersectionObserver : {};
}
}
const ActivityAppScreenIntersectionObserver : StaticActivityComponentType <
"ActivityAppScreenIntersectionObserver"
> = () => {
const [ tone , setTone ] = useState < AppBarProps [ "tone" ]>( "transparent" );
const whiteImageRef = useRef < HTMLDivElement >( null );
useEffect (() => {
const observer = new IntersectionObserver (
( entries ) => {
const entry = entries[ 0 ];
if ( ! entry.isIntersecting) {
// 이미지 영역을 벗어나면 tone을 layer로 변경
setTone ( "layer" );
} else {
// 이미지 영역을 포함하면 tone을 transparent로 변경
setTone ( "transparent" );
}
},
{
threshold: [ 0 , 0.1 , 0.5 , 1 ],
rootMargin: "0px" ,
},
);
if (whiteImageRef.current) {
observer. observe (whiteImageRef.current);
}
return () => {
observer. disconnect ();
};
}, []);
return (
< AppScreen theme = "cupertino" layerOffsetTop = "none" tone = {tone}>
< AppBar >
< AppBarLeft >
< AppBarCloseButton aria-label = "Close" />
</ AppBarLeft >
< AppBarMain >Preview</ AppBarMain >
< AppBarRight >
< AppBarIconButton aria-label = "Notification" >
< IconBellFill />
</ AppBarIconButton >
</ AppBarRight >
</ AppBar >
< AppScreenContent >
< Flex
ref = {whiteImageRef}
justifyContent = "center"
alignItems = "center"
bg = "palette.staticWhite"
height = "400px"
width = "full"
>
하얀 이미지
</ Flex >
< Flex
height = "1000px"
justify = "center"
align = "center"
bg = "palette.gray800"
color = "fg.neutralInverted"
>
컨텐츠 영역
</ Flex >
</ AppScreenContent >
</ AppScreen >
);
};
export default ActivityAppScreenIntersectionObserver;
You can adjust the top offset of AppScreenContent using the layerOffsetTop property.
When using tone="transparent" and gradient, generally set layerOffsetTop="none" together to extend the content area to the mobile OS status bar area.
When tone="layer", you can change the color of AppBar.
You can customize icons by using the Icon component within AppBarIconButton.
Learn more about the Icon component.
import { Flex, Icon } from "@seed-design/react" ;
import { IconBellFill } from "@karrotmarket/react-monochrome-icon" ;
import type { StaticActivityComponentType } from "@stackflow/react/future" ;
import { AppBar, AppBarIconButton, AppBarMain, AppBarRight } from "seed-design/ui/app-bar" ;
import { AppScreen, AppScreenContent } from "seed-design/ui/app-screen" ;
declare module "@stackflow/config" {
interface Register {
ActivityAppScreenAppBarCustomization : {};
}
}
const ActivityAppScreenAppBarCustomization : StaticActivityComponentType <
"ActivityAppScreenAppBarCustomization"
> = () => {
return (
< AppScreen theme = "android" >
< AppBar bg = "palette.blue200" >
< AppBarMain title = "Preview" subtitle = "This is a nice preview." />
< AppBarRight >
< AppBarIconButton aria-label = "Notification" >
< Icon svg = {< IconBellFill />} color = "palette.blue500" size = "x5" />
</ AppBarIconButton >
</ AppBarRight >
</ AppBar >
< AppScreenContent >
< Flex justify = "center" align = "center" height = "full" >
Preview
</ Flex >
</ AppScreenContent >
</ AppScreen >
);
};
export default ActivityAppScreenAppBarCustomization;
When placing custom elements within AppBar that don't correspond to AppBarLeft, AppBarMain, or AppBarRight, use the AppBarSlot component to apply the same screen transition as other elements.
AppBarSlot applies transitions by injecting class to child elements and does not generate additional markup.
import { useActivity, useFlow, type StaticActivityComponentType } from "@stackflow/react/future" ;
import {
AppBar,
AppBarBackButton,
AppBarLeft,
AppBarRight,
AppBarIconButton,
AppBarSlot,
} from "seed-design/ui/app-bar" ;
import { AppScreen, AppScreenContent } from "seed-design/ui/app-screen" ;
import { IconBellLine } from "@karrotmarket/react-monochrome-icon" ;
import { Flex, Text, VStack } from "@seed-design/react" ;
import { ActionButton } from "seed-design/ui/action-button" ;
declare module "@stackflow/config" {
interface Register {
ActivityAppBarSlot : Record < string , never >;
}
}
function FakeSearchBar ( props : React . HTMLAttributes < HTMLDivElement >) {
return (
< Flex grow py = "x2" px = "x2_5" height = "full" style = {{ boxSizing: "border-box" }} { ... props}>
< Flex
px = "x3"
background = "bg.neutralWeak"
grow
borderRadius = "r2"
align = "center"
borderColor = "stroke.neutralMuted"
borderWidth = { 1 }
>
< Text color = "fg.placeholder" textStyle = "t4Medium" >
검색어를 입력하세요
</ Text >
</ Flex >
</ Flex >
);
}
const ActivityAppBarSlot : StaticActivityComponentType < "ActivityAppBarSlot" > = () => {
const { isRoot } = useActivity ();
const { push } = useFlow ();
return (
< AppScreen theme = "cupertino" >
< AppBar >
{ ! isRoot && (
< AppBarLeft >
< AppBarBackButton />
</ AppBarLeft >
)}
< AppBarSlot >
< FakeSearchBar />
</ AppBarSlot >
< AppBarRight >
< AppBarIconButton aria-label = "알림" >
< IconBellLine />
</ AppBarIconButton >
< AppBarIconButton aria-label = "알림" >
< IconBellLine />
</ AppBarIconButton >
</ AppBarRight >
</ AppBar >
< AppScreenContent >
< VStack gap = "spacingY.componentDefault" px = "spacingX.globalGutter" py = "x4" >
< Text as = "p" textStyle = "articleBody" color = "fg.neutral" >
AppBar.Slot은 커스텀 요소에 stackflow 트랜지션 애니메이션을 적용합니다. 이 페이지에서
뒤로 swipe하면 검색바가 IconButton과 동일하게 fade 트랜지션됩니다.
</ Text >
< ActionButton onClick = {() => push ( "ActivityAppBarSlot" , {})} variant = "neutralSolid" >
이 액티비티 다시 열기
</ ActionButton >
</ VStack >
</ AppScreenContent >
</ AppScreen >
);
};
export default ActivityAppBarSlot;
You can prevent swipe back gestures by using the preventSwipeBack property to avoid rendering the edge area in AppScreen where theme="cupertino".
You can specify the transition to play when AppScreen is pushed to the top or popped from the top using the transitionStyle property.
If not specified separately, transitionStyle has a default value according to theme.
theme="cupertino": slideFromRightIOS
theme="android": fadeFromBottomAndroid
When the top AppScreen is pushed/popped, non-top AppScreens also play transitions.
Transition Style of Non-Top AppScreen Up to @seed-design/stackflow@1.1.15
When the top AppScreen is pushed/popped, non-top AppScreens play each AppScreen's unique transitionStyle.
For example, if AppScreen 1 with transitionStyle="slideFromLeftIOS" is pushed on top of AppScreen 0 with transitionStyle="fadeFromBottomAndroid", AppScreen 0 plays the fadeFromBottomAndroid transition.
AppScreen 0 remains unchanged in position (fadeFromBottomAndroid) and AppScreen 1 slides in from the right (slideFromLeftIOS)
Later versions
When the top AppScreen is pushed/popped, non-top AppScreens play the transitionStyle of the top AppScreen.
Provides smooth transitions when multiple transitionStyle coexist within the same stack.
For example, if AppScreen 1 with transitionStyle="slideFromLeftIOS" is pushed on top of AppScreen 0 with transitionStyle="fadeFromBottomAndroid", AppScreen 0 plays the slideFromLeftIOS transition.
AppScreen 0 is naturally pushed slightly to the left and darkened (slideFromLeftIOS) and AppScreen 1 slides in from the right (slideFromLeftIOS)
ActivityTransitionStyle.tsx
import { VStack, Text } from "@seed-design/react" ;
import { useFlow, type StaticActivityComponentType } from "@stackflow/react/future" ;
import {
AppBar,
AppBarBackButton,
AppBarIconButton,
AppBarLeft,
AppBarMain,
AppBarRight,
} from "seed-design/ui/app-bar" ;
import { AppScreen, AppScreenContent, type AppScreenProps } from "seed-design/ui/app-screen" ;
import { IconHouseLine } from "@karrotmarket/react-monochrome-icon" ;
import { ActionButton } from "seed-design/ui/action-button" ;
import { appScreenVariantMap } from "@seed-design/css/recipes/app-screen" ;
import { Snackbar, useSnackbarAdapter } from "seed-design/ui/snackbar" ;
import { SegmentedControl, SegmentedControlItem } from "seed-design/ui/segmented-control" ;
import { useState } from "react" ;
declare module "@stackflow/config" {
interface Register {
ActivityTransitionStyle : {
transitionStyle : NonNullable < AppScreenProps [ "transitionStyle" ]>;
};
}
}
const ActivityTransitionStyle : StaticActivityComponentType < "ActivityTransitionStyle" > = ({
params: { transitionStyle },
}) => {
const { push } = useFlow ();
const { create } = useSnackbarAdapter ();
const [ preventSwipeBack , setPreventSwipeBack ] = useState ( false );
return (
< AppScreen
transitionStyle = {transitionStyle}
preventSwipeBack = {preventSwipeBack}
onSwipeBackStart = {() => {
create ({ render : () => < Snackbar message = "Started swiping" />, timeout: 500 });
}}
onSwipeBackEnd = {({ swiped }) => {
create ({ render : () => < Snackbar message = { `Swiped: ${ swiped }` } />, timeout: 500 });
}}
>
< AppBar >
< AppBarLeft >
< AppBarBackButton />
</ AppBarLeft >
{ /* can be undefined if search parameter isn't provided */ }
< AppBarMain title = {transitionStyle ?? "Transition Styles" } />
< AppBarRight >
< AppBarIconButton aria-label = "Home" onClick = {() => push ( "ActivityHome" , {})}>
< IconHouseLine />
</ AppBarIconButton >
</ AppBarRight >
</ AppBar >
< AppScreenContent >
< VStack px = "spacingX.globalGutter" py = "x3" gap = "x4" >
< VStack gap = "x2" >
{appScreenVariantMap.transitionStyle. map (( style ) => (
< ActionButton
key = {style}
variant = {transitionStyle === style ? "neutralWeak" : "neutralSolid" }
onClick = {() => push ( "ActivityTransitionStyle" , { transitionStyle: style })}
>
{style}
</ ActionButton >
))}
</ VStack >
< VStack gap = "x2" align = "center" >
< Text textStyle = "t3Bold" aria-hidden >
Prevent Swipe Back
</ Text >
< SegmentedControl
value = {preventSwipeBack ? "true" : "false" }
onValueChange = {( value ) => setPreventSwipeBack (value === "true" )}
aria-label = "Prevent Swipe Back"
>
< SegmentedControlItem value = "false" >false</ SegmentedControlItem >
< SegmentedControlItem value = "true" >true</ SegmentedControlItem >
</ SegmentedControl >
</ VStack >
</ VStack >
</ AppScreenContent >
</ AppScreen >
);
};
export default ActivityTransitionStyle;