# App Screen
URL: /react/stackflow/app-screen
Source: https://github.com/daangn/seed-design/blob/dev/docs/content/react/stackflow/app-screen.mdx
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
```tsx
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 (
Preview
Preview
);
};
export default ActivityAppScreenPreview;
```
## Installation
- npm: npx @seed-design/cli@latest add ui:app-screen
- pnpm: pnpm dlx @seed-design/cli@latest add ui:app-screen
- yarn: yarn dlx @seed-design/cli@latest add ui:app-screen
- bun: bun x @seed-design/cli@latest add ui:app-screen
## Usage
```tsx
import {
AppBar,
AppBarBackButton,
AppBarCloseButton,
AppBarIconButton,
AppBarLeft,
AppBarMain,
AppBarRight,
} from "seed-design/ui/app-bar";
import { AppScreen, AppScreenContent } from "seed-design/ui/app-screen";
```
```tsx
Title
{/* actions */}
{/* content */}
```
## Props
### App Screen
#### `AppScreen`
#### `AppScreenContent`
### App Bar
#### `AppBar`
#### `AppBarLeft`
#### `AppBarMain`
#### `AppBarRight`
#### `AppBarIconButton`, `AppBarBackButton`, `AppBarCloseButton`
## Examples
### Tones
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`.
```tsx
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 (
Preview
Preview
);
};
export default ActivityAppScreenTransparent;
```
#### With Intersection Observer
You can dynamically change the `tone` property of `AppBar` using Intersection Observer.
```tsx
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("transparent");
const whiteImageRef = useRef(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 (
Preview
하얀 이미지
컨텐츠 영역
);
};
export default ActivityAppScreenIntersectionObserver;
```
### Layer Offset Top
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.
To properly handle safe areas like display cutouts (notches), use a `viewport` meta tag that includes `viewport-fit=cover`.
```html
```



### Customizing App Bar
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.
```tsx
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 (
} color="palette.blue500" size="x5" />
Preview
);
};
export default ActivityAppScreenAppBarCustomization;
```
#### Custom Elements in App Bar
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.
```tsx title='ActivityAppBarSlot.tsx'
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;
}
}
function FakeSearchBar(props: React.HTMLAttributes) {
return (
검색어를 입력하세요
);
}
const ActivityAppBarSlot: StaticActivityComponentType<"ActivityAppBarSlot"> = () => {
const { isRoot } = useActivity();
const { push } = useFlow();
return (
{!isRoot && (
)}
AppBar.Slot은 커스텀 요소에 stackflow 트랜지션 애니메이션을 적용합니다. 이 페이지에서
뒤로 swipe하면 검색바가 IconButton과 동일하게 fade 트랜지션됩니다.
push("ActivityAppBarSlot", {})} variant="neutralSolid">
이 액티비티 다시 열기
);
};
export default ActivityAppBarSlot;
```
### Preventing Swipe Back
You can prevent swipe back gestures by using the `preventSwipeBack` property to avoid rendering the edge area in AppScreen where `theme="cupertino"`.
### Transition Styles
You can specify the transition to play when AppScreen is pushed to the top or popped from the top using the `transitionStyle` property.
Top: Refers to AppScreen created by an activity where `useActivity().isTop === true`.
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.
**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`)
```tsx title='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;
};
}
}
const ActivityTransitionStyle: StaticActivityComponentType<"ActivityTransitionStyle"> = ({
params: { transitionStyle },
}) => {
const { push } = useFlow();
const { create } = useSnackbarAdapter();
const [preventSwipeBack, setPreventSwipeBack] = useState(false);
return (
{
create({ render: () => , timeout: 500 });
}}
onSwipeBackEnd={({ swiped }) => {
create({ render: () => , timeout: 500 });
}}
>
{/* can be undefined if search parameter isn't provided */}
push("ActivityHome", {})}>
{appScreenVariantMap.transitionStyle.map((style) => (
push("ActivityTransitionStyle", { transitionStyle: style })}
>
{style}
))}
Prevent Swipe Back
setPreventSwipeBack(value === "true")}
aria-label="Prevent Swipe Back"
>
false
true
);
};
export default ActivityTransitionStyle;
```